Node-RED as Alternative Rule Engine

I have a xiaomi button that click when I go to bed, it turns my whole apartment off and deactivates the motion detection that normally turns on the light, apart from the motions sensor on my bathroom.

I have a global motion detection switch for all my rooms, that will trickier the light if it is dark.

2 Likes

For thoes of you who are working with different types of light, e.g. yeelight, hue, tasmota ect. I have this small tool for handling the possible issues with different command for the types of light. It’s not finished but maybe you can use it as inspiration for your know flows. Some of it is in danish and some in english :smiley:

the conceptis that you send a msg.command and a msg.room to the node and then it get filtered out to the different lights. If you get more smarts lights you just add them to the tree.

The most interesting is the “translate light” which looks like this:

the code is here:

[{"id":"5bf24306.cd4b2c","type":"change","z":"28521005.9d89e","name":"Hue_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":54,"wires":[["56917fa3.53353"]]},{"id":"6f814d24.659a64","type":"switch","z":"28521005.9d89e","name":"Command","property":"Command","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"Random","vt":"str"},{"t":"eq","v":"Set","vt":"str"},{"t":"eq","v":"Color","vt":"str"},{"t":"eq","v":"Bri","vt":"str"},{"t":"eq","v":"CT","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":8,"x":232,"y":936,"wires":[["9c53f3c9.0727a"],["b9f377de.0192b8"],["95bf090e.839608"],["5521817b.95783"],["95bac735.b1f998"],["174cfce2.2c13c3"],["e90d6a09.386898"],["e22a2477.ef2ee8"]]},{"id":"9ef1d920.e7bf68","type":"change","z":"28521005.9d89e","name":"Yeelight_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true}","tot":"json"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":126,"wires":[["56917fa3.53353"]]},{"id":"4bcdd744.2c2808","type":"change","z":"28521005.9d89e","name":"Hue_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1078,"y":360,"wires":[["67d29b4c.2867d4"]]},{"id":"5a5eb155.268f2","type":"change","z":"28521005.9d89e","name":"Yeelight_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":false}","tot":"json"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1088,"y":432,"wires":[["67d29b4c.2867d4"]]},{"id":"b7487310.95525","type":"change","z":"28521005.9d89e","name":"Hue_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1006,"y":1026,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"4028424c.ade73c","type":"change","z":"28521005.9d89e","name":"Yeelight_Color","rules":[{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1016,"y":1098,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"e4f98d49.b2707","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"payload","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":996,"y":1242,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"5f1cc279.822a9c","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":306,"wires":[["56917fa3.53353"]]},{"id":"66ab9427.0500fc","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1058,"y":612,"wires":[["67d29b4c.2867d4"]]},{"id":"cbccaa8c.2b3818","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":986,"y":1278,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"21f4d382.de161c","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":572,"y":1656,"wires":[["a1d0917b.60f5a"]]},{"id":"9e50b7ee.840068","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1166,"y":1980,"wires":[["7f49d978.9db2c8"]]},{"id":"f362c72f.69eeb8","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":572,"y":2160,"wires":[["1142c587.c1640a"]]},{"id":"a205d9a6.ea16e8","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":972,"wires":[["8462c8eb.454938"]]},{"id":"8efe7bc2.ce9f58","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":270,"wires":[["56917fa3.53353"]]},{"id":"9dc3fc4.80124","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1068,"y":576,"wires":[["67d29b4c.2867d4"]]},{"id":"9b21c5bf.78e398","type":"comment","z":"28521005.9d89e","name":"Random","info":"","x":600,"y":684,"wires":[]},{"id":"93442ff7.0ce29","type":"comment","z":"28521005.9d89e","name":"Off","info":"","x":1058,"y":324,"wires":[]},{"id":"e513d1e4.c1bdf","type":"comment","z":"28521005.9d89e","name":"On","info":"","x":590,"y":18,"wires":[]},{"id":"76b6c94e.7753c8","type":"comment","z":"28521005.9d89e","name":"Set","info":"","x":986,"y":990,"wires":[]},{"id":"bbe9303.a77ecd","type":"comment","z":"28521005.9d89e","name":"Color","info":"","x":572,"y":1368,"wires":[]},{"id":"6b45e890.13af68","type":"comment","z":"28521005.9d89e","name":"Brightness","info":"","x":1176,"y":1692,"wires":[]},{"id":"7e5c5a43.5e87e4","type":"comment","z":"28521005.9d89e","name":"Color Temp","info":"","x":592,"y":1944,"wires":[]},{"id":"3db2a9a2.60f8c6","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"LightType","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":936,"wires":[["8462c8eb.454938"]]},{"id":"99aaab46.1216c8","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1176,"y":1944,"wires":[["7f49d978.9db2c8"]]},{"id":"546c37ef.91f318","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":582,"y":1620,"wires":[["a1d0917b.60f5a"]]},{"id":"aa4d695c.cfd618","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":582,"y":2124,"wires":[["1142c587.c1640a"]]},{"id":"87e3ed51.450a2","type":"comment","z":"28521005.9d89e","name":"mangler","info":"","x":734,"y":684,"wires":[]},{"id":"d6e12de5.448c4","type":"comment","z":"28521005.9d89e","name":"mangler","info":"","x":1104,"y":990,"wires":[]},{"id":"93ceff83.0bfd5","type":"comment","z":"28521005.9d89e","name":"mangler","info":"","x":708,"y":1368,"wires":[]},{"id":"e22a2477.ef2ee8","type":"change","z":"28521005.9d89e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Command not found","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":224,"y":1080,"wires":[[]]},{"id":"bab92f31.43de7","type":"change","z":"28521005.9d89e","name":"Yeelight_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":792,"wires":[["8462c8eb.454938"]]},{"id":"753500e5.e7573","type":"function","z":"28521005.9d89e","name":"Hue_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"ct\\\":[\" + SetTemp + \"]}\";\nmsg.LightType = \"Hue_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":1980,"wires":[["e63f24f.f64bbd8"]]},{"id":"eb9a0b64.52ef08","type":"function","z":"28521005.9d89e","name":"Yeelight_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"ct\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":602,"y":2052,"wires":[["e63f24f.f64bbd8"]]},{"id":"f37744f4.2ce4e8","type":"function","z":"28521005.9d89e","name":"Hue_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":[\" + SetTemp + \"]}\";\nmsg.LightType = \"Hue_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":1186,"y":1728,"wires":[["b8350a1.4b280f8"]]},{"id":"f6b287f5.8a5418","type":"function","z":"28521005.9d89e","name":"Yeelight_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":1196,"y":1800,"wires":[["b8350a1.4b280f8"]]},{"id":"96beb6a8.a4d4b8","type":"function","z":"28521005.9d89e","name":"Hue_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":[\" + SetTemp + \"]}\";\nmsg.LightType = \"Hue_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":1404,"wires":[["23ba7040.c481"]]},{"id":"587af158.8b85c","type":"function","z":"28521005.9d89e","name":"Yeelight_Color","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_Color\"\nreturn msg;","outputs":1,"noerr":0,"x":602,"y":1476,"wires":[["23ba7040.c481"]]},{"id":"acdef937.e020f8","type":"change","z":"28521005.9d89e","name":"Hue_dimmer","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":90,"wires":[["56917fa3.53353"]]},{"id":"a840a473.774648","type":"change","z":"28521005.9d89e","name":"Yeelight_TW","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true}","tot":"json"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_TW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":162,"wires":[["56917fa3.53353"]]},{"id":"9c53f3c9.0727a","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":144,"wires":[["5bf24306.cd4b2c","acdef937.e020f8","9ef1d920.e7bf68","a840a473.774648","8efe7bc2.ce9f58","5f1cc279.822a9c","e233b14.1a8175","5a9584c4.076d3c"]]},{"id":"b9f377de.0192b8","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":878,"y":486,"wires":[["4bcdd744.2c2808","5a5eb155.268f2","9dc3fc4.80124","66ab9427.0500fc","c30d27f3.847068","26a2788f.918678","d4a938ec.6c72e8","33527086.8e1ed"]]},{"id":"545f4e7c.5c57a","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":740,"wires":[["3db2a9a2.60f8c6","bab92f31.43de7","a205d9a6.ea16e8","67b75788.7f9f28","91b4cd17.393d3","5e9de635.db3988"]]},{"id":"5521817b.95783","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":824,"y":1062,"wires":[["e4f98d49.b2707","b7487310.95525","f3db9c1.191a86","4028424c.ade73c","cbccaa8c.2b3818","2099e892.9d7548"]]},{"id":"95bac735.b1f998","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":374,"y":1494,"wires":[["587af158.8b85c","96beb6a8.a4d4b8","55056d44.6b04a4","546c37ef.91f318","21f4d382.de161c","51877686.1b8e48","f8d56703.ed7b68","47e99e43.8ca3"]]},{"id":"174cfce2.2c13c3","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":932,"y":1764,"wires":[["f6b287f5.8a5418","f37744f4.2ce4e8","8c59da4a.875358","707ffa75.feb324","cf8266e.fa55498"]]},{"id":"e90d6a09.386898","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":1998,"wires":[["753500e5.e7573","853c0ebe.ae867","eb9a0b64.52ef08","84bf8922.cb4428","aa4d695c.cfd618","f362c72f.69eeb8"]]},{"id":"c30d27f3.847068","type":"change","z":"28521005.9d89e","name":"Hue_Dimmer","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1078,"y":396,"wires":[["67d29b4c.2867d4"]]},{"id":"26a2788f.918678","type":"change","z":"28521005.9d89e","name":"Yeelight_TW","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":false}","tot":"json"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_TW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1078,"y":468,"wires":[["67d29b4c.2867d4"]]},{"id":"67b75788.7f9f28","type":"change","z":"28521005.9d89e","name":"Hue_Dimmer","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":756,"wires":[["8462c8eb.454938"]]},{"id":"91b4cd17.393d3","type":"change","z":"28521005.9d89e","name":"Yeelight_TW","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_TW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":828,"wires":[["8462c8eb.454938"]]},{"id":"f3db9c1.191a86","type":"change","z":"28521005.9d89e","name":"Hue_Dimmer","rules":[{"t":"set","p":"LightType","pt":"msg","to":"Hue_Dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1006,"y":1062,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"2099e892.9d7548","type":"change","z":"28521005.9d89e","name":"Yeelight_TW","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Yeelight_TW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1006,"y":1134,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"51877686.1b8e48","type":"function","z":"28521005.9d89e","name":"Hue_Dimmer","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":[\" + SetTemp + \"]}\";\nmsg.LightType = \"Hue_Dimmer\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":1440,"wires":[["23ba7040.c481"]]},{"id":"55056d44.6b04a4","type":"function","z":"28521005.9d89e","name":"Yeelight_TW","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_TW\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":1512,"wires":[["23ba7040.c481"]]},{"id":"8c59da4a.875358","type":"function","z":"28521005.9d89e","name":"Hue_Dimmer","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Hue_Dimmer\"\nreturn msg;","outputs":1,"noerr":0,"x":1186,"y":1764,"wires":[["b8350a1.4b280f8"]]},{"id":"707ffa75.feb324","type":"function","z":"28521005.9d89e","name":"Yeelight_TW","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"bri\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_TW\"\nreturn msg;","outputs":1,"noerr":0,"x":1186,"y":1836,"wires":[["b8350a1.4b280f8"]]},{"id":"853c0ebe.ae867","type":"function","z":"28521005.9d89e","name":"Hue_Dimmer","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"ct\\\":[\" + SetTemp + \"]}\";\nmsg.LightType = \"Hue_Dimmer\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":2016,"wires":[["e63f24f.f64bbd8"]]},{"id":"84bf8922.cb4428","type":"function","z":"28521005.9d89e","name":"Yeelight_TW","func":"var SetTemp = \"\" + msg.payload;\n\nmsg.payload = \"{\\\"ct\\\":\" + SetTemp + \"}\";\nmsg.LightType = \"Yeelight_TW\"\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":2088,"wires":[["e63f24f.f64bbd8"]]},{"id":"8c3b48dc.ad6b28","type":"switch","z":"28521005.9d89e","name":"","property":"LightType","propertyType":"msg","rules":[{"t":"eq","v":"Hue_Color","vt":"str"},{"t":"eq","v":"Hue_Dimmer","vt":"str"},{"t":"eq","v":"Yeelight_Color","vt":"str"},{"t":"eq","v":"Yeelight_TW","vt":"str"},{"t":"eq","v":"OH_Color","vt":"str"},{"t":"eq","v":"OH_Brightless","vt":"str"},{"t":"eq","v":"Tasmota","vt":"str"},{"t":"eq","v":"Plug","vt":"str"}],"checkall":"true","repair":false,"outputs":8,"x":1598,"y":1008,"wires":[[],[],[],[],[],[],[],[]]},{"id":"56917fa3.53353","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":144,"wires":[["8c3b48dc.ad6b28"]]},{"id":"67d29b4c.2867d4","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":432,"wires":[["8c3b48dc.ad6b28"]]},{"id":"8462c8eb.454938","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":824,"y":810,"wires":[["8c3b48dc.ad6b28"]]},{"id":"e7eb3c5f.5c6d4","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1239.0234375,"y":1127.0546875,"wires":[["8c3b48dc.ad6b28"]]},{"id":"a1d0917b.60f5a","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":842,"y":1476,"wires":[["8c3b48dc.ad6b28"]]},{"id":"7f49d978.9db2c8","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1490,"y":1782,"wires":[["8c3b48dc.ad6b28"]]},{"id":"1142c587.c1640a","type":"change","z":"28521005.9d89e","name":"Joiner","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":842,"y":2052,"wires":[["8c3b48dc.ad6b28"]]},{"id":"e233b14.1a8175","type":"change","z":"28521005.9d89e","name":"OH_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":198,"wires":[["56917fa3.53353"]]},{"id":"5a9584c4.076d3c","type":"change","z":"28521005.9d89e","name":"OH_Brightless","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Brightless","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":234,"wires":[["56917fa3.53353"]]},{"id":"d4a938ec.6c72e8","type":"change","z":"28521005.9d89e","name":"OH_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1068,"y":504,"wires":[["67d29b4c.2867d4"]]},{"id":"33527086.8e1ed","type":"change","z":"28521005.9d89e","name":"OH_Brightless","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Brightless","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1088,"y":540,"wires":[["67d29b4c.2867d4"]]},{"id":"f7a083b6.ea3a5","type":"change","z":"28521005.9d89e","name":"OH_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":920,"wires":[["8462c8eb.454938"]]},{"id":"758014a1.72d8dc","type":"change","z":"28521005.9d89e","name":"OH_Brightless","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Brightless","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":900,"wires":[[]]},{"id":"1816073f.d67739","type":"change","z":"28521005.9d89e","name":"OH_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":996,"y":1170,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"8f775656.a6bb68","type":"change","z":"28521005.9d89e","name":"OH_Brightless","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Brightless","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1016,"y":1206,"wires":[["e7eb3c5f.5c6d4"]]},{"id":"f8d56703.ed7b68","type":"change","z":"28521005.9d89e","name":"OH_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":582,"y":1548,"wires":[["a1d0917b.60f5a"]]},{"id":"47e99e43.8ca3","type":"change","z":"28521005.9d89e","name":"OH_Brightless","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"OH_Brightless","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1560,"wires":[["a1d0917b.60f5a"]]},{"id":"b71eead5.70ac68","type":"comment","z":"28521005.9d89e","name":"Accept command and in some cases a payload for adjustment","info":"","x":256,"y":648,"wires":[]},{"id":"b8350a1.4b280f8","type":"json","z":"28521005.9d89e","name":"","property":"payload","action":"","pretty":false,"x":1346,"y":1764,"wires":[["7f49d978.9db2c8"]]},{"id":"e63f24f.f64bbd8","type":"json","z":"28521005.9d89e","name":"","property":"payload","action":"","pretty":false,"x":770,"y":1980,"wires":[["1142c587.c1640a"]]},{"id":"23ba7040.c481","type":"json","z":"28521005.9d89e","name":"","property":"payload","action":"","pretty":false,"x":870,"y":1400,"wires":[["a1d0917b.60f5a"]]},{"id":"29eec645.5e779a","type":"change","z":"28521005.9d89e","name":"Plug","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1166,"y":1908,"wires":[["7f49d978.9db2c8"]]},{"id":"c4630e7f.dbc8a","type":"change","z":"28521005.9d89e","name":"Tasmota","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.1.116/cm?cmnd=POWER ON","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Tasmota","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1176,"y":1872,"wires":[["7f49d978.9db2c8"]]},{"id":"cf8266e.fa55498","type":"switch","z":"28521005.9d89e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1004,"y":1908,"wires":[["c4630e7f.dbc8a","29eec645.5e779a"],["99aaab46.1216c8","9e50b7ee.840068"]]},{"id":"5e9de635.db3988","type":"change","z":"28521005.9d89e","name":"Hue_Color","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"effect\":[\"none\"]}","tot":"str"},{"t":"set","p":"LightType","pt":"msg","to":"Hue_Color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":720,"wires":[["8462c8eb.454938"]]},{"id":"4b59365a.0a0858","type":"function","z":"28521005.9d89e","name":"generate HSB","func":"var Hue = msg.payload;\n\n\nvar HSB = Hue + \",\" + \"100\" + \",\" + \"40\";\n\n\nmsg.payload = HSB;\n\nnode.status({fill:\"green\",shape:\"ring\",text: msg.payload});\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":864,"wires":[["f7a083b6.ea3a5"]]},{"id":"24414da5.e62342","type":"comment","z":"28521005.9d89e","name":"Mangler omskrivning så det passer til begge ","info":"","x":674,"y":1890,"wires":[]},{"id":"95bf090e.839608","type":"random","z":"28521005.9d89e","name":"","low":"0","high":"255","inte":"true","property":"payload","x":340,"y":800,"wires":[["545f4e7c.5c57a"]]}]

How do you experience the responsetime on Node Red? Home Assistant (HASSIO) has a significant lag compared to build in rules (YAML in that case) for me, which was a no-go in regards to motion sensors.

Virtually instantaneous

Great, then I think I’ll give Node Red a try in openhabian :stuck_out_tongue:

Here is a workflow for timed lights with notification.

Read the first post about notification.

Mine is :

rule "Send Notification"
when
	Item vNotification received update
then
	sendBroadcastNotification(vNotification.state.toString)
end

Then, in your .items file :

Group:Number:COUNT(ON) gNotifLight10s  "Lumières allumées timer 10 minutes [%d]" <light> (gNotifGlobal) // test 10s instead of 10m
Group:Number:COUNT(ON) gNotifLight10m  "Lumières allumées timer 10 minutes [%d]" <light> (gNotifGlobal) 
Group:Number:COUNT(ON) gNotifLight20m  "Lumières allumées timer 20 minutes [%d]" <light> (gNotifGlobal) 
Group:Number:COUNT(ON) gNotifLight30m  "Lumières allumées timer 30 minutes [%d]" <light> (gNotifGlobal) 
Group:Number:COUNT(ON) gNotifLight1h  "Lumières allumées timer 1 heure [%d]" <light> (gNotifGlobal) 
Group:Number:COUNT(ON) gNotifLight2h  "Lumières allumées timer 2 heures [%d]" <light> (gNotifGlobal) 
Group:Number:COUNT(ON) gNotifLight4h  "Lumières allumées timer 4 heures [%d]" <light> (gNotifGlobal) 
Group:Number:SUM gNotifGlobal "Lumières allumées avec tempo sur notification[%d]" <light> (Home)

If you get an error in openhab logs about COUNT and ON. Don’t care about, it will work… And if not, try again…

Set the proper group to the switch items you want to monitor.

Here is the workflow :

And the code :

[{"id":"fea6c6ef.fe6498","type":"tab","label":"Timer light switched ON test","disabled":false,"info":""},{"id":"58689464.f2402c","type":"switch","z":"fea6c6ef.fe6498","name":"OFF or ON ?","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":1130,"y":200,"wires":[["406465f.f45499c"],["54eea94d.704b48"]]},{"id":"878f2576.5d1638","type":"openhab2-out","z":"fea6c6ef.fe6498","name":"","controller":"996bcc70.92a13","itemname":"vNotification","topic":"ItemUpdate","payload":"","x":2850,"y":640,"wires":[]},{"id":"bb8672e7.03592","type":"change","z":"fea6c6ef.fe6498","name":"set remainder message","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t   \"la lampe \\\"\" & msg.lightLabel & \"\\\" est allumée depuis \" & (msg.duration * msg.counter) & \" minutes\"\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":2570,"y":420,"wires":[["878f2576.5d1638","cf6d8246.7a408"]]},{"id":"406465f.f45499c","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":300,"wires":[["dc370934.3f0288","213c7080.86575","66ae31ef.35003","ff49fa1c.bc4dd8"]]},{"id":"fb5a1558.81c508","type":"openhab2-events","z":"fea6c6ef.fe6498","name":"","controller":"996bcc70.92a13","itemname":"","x":100,"y":240,"wires":[["40313d5c.7a0c74"]]},{"id":"40313d5c.7a0c74","type":"switch","z":"fea6c6ef.fe6498","name":"Is topic gNotifLight","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"gNotifLight","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":160,"wires":[["f9234191.eaecd"]]},{"id":"f9234191.eaecd","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"item","pt":"msg","to":"(\t   $arr := $split(msg.topic, '/', limit);\t   $arr[-2]\t\t)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":120,"wires":[["7af6707b.e21a4"]]},{"id":"7af6707b.e21a4","type":"openhab2-get","z":"fea6c6ef.fe6498","name":"Get Light","controller":"996bcc70.92a13","itemname":"","x":800,"y":80,"wires":[["dc370934.3f0288","32475087.693c5"]]},{"id":"dc370934.3f0288","type":"debug","z":"fea6c6ef.fe6498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1770,"y":80,"wires":[]},{"id":"213c7080.86575","type":"switch","z":"fea6c6ef.fe6498","name":"Determine duration","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"gNotifLight10s","vt":"str"},{"t":"cont","v":"gNotifLight10m","vt":"str"},{"t":"cont","v":"gNotifLight20m","vt":"str"},{"t":"cont","v":"gNotifLight30m","vt":"str"},{"t":"cont","v":"gNotifLight1h","vt":"str"},{"t":"cont","v":"gNotifLight2h","vt":"str"},{"t":"cont","v":"gNotifLight4h","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":8,"x":1590,"y":420,"wires":[["c6b25632.c19ca8"],["27c2ffba.3a3a8"],["ca4f6d4f.85e1d"],["b8c8fa98.763968"],["4f3f1d4c.ba18f4"],["cf02b188.5989a"],["831427f8.341cb8"],["3642ccf3.4d8844"]]},{"id":"27c2ffba.3a3a8","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":false,"units":"min","reset":"","bytopic":"topic","name":"","x":1810,"y":280,"wires":[["dc370934.3f0288","9de818ab.dd4868"]]},{"id":"ca4f6d4f.85e1d","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"20","extend":false,"units":"min","reset":"","bytopic":"topic","name":"","x":1810,"y":340,"wires":[["dc370934.3f0288","b3c3fb05.c0a8e8"]]},{"id":"b8c8fa98.763968","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":false,"units":"min","reset":"","bytopic":"topic","name":"","x":1810,"y":400,"wires":[["dc370934.3f0288","97adcf2f.93f04"]]},{"id":"4f3f1d4c.ba18f4","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"units":"hr","reset":"","bytopic":"topic","name":"","x":1810,"y":460,"wires":[["dc370934.3f0288","29160e89.4aaeb2"]]},{"id":"cf02b188.5989a","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"2","extend":false,"units":"hr","reset":"","bytopic":"topic","name":"","x":1810,"y":520,"wires":[["dc370934.3f0288","454d3363.493d7c"]]},{"id":"831427f8.341cb8","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"4","extend":false,"units":"hr","reset":"","bytopic":"topic","name":"","x":1810,"y":580,"wires":[["dc370934.3f0288","5f5adc4f.9f1a74"]]},{"id":"3642ccf3.4d8844","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"20","extend":false,"units":"min","reset":"","bytopic":"topic","name":"default : 20 minutes","x":1830,"y":640,"wires":[["dc370934.3f0288","36f67639.06eaaa"]]},{"id":"6b036470.1f042c","type":"change","z":"fea6c6ef.fe6498","name":"Do nothing - visual only","rules":[{"t":"set","p":"nothing","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":170,"y":40,"wires":[["a8817359.5cbf1"]]},{"id":"9de818ab.dd4868","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":220,"wires":[["5d29e82f.f08a68"]]},{"id":"b3c3fb05.c0a8e8","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":280,"wires":[["5d29e82f.f08a68"]]},{"id":"97adcf2f.93f04","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"30","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":340,"wires":[["5d29e82f.f08a68"]]},{"id":"29160e89.4aaeb2","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"60","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":400,"wires":[["5d29e82f.f08a68"]]},{"id":"454d3363.493d7c","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"120","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":460,"wires":[["5d29e82f.f08a68"]]},{"id":"5f5adc4f.9f1a74","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"240","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":520,"wires":[["5d29e82f.f08a68"]]},{"id":"36f67639.06eaaa","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"duration","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":580,"wires":[["5d29e82f.f08a68"]]},{"id":"a8817359.5cbf1","type":"change","z":"fea6c6ef.fe6498","name":"increment counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"msg.counter + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":420,"wires":[["52f9687a.42bb58"]]},{"id":"54eea94d.704b48","type":"change","z":"fea6c6ef.fe6498","name":"init counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":440,"wires":[["a8817359.5cbf1"]]},{"id":"cf6d8246.7a408","type":"change","z":"fea6c6ef.fe6498","name":"Do nothing - visual only","rules":[{"t":"set","p":"nothing","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2950,"y":40,"wires":[["6b036470.1f042c"]]},{"id":"c6b25632.c19ca8","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"20","extend":false,"units":"s","reset":"","bytopic":"topic","name":"Test 20s instead of 10m","x":1850,"y":160,"wires":[["9de818ab.dd4868","dc370934.3f0288"]]},{"id":"d6b886a6.1bdc78","type":"function","z":"fea6c6ef.fe6498","name":"Add this light to blink array","func":"var blink = flow.get(\"blink\")||[];\nblink.push(msg.lightLabel);\nflow.set(\"blink\", blink);\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":620,"wires":[["9d22d84e.c3fc48","278ee60f.a096ca"]]},{"id":"52f9687a.42bb58","type":"switch","z":"fea6c6ef.fe6498","name":"counter exceeded ? (fixed max 3)","property":"counter","propertyType":"msg","rules":[{"t":"else"},{"t":"gte","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":400,"wires":[["213c7080.86575"],["66ae31ef.35003"]]},{"id":"66ae31ef.35003","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"4","extend":false,"units":"min","reset":"","bytopic":"topic","name":"","x":330,"y":620,"wires":[["d6b886a6.1bdc78"]]},{"id":"5d29e82f.f08a68","type":"switch","z":"fea6c6ef.fe6498","name":"counter reached ?","property":"counter","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2330,"y":400,"wires":[["a66e7547.8f2cc8"],["bb8672e7.03592"]]},{"id":"a66e7547.8f2cc8","type":"change","z":"fea6c6ef.fe6498","name":"set remainder and warning message","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t   \"la lampe \\\"\" & msg.lightLabel & \"\\\" est allumée depuis \" & (msg.duration * msg.counter) & \" minutes et sera éteinte dans 5 minutes\"\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":2610,"y":360,"wires":[["cf6d8246.7a408","878f2576.5d1638"]]},{"id":"9d22d84e.c3fc48","type":"openhab2-out","z":"fea6c6ef.fe6498","name":"OFF the light","controller":"996bcc70.92a13","itemname":"","topic":"ItemCommand","payload":"OFF","x":830,"y":580,"wires":[]},{"id":"278ee60f.a096ca","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"units":"s","reset":"","bytopic":"topic","name":"","x":820,"y":620,"wires":[["d08cbb4b.429b88","28b238b6.232878"]]},{"id":"ff49fa1c.bc4dd8","type":"trigger","z":"fea6c6ef.fe6498","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"units":"min","reset":"","bytopic":"topic","name":"","x":1290,"y":660,"wires":[["f76d93c8.d8a0e","da91dd84.f4541"]]},{"id":"d08cbb4b.429b88","type":"openhab2-out","z":"fea6c6ef.fe6498","name":"ON the light","controller":"996bcc70.92a13","itemname":"","topic":"ItemCommand","payload":"ON","x":1010,"y":580,"wires":[]},{"id":"f76d93c8.d8a0e","type":"openhab2-out","z":"fea6c6ef.fe6498","name":"OFF the light","controller":"996bcc70.92a13","itemname":"","topic":"ItemCommand","payload":"OFF","x":1530,"y":620,"wires":[]},{"id":"28b238b6.232878","type":"function","z":"fea6c6ef.fe6498","name":"Remove this light from blink array","func":"var blink = flow.get(\"blink\")||[];\nblink = blink.filter(function (value, index, array){\n   return value != msg.lightLabel; \n}) \nflow.set(\"blink\", blink);\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":660,"wires":[["ff49fa1c.bc4dd8"]]},{"id":"da91dd84.f4541","type":"change","z":"fea6c6ef.fe6498","name":"set remainder message","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t   \"la lampe \\\"\" & msg.lightLabel & \"\\\" a été automatiquement éteinte après une durée de \" & (msg.duration * msg.counter) & \" minutes\"\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1550,"y":700,"wires":[["878f2576.5d1638"]]},{"id":"82044f04.81a8c","type":"function","z":"fea6c6ef.fe6498","name":"Is light in blink array","func":"var blink = flow.get(\"blink\")||[];\nvar isInArray = false;\nif (blink.length > 0){\n    isInArray = blink.filter(function (value, index, array){\n       return value == msg.lightLabel; \n    })\n}\nif (isInArray) {\n    return [msg, null];\n}\nelse {\n    return [null, msg];\n}","outputs":2,"noerr":0,"x":700,"y":240,"wires":[["e4befec2.56f5e"],["58689464.f2402c"]]},{"id":"32475087.693c5","type":"change","z":"fea6c6ef.fe6498","name":"","rules":[{"t":"set","p":"lightLabel","pt":"msg","to":"payload.label","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":240,"wires":[["82044f04.81a8c"]]},{"id":"e4befec2.56f5e","type":"debug","z":"fea6c6ef.fe6498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":180,"wires":[]},{"id":"fb5c61ae.47d1b","type":"comment","z":"fea6c6ef.fe6498","name":"Initial entry point","info":"","x":100,"y":180,"wires":[]},{"id":"ca7cdc4.5d2902","type":"comment","z":"fea6c6ef.fe6498","name":"Last timer before switch the light OFF","info":"","x":410,"y":680,"wires":[]},{"id":"771db72b.f2f368","type":"comment","z":"fea6c6ef.fe6498","name":"LOOP","info":"","x":1190,"y":40,"wires":[]},{"id":"996bcc70.92a13","type":"openhab2-controller","z":"","name":"OH2","protocol":"http","host":"your_host","port":"8080","path":"","username":"","password":""}]

EDIT 1 : added .rules file
EDIT 2 : Auto OFF after 2 x timer with blink alert (1 minute before going OFF)

Any improvement are welcome !

Could a have a peak at your notification rule? I had some problems making it work.
thanks

Sure, updated my post
And updated it a second time with improvement.

1 Like

Hello, can someone explain to me how to build an if…then…else statement with Nodered?
I try to build a logic that when the light intensity (from the motion detector) is> 39 and when a switch is pressed to light a lamp.

Thx.

You will need to set a global variable with one of the values and then compare it in a function node.
It will be easier in the DSL in this case

Isn’t it a bit overkill to use a global variable ? I think he should use a flow variable.

@hermann1514 when you say “is pressed” does it means that it is when you press the switch that you want to check if light intensity is > 39 ?

If YES : take a look at my flow : Node-RED as Alternative Rule Engine
You will see how to get another item state in the same flow. Just don’t forget to store previous values

If NO : I think I understand what you mean and I can show you a flow but I’m not at home now. :wink:

Hello,

for example, I have 2 devices: A motion detector and a Türkontakt.Wenn the motion detector, a brightness of less than 39 and the door contact is open, the light should come on. There should be a possibility in Nodered that if two or more states are true or have a certain value that the light is switched. Excuse me. I’m still pretty new to NodeRed …

And…do you have some Screenshots :wink:

Thx.

Try this

[{"id":"14824bc.042abb4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7d67af5c.419b7","type":"switch","z":"14824bc.042abb4","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"yourMotionItem","vt":"str"},{"t":"cont","v":"yourContactItem","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["9b43469b.160dd8"],["fd027f8a.69699"]]},{"id":"9b43469b.160dd8","type":"switch","z":"14824bc.042abb4","name":"","property":"payload.value","propertyType":"msg","rules":[{"t":"neq","v":"yourMotionItem","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":160,"wires":[["2a52616f.aa4bae"]]},{"id":"2a52616f.aa4bae","type":"change","z":"14824bc.042abb4","name":"","rules":[{"t":"set","p":"yourMotionItem","pt":"flow","to":"(\t    if (payload.value < 39)\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":160,"wires":[["58ebd238.f8f04c"]]},{"id":"62ccf864.2e4878","type":"change","z":"14824bc.042abb4","name":"","rules":[{"t":"set","p":"yourContactItem","pt":"flow","to":"(\t    if (payload.value != \"ON\")\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":240,"wires":[["58ebd238.f8f04c"]]},{"id":"fd027f8a.69699","type":"switch","z":"14824bc.042abb4","name":"","property":"payload.value","propertyType":"msg","rules":[{"t":"neq","v":"yourContactItem","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":240,"wires":[["62ccf864.2e4878"]]},{"id":"58ebd238.f8f04c","type":"switch","z":"14824bc.042abb4","name":"","property":"(\t    if (flow.yourMotionItem and flow.yourContactItem )\t)","propertyType":"jsonata","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":990,"y":200,"wires":[["d2898229.8cb84"],["1944ac1c.950b14"]]},{"id":"d2898229.8cb84","type":"openhab2-out","z":"14824bc.042abb4","name":"","controller":"","itemname":"","topic":"ItemCommand","payload":"ON","x":1200,"y":160,"wires":[]},{"id":"1944ac1c.950b14","type":"openhab2-out","z":"14824bc.042abb4","name":"","controller":"","itemname":"","topic":"ItemCommand","payload":"OFF","x":1200,"y":240,"wires":[]},{"id":"5016f9a0.819e38","type":"comment","z":"14824bc.042abb4","name":"filter your items","info":"","x":280,"y":360,"wires":[]},{"id":"63b3cba.393f634","type":"comment","z":"14824bc.042abb4","name":"has it changed ?","info":"","x":520,"y":360,"wires":[]},{"id":"30252ce8.def2e4","type":"comment","z":"14824bc.042abb4","name":"Save value","info":"","x":720,"y":360,"wires":[]},{"id":"ba94b11c.17e83","type":"comment","z":"14824bc.042abb4","name":"Are the two values set ?","info":"","x":980,"y":360,"wires":[]},{"id":"bc7c0ea6.01904","type":"comment","z":"14824bc.042abb4","name":"Switch the light OFF","info":"","x":1390,"y":240,"wires":[]},{"id":"ae8c4b8b.fbb178","type":"comment","z":"14824bc.042abb4","name":"Switch the light ON","info":"","x":1390,"y":160,"wires":[]},{"id":"42c25e00.f297b","type":"openhab2-events","z":"14824bc.042abb4","name":"","controller":"","itemname":"","x":100,"y":200,"wires":[["7d67af5c.419b7"]]}]

Hi. thanks. But i receive an error on the Switch “set flow.dummy3”…

Can you help?

Yep sorry I should have test before…

Juste type in : payload.value != “ON”

Same for the other one and the last switch too…

Hi.

Sorry, but I think I’m too stupid for that. Can you even send me the complete version - and maybe test it before :wink:
I can not do it.

Thx.

You will not get help here by asking others to do it for you. We will offer help, and you should try…if you need more help, we will help, but again, we will not do.

I could give you a complete answer (TBH I already have it in my flows because I already test it before you asked me to do it).
But I won’t really help you if I give you the complete solution !

Try to understand how it works, what is asked to you for a node to work properly. If you do not try yourself, you will always be dependant of our help.

Another help : import this node as an example

[{"id":"7a4c924.bf1d06c","type":"change","z":"9d27bbb4.fb2c68","name":"","rules":[{"t":"set","p":"test1","pt":"flow","to":"payload.value != \"ON\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":160,"wires":[["18e8880a.37ceb8","a777a8f1.e3a2d8"]]}]

Ps : don’t forget the proverb “give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime”

Hello.
It was not my intention to let you do my work. I’ve really spent a few hours on the example and could not find the problem - since I thought this example works.
I will continue to play around with it - eventually it will work out well.

Thanks to scantineau for your help and suggestions.

THx.
Regards
Hermann

Hi, after a long tinkering … I have now created the following flow. This seems to work so far. Is this way correct or can you optimize something here?

Here is my flow:

[{"id":"fcb208d5.874228","type":"change","z":"796b9f56.81c11","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":742,"y":450,"wires":[["cf82923c.d01488"]]},{"id":"cd658113.728ed8","type":"switch","z":"796b9f56.81c11","name":"brightness_flow","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"49","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":458,"y":480,"wires":[["fcb208d5.874228"],["a87776ec.8c31c8"]]},{"id":"9583570f.064978","type":"change","z":"796b9f56.81c11","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":749,"y":611,"wires":[["cf82923c.d01488"]]},{"id":"ef26b4b0.410e08","type":"switch","z":"796b9f56.81c11","name":"switch_flow","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":455,"y":627,"wires":[["9583570f.064978"],["b7803c80.a03978"]]},{"id":"cf82923c.d01488","type":"switch","z":"796b9f56.81c11","name":"True or not","property":"$flowContext('dummy') and $flowContext('dummy2')","propertyType":"jsonata","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1026,"y":545,"wires":[["844b802d.d92dc"],["8c962719.dbbb"]]},{"id":"a87776ec.8c31c8","type":"change","z":"796b9f56.81c11","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":742,"y":495,"wires":[["cf82923c.d01488"]]},{"id":"b7803c80.a03978","type":"change","z":"796b9f56.81c11","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":748,"y":652,"wires":[["cf82923c.d01488"]]},{"id":"844b802d.d92dc","type":"openhab2-out","z":"796b9f56.81c11","name":"","controller":"","itemname":"dummy2","topic":"ItemCommand","payload":"ON","x":1276,"y":503,"wires":[]},{"id":"8c962719.dbbb","type":"openhab2-out","z":"796b9f56.81c11","name":"","controller":"","itemname":"dummy2","topic":"ItemCommand","payload":"OFF","x":1281,"y":591,"wires":[]},{"id":"1312a074.33c36","type":"openhab2-in","z":"796b9f56.81c11","name":"","controller":"","itemname":"dummy","x":89,"y":635,"wires":[["ef26b4b0.410e08"],[]]},{"id":"12194930.c2dbc7","type":"openhab2-in","z":"796b9f56.81c11","name":"","controller":"","itemname":"Stube_Bewegungsmelder_Brightness","x":187,"y":486,"wires":[["cd658113.728ed8"],[]]}]

`