[{"id":"f64edfdc.d851e","type":"tab","label":"Light"},{"id":"11b3d0e7.b4bdef","type":"mqtt-broker","z":"f64edfdc.d851e","broker":"localhost","port":"1883","clientid":"mosquitto","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"120","cleansession":true,"willTopic":"Will","willQos":"0","willRetain":"false","willPayload":"Will","birthTopic":"Bitth","birthQos":"0","birthRetain":"false","birthPayload":"Birth"},{"id":"6ebda08d.43d53","type":"ui_group","z":"","name":"Main Lamp","tab":"f9a92b0d.899528","order":1,"disp":true,"width":"6"},{"id":"d10a7fd6.cd8b4","type":"ui_group","z":"","name":"Bench Light","tab":"f9a92b0d.899528","order":2,"disp":true,"width":"6"},{"id":"f9a92b0d.899528","type":"ui_tab","z":"","name":"LAB","icon":"dashboard","order":1},{"id":"e47d180b.7d7848","type":"ui_group","z":"","name":"MiFlora","tab":"69680ab4.916fc4","order":2,"disp":true,"width":"6"},{"id":"1c2d661e.35f9da","type":"ui_group","z":"","name":"Report","tab":"744faf1d.cef9","order":2,"disp":true,"width":"18"},{"id":"a567ed1d.bcc4c","type":"ui_group","z":"","name":"Selection","tab":"744faf1d.cef9","order":1,"disp":true,"width":"5"},{"id":"69680ab4.916fc4","type":"ui_tab","z":"","name":"Home","icon":"home","order":"1"},{"id":"744faf1d.cef9","type":"ui_tab","z":"","name":"Reports","icon":"dashboard","order":9},{"id":"9476a661.c70048","type":"ui_group","z":"","name":"MiFlora","tab":"218f23d3.f6945c","order":2,"disp":true,"width":"6"},{"id":"c779d2c1.a36ad","type":"ui_group","z":"","name":"Report","tab":"330cfe71.4e0da2","order":2,"disp":true,"width":"18"},{"id":"429526e6.f7e818","type":"ui_group","z":"","name":"Selection","tab":"330cfe71.4e0da2","order":1,"disp":true,"width":"5"},{"id":"218f23d3.f6945c","type":"ui_tab","z":"","name":"Home","icon":"home","order":"1"},{"id":"330cfe71.4e0da2","type":"ui_tab","z":"","name":"Reports","icon":"dashboard","order":9},{"id":"1d38ff1b.df4d71","type":"sqlitedb","z":"","db":"/home/pi/dbs/iot.sav"},{"id":"d28d2cb3.499d7","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"Helvetica Neue","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"Helvetica Neue","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"Helvetica Neue"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#000000","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false}}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"c81195cd.329698","type":"mqtt in","z":"f64edfdc.d851e","name":"PIR_MAIN","topic":"LAB/PIR/MAIN/relay/0","qos":"1","broker":"11b3d0e7.b4bdef","x":249,"y":292,"wires":[["68404a1.579cdb4","882b308d.2f5e","4bce79f6.970f38","731273d9.8befcc"]]},{"id":"3b14bca1.e0f054","type":"trigger","z":"f64edfdc.d851e","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":true,"units":"min","reset":"","name":"Pulse","x":948,"y":280,"wires":[["fa0cee09.922a1","ec87000f.f5755"]]},{"id":"23741f9e.79c0b","type":"ui_button","z":"f64edfdc.d851e","name":"Off","group":"6ebda08d.43d53","order":1,"width":0,"height":0,"label":"OFF","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"LAB/OVERRIDE/","x":907,"y":20,"wires":[["ec87000f.f5755"]]},{"id":"2f24acef.c48c74","type":"ui_button","z":"f64edfdc.d851e","name":"On","group":"6ebda08d.43d53","order":2,"width":0,"height":0,"label":"ON","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"str","topic":"LAB/OVERRIDE/","x":912,"y":68,"wires":[["ec87000f.f5755"]]},{"id":"421b8492.451f3c","type":"mqtt in","z":"f64edfdc.d851e","name":"PIR_TABLE","topic":"LAB/PIR/TABLE/relay/0","qos":"1","broker":"11b3d0e7.b4bdef","x":256,"y":364,"wires":[["4cb4e0e3.cac1c","d090b1b6.2c258","dceea436.5120c8","9bba38fe.5bfc48"]]},{"id":"9b3c491c.b2cf58","type":"mqtt out","z":"f64edfdc.d851e","name":"LIGHT_MAIN","topic":"LAB/LIGHT/LIGHT_MAIN/relay/0","qos":"1","retain":"false","broker":"11b3d0e7.b4bdef","x":1619,"y":116,"wires":[]},{"id":"75a43649.357bd8","type":"trigger","z":"f64edfdc.d851e","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":true,"units":"min","reset":"","name":"Pulse","x":946,"y":364,"wires":[["82d8ba23.942378","af5d8c08.3af61"]]},{"id":"89212d66.918ee","type":"ui_button","z":"f64edfdc.d851e","name":"Off","group":"d10a7fd6.cd8b4","order":1,"width":0,"height":0,"label":"OFF","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"LAB/OVERRIDE/","x":908,"y":639,"wires":[["af5d8c08.3af61"]]},{"id":"4789b3b3.3a466c","type":"ui_button","z":"f64edfdc.d851e","name":"On","group":"d10a7fd6.cd8b4","order":2,"width":0,"height":0,"label":"ON","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"str","topic":"LAB/OVERRIDE/","x":911,"y":677,"wires":[["af5d8c08.3af61"]]},{"id":"4cb4e0e3.cac1c","type":"switch","z":"f64edfdc.d851e","name":"ON","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","outputs":1,"x":640,"y":362,"wires":[["75a43649.357bd8","3b14bca1.e0f054"]]},{"id":"68404a1.579cdb4","type":"switch","z":"f64edfdc.d851e","name":"ON","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","outputs":1,"x":644,"y":289,"wires":[["3b14bca1.e0f054"]]},{"id":"5e91047e.9157cc","type":"sqlite","z":"f64edfdc.d851e","mydb":"1d38ff1b.df4d71","name":"IOT.db","x":745.5,"y":969,"wires":[[]]},{"id":"9bba38fe.5bfc48","type":"function","z":"f64edfdc.d851e","name":"","func":"var overrideMain = global.get('overrideMain');\nvar overrideTable = global.get('overrideTable');\n\n\n// Update the status with current timestamp\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\nvar timeFormat= dd + \".\" + mm + \".\" + yyyy + \" \" + hh + \":\" + mmm + \":\" + ss;\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Last update: \"+timeFormat}); \n\nvar top=msg.topic.toString();\nvar pay=msg.payload.toString();\n\nif(msg.topic.includes(\"TABLE\")) overrideMain =\"NONE\"\nmsg.topic = \"INSERT INTO Sonoff (Topic,timeStamp,payload,overrideMain,overrideTable) VALUES (?,?,?,?,?)\";\nmsg.payload = [top,timeFormat,pay, overrideMain,overrideTable];\nreturn msg;","outputs":1,"noerr":0,"x":502,"y":971,"wires":[["5e91047e.9157cc"]]},{"id":"ebcb48d7.2c0288","type":"mqtt in","z":"f64edfdc.d851e","name":"ALEXA","topic":"LAB/PIR/MAIN/alexa/1","qos":"1","broker":"11b3d0e7.b4bdef","x":909,"y":160,"wires":[["ec87000f.f5755"]]},{"id":"ec87000f.f5755","type":"function","z":"f64edfdc.d851e","name":"OverrideMain","func":"var over=global.get('overrideMain');\nif (msg.topic.includes(\"OVERRIDE\") || msg.topic.includes(\"alexa\")) {\n if (msg.payload==\"A\"){\n over=\"AUTO\";\n global.set('overrideMain',over);\n node.status({fill:\"blue\",shape:\"ring\",text:\"Override: \"+over}); \n } else {\n if (msg.payload==\"1\") {\n over=\"ON\";\n msg.payload=\"1\"\n }\n if (msg.payload==\"0\") {\n over=\"OFF\";\n msg.payload=\"0\"\n }\n global.set('overrideMain',over);\n node.status({fill:\"blue\",shape:\"ring\",text:\"Override: \"+over}); \n return msg;\n }\n} else {\n if (over==\"ON\") msg.payload=\"1\";\n if (over==\"OFF\") msg.payload=\"0\";\n return msg;\n}","outputs":1,"noerr":0,"x":1329,"y":122,"wires":[["9b3c491c.b2cf58","9e6334f0.4adc48"]]},{"id":"af5d8c08.3af61","type":"function","z":"f64edfdc.d851e","name":"OverrideTable","func":"var over=global.get('overrideTable');\nif (msg.topic.includes(\"OVERRIDE\") || msg.topic.includes(\"alexa\")) {\n if (msg.payload==\"A\"){\n over=\"AUTO\";\n global.set('overrideTable',over);\n node.status({fill:\"blue\",shape:\"ring\",text:\"Override: \"+over}); \n } else {\n if (msg.payload==\"1\") {\n over=\"ON\";\n msg.payload=\"1\"\n }\n if (msg.payload==\"0\") {\n over=\"OFF\";\n msg.payload=\"0\"\n }\n global.set('overrideTable',over);\n node.status({fill:\"blue\",shape:\"ring\",text:\"Override: \"+over}); \n return msg;\n }\n} else {\n if (over==\"ON\") msg.payload=\"1\";\n if (over==\"OFF\") msg.payload=\"0\";\n return msg;\n}","outputs":1,"noerr":0,"x":1330,"y":521,"wires":[["d3972ba0.614608","2a3dfb63.06e2e4"]]},{"id":"8858d792.b04b48","type":"ui_button","z":"f64edfdc.d851e","name":"Auto","group":"d10a7fd6.cd8b4","order":1,"width":0,"height":0,"label":"AUTO","color":"","bgcolor":"","icon":"","payload":"A","payloadType":"str","topic":"LAB/OVERRIDE/","x":910,"y":715,"wires":[["af5d8c08.3af61"]]},{"id":"2ee6a115.a0cd0e","type":"ui_button","z":"f64edfdc.d851e","name":"Auto","group":"6ebda08d.43d53","order":1,"width":0,"height":0,"label":"AUTO","color":"","bgcolor":"","icon":"","payload":"A","payloadType":"str","topic":"LAB/OVERRIDE/","x":912,"y":118,"wires":[["ec87000f.f5755"]]},{"id":"bd145283.deab","type":"ui_audio","z":"f64edfdc.d851e","name":"","group":"6ebda08d.43d53","voice":"3","always":"","x":611,"y":620,"wires":[]},{"id":"d090b1b6.2c258","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":508,"y":439,"wires":[[]]},{"id":"dceea436.5120c8","type":"function","z":"f64edfdc.d851e","name":"","func":"if (msg.payload==\"1\") msg.payload=\"james, please switch the bench light on\"\nif (msg.payload==\"0\") msg.payload=\"james, please switch the bench light off\"\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":618,"wires":[[]]},{"id":"882b308d.2f5e","type":"function","z":"f64edfdc.d851e","name":"","func":"global.set('overrideTable',\"0\");\nif (msg.payload==\"1\") msg.payload=\"ich kriege mein Licht eingeschaltet\"\nif (msg.payload==\"0\") msg.payload=\"ich kriege mein Licht ausgeschaltet\"\nreturn msg;","outputs":1,"noerr":0,"x":411,"y":123,"wires":[[]]},{"id":"c16816c8.7b4ba8","type":"ui_audio","z":"f64edfdc.d851e","name":"","group":"6ebda08d.43d53","voice":"1","always":"","x":577,"y":129,"wires":[]},{"id":"38055919.0b8ac6","type":"mqtt in","z":"f64edfdc.d851e","name":"ALEXA","topic":"LAB/PIR/TABLE/alexa/1","qos":"1","broker":"11b3d0e7.b4bdef","x":911,"y":762,"wires":[["af5d8c08.3af61"]]},{"id":"4bce79f6.970f38","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":513,"y":225,"wires":[[]]},{"id":"731273d9.8befcc","type":"function","z":"f64edfdc.d851e","name":"","func":"var overrideMain = global.get('overrideMain');\nvar overrideTable = global.get('overrideTable');\n\n\n// Update the status with current timestamp\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\nvar timeFormat= dd + \".\" + mm + \".\" + yyyy + \" \" + hh + \":\" + mmm + \":\" + ss;\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Last update: \"+timeFormat}); \n\nvar top=msg.topic.toString();\nvar pay=msg.payload.toString();\n\nif(msg.topic.includes(\"MAIN\")) overrideTable =\"NONE\"\nmsg.topic = \"INSERT INTO Sonoff (Topic,timeStamp,payload,overrideMain,overrideTable) VALUES (?,?,?,?,?)\";\nmsg.payload = [top,timeFormat,pay, overrideMain,overrideTable];\nreturn msg;","outputs":1,"noerr":0,"x":499,"y":895,"wires":[["5e91047e.9157cc"]]},{"id":"d3972ba0.614608","type":"mqtt out","z":"f64edfdc.d851e","name":"LIGHT_TABLE","topic":"LAB/LIGHT/LIGHT_TABLE/relay/0","qos":"1","retain":"false","broker":"11b3d0e7.b4bdef","x":1599,"y":513,"wires":[]},{"id":"2a3dfb63.06e2e4","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":1573,"y":565,"wires":[[]]},{"id":"9e6334f0.4adc48","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":1592,"y":169,"wires":[[]]},{"id":"fa0cee09.922a1","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":1137,"y":279,"wires":[[]]},{"id":"82d8ba23.942378","type":"function","z":"f64edfdc.d851e","name":"Status","func":"if (msg.payload==\"0\") node.status({fill:\"red\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"green\",shape:\"ring\",text:msg.payload}); \nreturn msg;","outputs":1,"noerr":0,"x":1112,"y":365,"wires":[[]]}]