Node-red flow to leave light ON if already ON

Hi guys, I have been messing with this for a while but just can’t figure it out. What I have is a sliding door contact that when opens turns on LED lights on the porch during certain hours of the night and turns off after set time (25 seconds) in this example. That part works great.

If I am out there on the porch and I turn on the LED lights while entertaining my guest, and the sliding door opens, I don’t want it to trigger the timer, but instead do nothing since the light was already on. How can I get the flow to cancel if the LED lights are already on?

I put conditions in the trigger-state node but that didn’t seem to work. What happens is if the lights are already on, and the door opens, the lights flash quickly and turns off 25 seconds later. Just want the lights to remain on unless the lights were off.

[{"id":"2c4ea8fe.401718","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"304e7974.ccbde6","type":"time-range-switch","z":"2c4ea8fe.401718","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":470,"y":80,"wires":[["885318ec.a4d0d8"],[]]},{"id":"e542fad2.7d27a8","type":"stoptimer","z":"2c4ea8fe.401718","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":570,"y":340,"wires":[["ef4e817b.facd5"],[]]},{"id":"ef4e817b.facd5","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights OFF","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":480,"wires":[[]]},{"id":"885318ec.a4d0d8","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights ON","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":480,"y":200,"wires":[["e542fad2.7d27a8"]]},{"id":"685b974d.d7aae8","type":"trigger-state","z":"2c4ea8fe.401718","name":"Sliding Door Open","server":"6821cdda.fbbcd4","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sliding_door_contact","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"light.801068338cce4ec36777","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":150,"y":140,"wires":[["304e7974.ccbde6"],[]]},{"id":"6821cdda.fbbcd4","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

You pasted only one node instead whole automation. in addition messed up with image tag you wanted to paste here.

Oh no… Here it its, my first post… go easy on me. LOL

[{"id":"2c4ea8fe.401718","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"304e7974.ccbde6","type":"time-range-switch","z":"2c4ea8fe.401718","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":470,"y":80,"wires":[["885318ec.a4d0d8"],[]]},{"id":"e542fad2.7d27a8","type":"stoptimer","z":"2c4ea8fe.401718","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":570,"y":340,"wires":[["ef4e817b.facd5"],[]]},{"id":"ef4e817b.facd5","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights OFF","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":480,"wires":[[]]},{"id":"885318ec.a4d0d8","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights ON","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":480,"y":200,"wires":[["e542fad2.7d27a8"]]},{"id":"685b974d.d7aae8","type":"trigger-state","z":"2c4ea8fe.401718","name":"Sliding Door Open","server":"6821cdda.fbbcd4","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sliding_door_contact","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"light.801068338cce4ec36777","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":170,"y":80,"wires":[["304e7974.ccbde6"],[]]},{"id":"6821cdda.fbbcd4","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

What you could do is add a change node between the light switch and the timer that sends stops the timer

[{"id":"304e7974.ccbde6","type":"time-range-switch","z":"2c4ea8fe.401718","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":570,"y":80,"wires":[["885318ec.a4d0d8"],[]]},{"id":"e542fad2.7d27a8","type":"stoptimer","z":"2c4ea8fe.401718","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":570,"y":340,"wires":[["ef4e817b.facd5"],[]]},{"id":"ef4e817b.facd5","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights OFF","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":480,"wires":[[]]},{"id":"885318ec.a4d0d8","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights ON","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":480,"y":200,"wires":[["e542fad2.7d27a8"]]},{"id":"685b974d.d7aae8","type":"trigger-state","z":"2c4ea8fe.401718","name":"Sliding Door Open","server":"6821cdda.fbbcd4","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sliding_door_contact","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"light.801068338cce4ec36777","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":170,"y":80,"wires":[["304e7974.ccbde6"],[]]},{"id":"50211d97661222bb","type":"change","z":"2c4ea8fe.401718","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":300,"wires":[["e542fad2.7d27a8"]]},{"id":"23265186644c9b37","type":"server-state-changed","z":"2c4ea8fe.401718","name":"Light Switch","server":"fcbb557.4bc97a8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":220,"wires":[["50211d97661222bb"]]},{"id":"6821cdda.fbbcd4","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"fcbb557.4bc97a8","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Thanks for your help… after adding change node it still turns off the light if it was on before door opens.

I’m wondering if there is another automation shutting the light, the flow you first had should be ok. You could try disabling the flow and making sure there isn’t something else shutting the light off.

You could try moving the condition the lights off out of the trigger node.

[{"id":"304e7974.ccbde6","type":"time-range-switch","z":"2c4ea8fe.401718","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":850,"y":80,"wires":[["885318ec.a4d0d8"],[]]},{"id":"e542fad2.7d27a8","type":"stoptimer","z":"2c4ea8fe.401718","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":950,"y":340,"wires":[["ef4e817b.facd5"],[]]},{"id":"ef4e817b.facd5","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights OFF","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":820,"y":480,"wires":[[]]},{"id":"885318ec.a4d0d8","type":"api-call-service","z":"2c4ea8fe.401718","name":"Porch LED Lights ON","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":200,"wires":[["e542fad2.7d27a8"]]},{"id":"685b974d.d7aae8","type":"trigger-state","z":"2c4ea8fe.401718","name":"Sliding Door Open","server":"6b1110b5.183a4","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sliding_door_contact","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":170,"y":80,"wires":[["9a021b957b909495"],[]]},{"id":"9a021b957b909495","type":"api-current-state","z":"2c4ea8fe.401718","name":"","server":"6b1110b5.183a4","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.801068338cce4ec36777","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":490,"y":80,"wires":[[],["304e7974.ccbde6"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

edit: yeah just like above :slight_smile:

putting a current state node after your trigger did the trick (you’ll have to change entities back, i changed to test with mine)

[{"id":"67f9997ddcf5ed3c","type":"time-range-switch","z":"85158685cafb26f7","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":590,"y":80,"wires":[["4416bd374a663ae2"],[]]},{"id":"c1d3445f2dbb668b","type":"stoptimer","z":"85158685cafb26f7","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":570,"y":220,"wires":[["bd3c624dfe8655e1"],[]]},{"id":"bd3c624dfe8655e1","type":"api-call-service","z":"85158685cafb26f7","name":"Porch LED Lights OFF","server":"6821cdda.fbbcd4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.bedroom_light","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":300,"wires":[[]]},{"id":"4416bd374a663ae2","type":"api-call-service","z":"85158685cafb26f7","name":"Porch LED Lights ON","server":"fcbb557.4bc97a8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.bedroom_light","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":140,"wires":[["c1d3445f2dbb668b"]]},{"id":"bf38eb869b87436b","type":"trigger-state","z":"85158685cafb26f7","name":"Sliding Door Open","server":"fcbb557.4bc97a8","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.toilet_sensor_occupancy","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":190,"y":80,"wires":[["68b6646a0e97e5ad"],[]]},{"id":"68b6646a0e97e5ad","type":"api-current-state","z":"85158685cafb26f7","name":"Light off?","server":"6821cdda.fbbcd4","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.bedroom_light","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":380,"y":80,"wires":[["67f9997ddcf5ed3c"],[]]},{"id":"6821cdda.fbbcd4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"fcbb557.4bc97a8","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Not sure why its not working for me… I don’t haven’t other automation for that light. Still goes off when on and the door is open after.

Not sure why its not working for me… I don’t haven’t other automation for that light. Still goes off when on and the door is open after.

There is something else maybe the entity is wrong in the current state node? If the light is on, the message can not get to the timer.

Look at the debug if the message gets through.

[{"id":"7bfa59b6010f74fe","type":"time-range-switch","z":"f80b6c338afd5483","name":"Hours Between 7pm to 6:30am","lat":"","lon":"","startTime":"16:00","endTime":"06:30","startOffset":0,"endOffset":0,"x":1410,"y":980,"wires":[["9b9a81be07b7857f"],[]]},{"id":"cf1a6f03a335f7e0","type":"stoptimer","z":"f80b6c338afd5483","duration":"25","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":1390,"y":1260,"wires":[["ba5774cf8d758f32"],[]]},{"id":"ba5774cf8d758f32","type":"api-call-service","z":"f80b6c338afd5483","name":"Porch LED Lights OFF","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1260,"y":1400,"wires":[[]]},{"id":"9b9a81be07b7857f","type":"api-call-service","z":"f80b6c338afd5483","name":"Porch LED Lights ON","server":"6b1110b5.183a4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.801068338cce4ec36777","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1300,"y":1120,"wires":[["cf1a6f03a335f7e0"]]},{"id":"d3b84d9e3799e3bd","type":"trigger-state","z":"f80b6c338afd5483","name":"Sliding Door Open","server":"6b1110b5.183a4","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sliding_door_contact","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":610,"y":1000,"wires":[["836c1d810edae4ea"],[]]},{"id":"836c1d810edae4ea","type":"api-current-state","z":"f80b6c338afd5483","name":"","server":"6b1110b5.183a4","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.801068338cce4ec36777","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":930,"y":1000,"wires":[["67f1963c0a4beb35"],["7bfa59b6010f74fe","5cfc56e16672fa5c"]]},{"id":"5cfc56e16672fa5c","type":"debug","z":"f80b6c338afd5483","name":"false","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":1160,"wires":[]},{"id":"67f1963c0a4beb35","type":"debug","z":"f80b6c338afd5483","name":"true","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":920,"wires":[]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

OMG, It works…I didn’t realize I was referring the wrong entity. Thank you, thank you.

1 Like

Xalies, you were also correct… I was referring the incorrect entity ID. Thank you for your assistance.