IOT - Engine run time

If you ever have to record engine run time or have to record the time valves stay open etc. this little flow does it.

[{"id":"d5ebfa8d.412cf8","type":"tab","label":"Engine runtime","disabled":false,"info":""},{"id":"d1605568.7de958","type":"function","z":"d5ebfa8d.412cf8","name":"init engine runtime","func":"//var total_time = parseInt(msg.payload);\nvar t1 = Date.now();\n//flow.set('total_time',total_time);\nflow.set('total_time',0);\nflow.set('t1', t1);\nflow.set('t2', t1);\nreturn msg;\n","outputs":1,"noerr":0,"x":630,"y":100,"wires":[[]]},{"id":"52216aae.036d04","type":"function","z":"d5ebfa8d.412cf8","name":"stop","func":"var t2 = Date.now();\nvar t1 = flow.get('t1');\nvar delta = t2 -t1;\nvar total_time = parseInt(flow.get('total_time'));\ntotal_time = total_time + delta;\nflow.set('total_time',total_time);\nmsg.payload = total_time;\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":260,"wires":[["c713ac88.de924"]]},{"id":"c713ac88.de924","type":"function","z":"d5ebfa8d.412cf8","name":"engine runtime","func":"var ms = parseInt(msg.payload);\nvar t = ms/1000;\nvar h = (Math.floor(t / 3600)).toString();\nvar m = (\"0\" + (Math.floor(t%3600 / 60))).slice(-2);\nvar s = (\"0\" + (Math.floor(t%3600 % 60))).slice(-2);\n\nvar ts = h + \":\" +  m + \":\" + s;\nflow.set('DG-WZ-total',{'ms':ms,'time':ts});\nreturn [\n    {payload:{'ms':ms,'time':ts}},\n    {payload:ms,filename:'/home/pi/duration/DG-WZ-Dauer.log'}\n];","outputs":2,"noerr":0,"x":600,"y":260,"wires":[["5554cf81.77314"],["9ecabb23.d8f278"]]},{"id":"5554cf81.77314","type":"debug","z":"d5ebfa8d.412cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":240,"wires":[]},{"id":"5a25ad91.6ae9a4","type":"file","z":"d5ebfa8d.412cf8","name":"save engine time","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","x":970,"y":280,"wires":[[]]},{"id":"9ecabb23.d8f278","type":"debug","z":"d5ebfa8d.412cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":280,"wires":[]},{"id":"e9dc425a.7c913","type":"function","z":"d5ebfa8d.412cf8","name":"start","func":"var t1 = Date.now();\nflow.set('t1', t1);\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":200,"wires":[[]]},{"id":"240b10a7.1799c","type":"inject","z":"d5ebfa8d.412cf8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":320,"y":200,"wires":[["e9dc425a.7c913"]]},{"id":"7b86756d.26fc6c","type":"inject","z":"d5ebfa8d.412cf8","name":"load at program start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":220,"y":40,"wires":[["ce968ea6.d8dcb"]]},{"id":"d5b21314.a8fff","type":"inject","z":"d5ebfa8d.412cf8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":320,"y":260,"wires":[["52216aae.036d04"]]},{"id":"fbc67eab.e8d97","type":"inject","z":"d5ebfa8d.412cf8","name":"init when testing","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":140,"wires":[["d1605568.7de958"]]},{"id":"ce968ea6.d8dcb","type":"function","z":"d5ebfa8d.412cf8","name":"path/file","func":"return {filename:'/home/pi/duration/Engine_Time.log'};\n","outputs":1,"noerr":0,"x":400,"y":40,"wires":[[]]},{"id":"cd0850f9.b3d18","type":"file in","z":"d5ebfa8d.412cf8","name":"load engine time","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":420,"y":100,"wires":[["d1605568.7de958"]]},{"id":"4929bb84.4c6af4","type":"inject","z":"d5ebfa8d.412cf8","name":"load total time at programm start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":100,"wires":[[]]}]
2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.