i got the following flow:"
[{"id":"79ce684e.6b6da8","type":"function","z":"1f216cc0.281a93","name":"INSERT statement","func":"msg.topic = \"INSERT INTO `IOT_DATA` ( `DATA_BRON`,`DATA_SOORT`,`DATA_WAARDE`) VALUES ('77','uit',\" + msg.payload + \")\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":360,"wires":[["933216aa.2dc248","a4481e1e.3b5b9"]]},{"id":"933216aa.2dc248","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":360,"wires":[]},{"id":"9eb082e8.fa622","type":"mqtt in","z":"1f216cc0.281a93","name":"","topic":"pers77_status","qos":"2","broker":"d0e4f151.5ec18","x":70,"y":400,"wires":[["5cbedf1f.672cc","54c828cf.882268","4dac3b4d.140274"]]},{"id":"a4481e1e.3b5b9","type":"mysql","z":"1f216cc0.281a93","mydb":"23c1ad96.82d712","name":"","x":1170,"y":400,"wires":[[]]},{"id":"54c828cf.882268","type":"function","z":"1f216cc0.281a93","name":"Color","func":"if (msg.payload == 1) {\n msg.payload = true;\n} else {\n msg.payload = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":500,"wires":[["4484dea2.81af1","aca98c67.3cfae"]]},{"id":"3c3ee011.f1b88","type":"function","z":"1f216cc0.281a93","name":"Generate spike","func":"var interval = setInterval(function() {\n clearInterval(interval);\n\tnode.send({payload: 0});\n}, msg.payload); \n\nreturn null;","outputs":1,"noerr":0,"x":440,"y":380,"wires":[["20746ea6.68e8e2"]]},{"id":"20746ea6.68e8e2","type":"interval-length","z":"1f216cc0.281a93","format":"mills","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"secs","maximumunit":"msecs","windowunit":"secs","reset":false,"startup":true,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"","x":640,"y":380,"wires":[["79ce684e.6b6da8","2a1fad18.a78762"],[]]},{"id":"2a1fad18.a78762","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":400,"wires":[]},{"id":"5cbedf1f.672cc","type":"switch","z":"1f216cc0.281a93","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":400,"wires":[["3c3ee011.f1b88"],["e8683c0e.f97bb"]]},{"id":"c448d0c8.e005e","type":"function","z":"1f216cc0.281a93","name":"INSERT statement","func":" msg.topic = \"INSERT INTO `IOT_DATA` ( `DATA_BRON`,`DATA_SOORT`,`DATA_WAARDE`) VALUES ('77','aan',\" + msg.payload + \")\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":460,"wires":[["5a14a007.53421","b50c1a56.eb3f28"]]},{"id":"5a14a007.53421","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":460,"wires":[]},{"id":"b50c1a56.eb3f28","type":"mysql","z":"1f216cc0.281a93","mydb":"23c1ad96.82d712","name":"","x":1170,"y":500,"wires":[[]]},{"id":"e8683c0e.f97bb","type":"function","z":"1f216cc0.281a93","name":"Generate spike","func":"var interval = setInterval(function() {\n clearInterval(interval);\n\tnode.send({payload: 0});\n}, msg.payload); \n\nreturn null;","outputs":1,"noerr":0,"x":440,"y":420,"wires":[["d1a16f19.b92e2"]]},{"id":"d1a16f19.b92e2","type":"interval-length","z":"1f216cc0.281a93","format":"mills","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"secs","maximumunit":"msecs","windowunit":"secs","reset":false,"startup":true,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"","x":640,"y":420,"wires":[["c448d0c8.e005e","c41f05fb.e87568"],[]]},{"id":"c41f05fb.e87568","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":500,"wires":[]},{"id":"4dac3b4d.140274","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":250,"y":580,"wires":[]},{"id":"4484dea2.81af1","type":"ui_led","z":"1f216cc0.281a93","group":"ef52ec43.10754","order":1,"width":"3","height":"2","label":"Aan/uit","labelPlacement":"right","labelAlignment":"left","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"name":"Aan/uit","x":420,"y":500,"wires":[]},{"id":"aca98c67.3cfae","type":"ui_led","z":"1f216cc0.281a93","group":"ef52ec43.10754","order":2,"width":"4","height":"2","label":"Slag","labelPlacement":"right","labelAlignment":"left","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"name":"Slag","x":410,"y":540,"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":""},{"id":"23c1ad96.82d712","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"VEKO_IOT","tz":""},{"id":"ef52ec43.10754","type":"ui_group","z":"","name":"Pers 77","tab":"6b96da3f.ce1c04","order":1,"disp":true,"width":"24","collapse":false},{"id":"6b96da3f.ce1c04","type":"ui_tab","z":"","name":"Machine data","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
The problem i just noticed is that the time on is calculating the time between 1 and 1 and the time off is calculated between 0 and 0. So it's not the time on (1 to 0) or off (o to 1) but between on and on or off and off.
Can anyone help me to get the time on and off?