Hi,
Im trying to make a % up time of a machine. The machine sends a MQTT signal to the broker where node-red is running. The signal gets inserted into a mysql database. When the machine is on it publish a 1. When the machine is turned off it publish a 0. Is there a way is node-red to calculate the % on based on the daily time on + off?
I tried to make it myself and got this from the internet:
[{"id":"1d29d505.98215b","type":"mqtt in","z":"f61eaed1.e45da","name":"","topic":"pers77_status","qos":"2","broker":"d0e4f151.5ec18","x":130,"y":260,"wires":[["8bd74e88.dc306","dbc06091.377bd","71de4e59.9991d"]]},{"id":"8bd74e88.dc306","type":"function","z":"f61eaed1.e45da","name":"Set start time","func":"if (msg.topic === \"0\") {\nvar now = new Date(); // current time\nflow.set(\"startTime\", now);\n} else {\n return [ msg, null ];\n}\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":260,"wires":[["1c1caf69.bd00d1"]]},{"id":"dbc06091.377bd","type":"function","z":"f61eaed1.e45da","name":"Calc difference ms","func":"if (msg.topic === \"1\") {\nvar now = new Date();\nmsg.payload = now - flow.get(\"startTime\")\n} else {\n return [ msg, null ];\n}\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":340,"wires":[["49a1c573.c8644c"]]},{"id":"49a1c573.c8644c","type":"debug","z":"f61eaed1.e45da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":340,"wires":[]},{"id":"71de4e59.9991d","type":"debug","z":"f61eaed1.e45da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":330,"y":300,"wires":[]},{"id":"1c1caf69.bd00d1","type":"debug","z":"f61eaed1.e45da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":260,"wires":[]},{"id":"d0e4f151.5ec18","type":"mqtt-broker","z":"","name":"MQTT_Broker","broker":"192.168.16.76","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
i basicly need the total time the machine is on 1 and the total time the machine is on 0.
Im not sure if i presented all the information. If you need anymore information, please let me know.