Node-RED as Alternative Rule Engine

rules
node-red
Tags: #<Tag:0x00007f0e96161fd8> #<Tag:0x00007f0e96161e48>

(Vincent Regaud) #122

I have something at home I’ll have a look.


(Gad Ofir) #123

try big timer node


(Jompa68) #124

Want to use TOD for other stuff, so if i can get some example to use it will be perfect. I am a beginner of node-red and openhab2, still learning :slight_smile:


(Jompa68) #125

Goodmorning, did you find any examples?


(Vincent Regaud) #126

I was thinking about it last night.
What is your purpose for time of day?
If you are using Node-red as an alternative rule engine for OpenHAB there you will be better off using this:


(Rgerrans) #127

@jompa68 Sorry for the delayed response. I’ve fully moved of of OH at this point and use Node-Red and a handful of mqtt connected interfaces to run my system so don’t check this board regularly anymore.

That said, how I use ToD is two fold: 1) trigger events at a change in ToD; and 2) use a global variable to store the current ToD to check the point of executing another trigger. To be specific:

Below is a snapshot of some of my ToD triggers. You can see where I use it to Set my ToD variable and then pass them on to a link node and you can see where the links go in my system.

I have a BigTimer trigger to define “Evening” (which is defined at Sunset) and “Night” (defined as midnight. This then gets sent through the Link node to my landscape lights (and others like indoor table lamps I keep on from sunset to sunrise) where I check to see if it is either one of those two time events and turn the lights on/off accordingly:

From above you can also see where I set a brightness variable based on the ToD. I use this to set many of the dimmers in my house when they are turned on to that brightness interval (started in our master bathroom so I didn’t get blinded when I turned on the lights when I first get up before sunrise during the winter months. I actually created a subflow since I use this quite a bit throughout the house now and have to make sure the light is turning on, not just having a dimmer level adjustment.

Let me know if that helps or any other questions I can answer (be sure and flag me again to make sure I get notified).

.


(Rgerrans) #128

That’s where I started with my rules when I was in OH exclusively of using many of the design patterns approach (the ToD) came from one of them and I just translated it to Node-Red. So you can accomplish it in either it’s just if you are more comfortable in a scripted rule environment or a visual. For me the Node-Red environment was easier and provided much more functionality since I’m decades away from my programming days so it was easier to use pre-defined Nodes. For me I ended up replacing my OH setup overtime once I committed to mqtt as my communication bus and Node-Red as my rules engine (and some interfaces that are already built into Nodes).

So at the end of the day there is no right answer, both work. It’s just what ever works better for each person.


(Rgerrans) #129

You don’t have to, it can be installed in your pi user account just like OH. I ended up with mine in as root (don’t remember why now) and haven’t moved it back to my pi user account.


(Rgerrans) #130

I saw you solved it with a function node, you can also just use a change node to set msg.payload.level to 80 and achieve the same thing.


(Jompa68) #131

@rgerrans, I think I understand after I’ve seen your pictures. WIll see within 1 hour if i got it when evening start :grinning:
I will come back if i got more question, thanks again.

One thing, howto deal with sleepmode? If sleepmode is on i dont want that evening turn on lights


(Brian M. Pedersen) #132

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.


(Brian M. Pedersen) #133

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"]]}]

(Morten P) #135

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.


(Vincent Regaud) #136

Virtually instantaneous


(Morten P) #137

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


(Scantineau) #138

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 !


(Brian M. Pedersen) #139

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


(Scantineau) #140

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


(Hermann Mueller) #141

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.


(Vincent Regaud) #142

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