Hall lighting automation

Hello

Recently moved to Home Assistant and node red after coming from SmartThings so apologies if this is a basic question but I’m trying to get my head round node red still.

I’m trying to set up an automation in that when a sensor detects motion it turns a light on and then after 10 seconds if there is no motion it turns it off. I can get that working fine but what I’m trying to stop it doing is that if the light was already on before motion was detected it doesn’t just turn the light off after motion stops. I want it to leave it on.

In smartthings I had some sort of value stored elsewhere so that when it automatically turned the light on it created a flag and when it come to turning it off it would only do that if the flag was on. I assume I need to do something similar but can’t get my head round how.
Can someone help please

Use the “current state node”.

Then configure:
image

And connect to the top notch:
image

(you can also select “on” as true).

Expanding on what @sender suggested, your flow could look like this:

When the light is already on, it doesn’t adjust it and doesn’t set a flow variable. Then, when motion stops, if the flow variable isn’t true, it doesn’t turn the lights off.

Ok, that is starting to make sense now although I’m not sure about setting up the payload bit?

Ah, my infamous “Setup payload” function nodes. LOL

I use these in all of my motion flows because I use scenes for all my lights that match modes I have setup in HA using TOD sensors (Times of the day sensor).

You can just remove it from your flow unless you want to setup TOD sensors, scenes to match those sensors and a global variable.

This flow may look a bit complicated but mimics how the Philips Hue Hub deals with motion.

  • Based on the time and light level it will turn the lights on when motion is detected.

  • It then checks if there is motion for 30 seconds, every second before dimming lights

  • It then checks for motion for the next 30 seconds, every second before turning off the lights

  • If at any point motion is detected it turns the lights back to its preset brightness and starts motion detection from the beginning again.

With some exceptions:

  • After 23.00 the lights are set to dim so it doesn’t dim them after 30 seconds but checks for motion for every second for 60 seconds before turning them off.

  • If the alarm is not disarmed then this flow is not triggered - I have different settings for this when alarm is armed and triggered

I’m using Hue Motion sensors so they re-trigger quickly. Other motion sensors may not but this works well with the setup I have.

You may need to change your entities names in the nodes in this flow and also add your longitude/latitude to the time interval nodes.

[{"id":"424d9ac3.5584d4","type":"time-range-switch","z":"fe3260af.8794a","name":"","lat":"","lon":"","startTime":"23:00","endTime":"sunrise","startOffset":0,"endOffset":"-60","x":1080,"y":260,"wires":[["203ed480.2c666c"],["3af12b2.4c782d4"]]},{"id":"6e259947.91879","type":"server-state-changed","z":"fe3260af.8794a","name":"Hallway Motion Detected","server":"60e1db70.15c0ec","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hallway_motion_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":250,"y":260,"wires":[["5651771c.45784"],[]]},{"id":"cddd65bf.d0199","type":"api-current-state","z":"fe3260af.8794a","name":"Halway Lux","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"24","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.hallway_motion_sensor_light_level","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":870,"y":260,"wires":[["424d9ac3.5584d4"],[]]},{"id":"3af12b2.4c782d4","type":"api-call-service","z":"fe3260af.8794a","name":"turn on hallway lights","server":"60e1db70.15c0ec","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.hallway_tropical_twilight","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1340,"y":260,"wires":[[]]},{"id":"5651771c.45784","type":"api-current-state","z":"fe3260af.8794a","name":"Check Disarmed Status","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"disarmed","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"alarm_control_panel.house","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":510,"y":260,"wires":[["6a0466ff.f2e66"],[]]},{"id":"6a0466ff.f2e66","type":"delay","z":"fe3260af.8794a","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":710,"y":260,"wires":[["cddd65bf.d0199"]]},{"id":"ad328435.e0ca8","type":"api-call-service","z":"fe3260af.8794a","name":"Dim hallway  lights","server":"60e1db70.15c0ec","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1550,"y":420,"wires":[["94e778ef.c10898"]]},{"id":"c0efba0d.362bf","type":"api-call-service","z":"fe3260af.8794a","name":"turn off  hallway  lights","server":"60e1db70.15c0ec","version":1,"service_domain":"light","service":"turn_off","entityId":"group.hallway_lights_group","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2280,"y":420,"wires":[[]]},{"id":"f04ce98a.5442e","type":"api-current-state","z":"fe3260af.8794a","name":"Check Disarmed Status","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"disarmed","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"alarm_control_panel.house","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":510,"y":420,"wires":[["9192cf29.2589d"],[]]},{"id":"461f2314.0ff6dc","type":"time-range-switch","z":"fe3260af.8794a","name":"","lat":"","lon":"","startTime":"23:00","endTime":"sunrise","startOffset":0,"endOffset":"-60","x":800,"y":420,"wires":[["f291b906.96697"],["22f9ad9f.f0caa2"]]},{"id":"fbea3a58.cd7648","type":"server-state-changed","z":"fe3260af.8794a","name":"Hallway Motion Detected","server":"60e1db70.15c0ec","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hallway_motion_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":270,"y":420,"wires":[["f04ce98a.5442e"],[]]},{"id":"22f9ad9f.f0caa2","type":"api-current-state","z":"fe3260af.8794a","name":"Check Motion","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.hallway_motion_sensor","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1040,"y":420,"wires":[[],["ce8a0f2a.6c3d1"]]},{"id":"94e778ef.c10898","type":"api-current-state","z":"fe3260af.8794a","name":"Check Motion","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.hallway_motion_sensor","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1780,"y":420,"wires":[["424d9ac3.5584d4"],["d5f89f14.c0efa8"]]},{"id":"a18ee953.7ebe4","type":"delay","z":"fe3260af.8794a","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2019,"y":500,"wires":[["94e778ef.c10898"]]},{"id":"d5f89f14.c0efa8","type":"counter-loop","z":"fe3260af.8794a","name":"","counter":"ile86d4036d62498","counterType":"msg","reset":true,"resetValue":"value-null","initial":0,"initialType":"num","operator":"lt","termination":"31","terminationType":"num","increment":1,"incrementType":"num","x":2020,"y":420,"wires":[["c0efba0d.362bf"],["a18ee953.7ebe4"]]},{"id":"ce8a0f2a.6c3d1","type":"counter-loop","z":"fe3260af.8794a","name":"","counter":"ile86d4036d62498","counterType":"msg","reset":true,"resetValue":"value-null","initial":0,"initialType":"num","operator":"lt","termination":"31","terminationType":"num","increment":1,"incrementType":"num","x":1280,"y":420,"wires":[["ad328435.e0ca8"],["8656a797.318f1"]]},{"id":"8656a797.318f1","type":"delay","z":"fe3260af.8794a","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1180,"y":500,"wires":[["22f9ad9f.f0caa2"]]},{"id":"203ed480.2c666c","type":"api-call-service","z":"fe3260af.8794a","name":"turn on hallway lights dim","server":"60e1db70.15c0ec","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":\"30\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1350,"y":220,"wires":[[]]},{"id":"505295af.695e04","type":"api-call-service","z":"fe3260af.8794a","name":"turn off  hallway  lights","server":"60e1db70.15c0ec","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.hallway_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":700,"wires":[[]]},{"id":"f291b906.96697","type":"api-current-state","z":"fe3260af.8794a","name":"Check Motion","server":"60e1db70.15c0ec","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.hallway_motion_sensor","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":640,"wires":[[],["42bf161a.09baa"]]},{"id":"a7f6a3db.667ef","type":"delay","z":"fe3260af.8794a","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1080,"y":680,"wires":[["f291b906.96697"]]},{"id":"42bf161a.09baa","type":"counter-loop","z":"fe3260af.8794a","name":"","counter":"ile86d4036d62498","counterType":"msg","reset":true,"resetValue":"value-null","initial":0,"initialType":"num","operator":"lt","termination":"61","terminationType":"num","increment":1,"incrementType":"num","x":880,"y":700,"wires":[["505295af.695e04"],["a7f6a3db.667ef"]]},{"id":"ab7ee7cf.53231","type":"comment","z":"fe3260af.8794a","name":"................... Hallway  Lights Motion Presence .................. ................... 2 Preset Light Levels - Hue Motion Presence..................","info":"","x":680,"y":160,"wires":[]},{"id":"56ee0f9b.e5f5d8","type":"api-current-state","z":"fe3260af.8794a","name":"Hallway Lights","server":"57ce5691.fd6e48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"group.hallway_lights_group","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":540,"wires":[["461f2314.0ff6dc"],[]]},{"id":"9192cf29.2589d","type":"delay","z":"fe3260af.8794a","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":620,"y":480,"wires":[["56ee0f9b.e5f5d8"]]},{"id":"87ddd38f.c0fd7","type":"comment","z":"fe3260af.8794a","name":"Lights already dim so check if motion is in next 60 seconds else turn lights off  ","info":"","x":1090,"y":600,"wires":[]},{"id":"92d9c7cb.343b78","type":"comment","z":"fe3260af.8794a","name":"Turn on Lights Flow ---->","info":"","x":270,"y":220,"wires":[]},{"id":"98d5d4c2.e068c8","type":"comment","z":"fe3260af.8794a","name":"Check for motion before turning off lights ---->","info":"","x":350,"y":360,"wires":[]},{"id":"60e1db70.15c0ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"57ce5691.fd6e48","type":"server","name":"Home Assistant","addon":true}]