Help with a flow

Greetings,
I’m coming from Hubitat, which has a powerfull Rule machine for newbies like me…but felt in love with HA so i’m trying to learn.
I have very basics skills of Node Red (watching few tutorial on Youtube…) and i have problems with a flow.
basically I have a Light which is controlled for a Motion sensor and a Contact. If any of the two sensors in on, the light shouldn’t turn off.
The main problem I have is when the movement sensor goes off, but the contact remain open…the lights turn off.
I been spending all night watching for a solution…Finally I made it work. But I think I created a Frankstein’s code…and I would like to improve if anyone want wish to help me pls.

Thanks in advance…I hope my flow make u all laugh atleast :slight_smile:
Regards,
Marc.

The main problem is the “OFF” part (bottom one ofc). I madre a trigger that refresh every 2 sec while it loops the status of the contact and movement sensor.
Then if a Sensor is ON, I made a Reset Timer that stops the light to turn off, and if both sensors are OFF the lights are turned off after 30 sec.
Thanks in advance again :slight_smile:

break the bottom part into a separate piece where you listen for both sensors to be off and then turn the light off.

[{"id":"5c43ad0278304f6d","type":"trigger-state","z":"c89d915bdff0f798","name":"","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":["sensor.motion","sensor.contact"],"entityidfiltertype":"list","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"sensor.moiton","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"targetType":"entity_id","targetValue":"sensor.contact","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":256,"y":2064,"wires":[["a3ba3c562ac113a0"],["608b9d8a8cd3b7ed"]]},{"id":"a3ba3c562ac113a0","type":"trigger","z":"c89d915bdff0f798","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":650,"y":2064,"wires":[["d9f4b3b8847f0150"]]},{"id":"608b9d8a8cd3b7ed","type":"change","z":"c89d915bdff0f798","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":498,"y":2112,"wires":[["a3ba3c562ac113a0"]]},{"id":"d9f4b3b8847f0150","type":"debug","z":"c89d915bdff0f798","name":"turn off lights","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":822,"y":2064,"wires":[]}]

or you could do what you’re doing but put the two current state nodes in series not parallel

1 Like

Thanks a lot, i’m going to try that flow tonight :slight_smile: