- if (context.get('previous') === undefined){
- //die Person kann in den Raum eintretten
- if (msg.payload !== undefined){
- context.set('previous', msg.payload);
- }else{
- context.set('previous', 340);
- }
- }
- if (context.get('previous') != msg.payload){
- if (msg.payload < 15){
- if (context.get('time') === null || context.get('time') === undefined){
- let data = Date.now();
- let date = new Date(data);
- let year=date.getFullYear();
- let month=date.getMonth()+1;
- let day=date.getDate();
- let fullDate = day + " " + month + " " + year;
- let hours=date.getHours();
- let minutes=date.getMinutes();
- if (minutes < 10){
- minutes = "0" + minutes;
- }
- let seconds=date.getSeconds();
- if (seconds < 10){
- seconds = "0" + seconds;
- }
- let datum = hours + ":" + minutes + ":" + seconds;
- context.set('time', data);
- msg.payload = context.get('time');
- msg.payload = "inside" + "," + 1 + "," + fullDate + "," + datum;
- return msg;
- }else{
- context.set('leave', Date.now());
- let durationText;
- let duration = context.get('leave') - context.get('time');
- context.set('duration', duration);
- if(context.get('duration') > 1000){
- let duration = context.get('duration') / 1000;
- durationText = duration + " s";
- if(context.get('duration') > 60000 ){
- let duration = context.get('duration') / 60000;
- durationText = duration + " min";
- if (context.get('duration') > 3600000){
- let duration = context.get('duration') / 3600000;
- durationText = duration + " h";
- }
- }
- }else {
- durationText = context.get('duration') + " ms";
- }
- context.set('durationText', durationText);
- }
- }else{
- context.set('time', null);
- if (context.get('leave') === null){
- msg.payload = "nobody inside";
- context.set('previous', msg.payload);
- return msg;
- }else{
- if( context.get('leave') != null){
- let data = new Date(context.get('leave'));
- let year=data.getFullYear();
- let month=data.getMonth()+1;
- let day=data.getDate();
- let fullDate = day + " " + month + " " + year;
- let hours=data.getHours();
- let minutes=data.getMinutes();
- if (minutes < 10){
- minutes = "0" + minutes;
- }
- let seconds=data.getSeconds();
- if (seconds < 10){
- seconds = "0" + seconds;
- }
- let datum = hours + ":" + minutes + ":" + seconds;
- msg.payload = "leave" + "," + 0 + "," + fullDate + "," + datum + "," + context.get('durationText');
- context.set('leave', null);
- context.set ('duration', null);
- context.set('previous', msg.payload);
- return msg;
- }
- }
- }
[text] inside
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: