Node Red flow for Motion activated lights

In my house, I have two motion sensors, one at the bottom of the stairs, and one at the top. These sensors are motion only and don’t report on LUX levels.

I wanted an automation that depending on the time of the day would turn them on to a preset brightness level, wait until there was no motion then turn them off.

Now, I found that when these sensors send an ‘off’ signal, there would be a delay of 60 seconds before they could be triggered again by motion, so to avoid inconvenience I built this 60-second delay into my flow:

I’m using these Sonoff sensors  (zigbee) in my setup.

As you can see, my lights only trigger if it is between 1.5 hours before sunset and 22:30 (lights on at 100%) or between 22:30 and an hour after sunrise (lights on at 10% so we are blinded in the middle of the night!). Outside of these times, the lights are controlled the old fashioned way!

When the motion sensor reports clear, there is a 60-second delay, a check that there are no new motion events, then turn the lights off. This delay means that when the lights go off, the sensors are in a state ready to be triggered again.

You can download the flow below and try it yourself.

[{"id":"7ceb8b16.efadb4","type":"time-range-switch","z":"fa51c4ec.696f78","name":"Dusk","lat":"53.20622","lon":"-0.46285","startTime":"sunset","endTime":"22:30","startOffset":"-1.5","endOffset":"","x":370,"y":160,"wires":[["7a9bca5.0c5d434","e9c052c6.29bb8","7b914dd3.b4b7d4"],[]]},{"id":"29481eea.e6c1e2","type":"api-call-service","z":"fa51c4ec.696f78","name":"","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.front_lobby","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":620,"wires":[[]]},{"id":"7a9bca5.0c5d434","type":"api-call-service","z":"fa51c4ec.696f78","name":"Downstairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front_lobby","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":100,"wires":[[]]},{"id":"e9c052c6.29bb8","type":"api-call-service","z":"fa51c4ec.696f78","name":"Upstairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.landing_light","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":740,"y":40,"wires":[[]]},{"id":"c305b7fa.48cc28","type":"api-call-service","z":"fa51c4ec.696f78","name":"","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.hall","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":480,"wires":[[]]},{"id":"739a9a89.0b1cf4","type":"time-range-switch","z":"fa51c4ec.696f78","name":"Dusk","lat":"53.20622","lon":"-0.46285","startTime":"22:30","endTime":"sunrise","startOffset":"-1","endOffset":"1","x":370,"y":220,"wires":[["8afc87ab.1ca8d8","2c35e04c.c92f9","8a2e049f.d43168"],[]]},{"id":"2c35e04c.c92f9","type":"api-call-service","z":"fa51c4ec.696f78","name":"Downstairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front_lobby","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":300,"wires":[[]]},{"id":"8afc87ab.1ca8d8","type":"api-call-service","z":"fa51c4ec.696f78","name":"Upstairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.landing_light","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":740,"y":240,"wires":[[]]},{"id":"7546e002.26c21","type":"api-current-state","z":"fa51c4ec.696f78","name":"","server":"eef365a0.94b4f8","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.stairs_bottom_motion_occupancy","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":490,"y":660,"wires":[["29481eea.e6c1e2"],["c546ca98.210e58"]]},{"id":"a57173b5.cac84","type":"api-current-state","z":"fa51c4ec.696f78","name":"","server":"eef365a0.94b4f8","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.stairs_top_motion_occupancy","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":500,"y":500,"wires":[["c305b7fa.48cc28"],["c546ca98.210e58"]]},{"id":"56cf4e65.133ce","type":"server-state-changed","z":"fa51c4ec.696f78","name":"Upstairs motion","server":"eef365a0.94b4f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.stairs_top_motion_occupancy","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":160,"wires":[["7ceb8b16.efadb4","739a9a89.0b1cf4"],["c546ca98.210e58"]]},{"id":"f560c9ed.bcec78","type":"server-state-changed","z":"fa51c4ec.696f78","name":"Upstairs motion","server":"eef365a0.94b4f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.stairs_bottom_motion_occupancy","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":220,"wires":[["739a9a89.0b1cf4","7ceb8b16.efadb4"],["c546ca98.210e58"]]},{"id":"c546ca98.210e58","type":"stoptimer","z":"fa51c4ec.696f78","duration":"60","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":230,"y":580,"wires":[["a57173b5.cac84","7546e002.26c21"],[]]},{"id":"7b914dd3.b4b7d4","type":"api-call-service","z":"fa51c4ec.696f78","name":"Stairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.stairs","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":160,"wires":[[]]},{"id":"8a2e049f.d43168","type":"api-call-service","z":"fa51c4ec.696f78","name":"Stairs","server":"eef365a0.94b4f8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.stairs","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":360,"wires":[[]]},{"id":"eef365a0.94b4f8","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.