Motion triggered lights

I am aware that this topic has been addressed before and there are many flows out there to accomplish the same task, but I could not find a comprehensive flow that handles all aspects of motion-based triggering. I hope others will find it useful.

The idea is to wait for motion detection. Once detected, the lights should turn on if the time is after sunset (dark outside). With the lights on, we need them to stay on as long as motion is still detected, or if they are turned off manually. Once there is no more motion for 15 minutes, the lights should turn off and standby for another motion trigger.

image

[{"id":"de82d455.7709f8","type":"comment","z":"a4193cb.0d41ac","name":"Bathroom Lights","info":"# Master Bathroom Lights Automation Logic\nThis flow monitors motion in the Master Bathroom to turn on the Bathroom lights if it is dark. The lights should stay on for 15 minutes since the last motion detection then turn off automatically.\n\n","x":100,"y":380,"wires":[]},{"id":"97aebb2f908d6f02","type":"trigger","z":"a4193cb.0d41ac","name":"Turn them on for 15 mins","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"15","extend":false,"overrideDelay":true,"units":"min","reset":"reset","bytopic":"all","topic":"topic","outputs":2,"x":710,"y":560,"wires":[["d70122a7d11f1c0e"],["ca98d8f2ed12e674"]]},{"id":"b70a595bbed15ec7","type":"api-current-state","z":"a4193cb.0d41ac","name":"lights off?","server":"c8b3e58.9a76e18","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.master_bathroom_lights_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"on","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":300,"y":560,"wires":[["63b8c3ca4eda2d59"],["cbd33c0f9dac8a96"]]},{"id":"d70122a7d11f1c0e","type":"api-call-service","z":"a4193cb.0d41ac","name":"Turn on Lights","server":"c8b3e58.9a76e18","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.master_bathroom_lights_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":540,"wires":[[]]},{"id":"1ab8faf2a42facb2","type":"trigger-state","z":"a4193cb.0d41ac","name":"Just turned off","server":"c8b3e58.9a76e18","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.master_bathroom_lights_2","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"this_entity","targetValue":"","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":310,"y":640,"wires":[["23c8568c5cf59e10"],[]]},{"id":"6f5a233d3e0b4176","type":"api-call-service","z":"a4193cb.0d41ac","name":"Turn off Lights","server":"c8b3e58.9a76e18","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.master_bathroom_lights_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":700,"wires":[[]]},{"id":"23c8568c5cf59e10","type":"change","z":"a4193cb.0d41ac","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":640,"wires":[["dbb25c6ea8d1d836"]]},{"id":"ca98d8f2ed12e674","type":"api-current-state","z":"a4193cb.0d41ac","name":"Lights are on?","server":"c8b3e58.9a76e18","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.master_bathroom_lights_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":940,"y":620,"wires":[["6f5a233d3e0b4176"],[]]},{"id":"0c6f3b0dd7511448","type":"change","z":"a4193cb.0d41ac","name":"extend","rules":[{"t":"set","p":"delay","pt":"msg","to":"900000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":700,"wires":[["4eed6787d2ad2899"]]},{"id":"2bb0794d1f65d0ea","type":"trigger-state","z":"a4193cb.0d41ac","name":"motion?","server":"c8b3e58.9a76e18","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.master_bathroom_presence_sensor","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":110,"y":440,"wires":[["4b2a199b4ccb0c31"],[]]},{"id":"4eed6787d2ad2899","type":"link out","z":"a4193cb.0d41ac","name":"extend","mode":"link","links":["6fdee0fe4d750458"],"x":565,"y":700,"wires":[]},{"id":"6fdee0fe4d750458","type":"link in","z":"a4193cb.0d41ac","name":"","links":["4eed6787d2ad2899"],"x":615,"y":520,"wires":[["97aebb2f908d6f02"]]},{"id":"4b2a199b4ccb0c31","type":"time-range-switch","z":"a4193cb.0d41ac","name":"Dark Outside","lat":"26.164777","lon":"50.575251","startTime":"sunsetStart","endTime":"sunriseEnd","startOffset":"0","endOffset":"5","x":170,"y":500,"wires":[["b70a595bbed15ec7"],[]]},{"id":"b717da7be90b83d1","type":"link in","z":"a4193cb.0d41ac","name":"reset","links":["ef3709d14051a554","dbb25c6ea8d1d836"],"x":615,"y":600,"wires":[["97aebb2f908d6f02"]]},{"id":"dbb25c6ea8d1d836","type":"link out","z":"a4193cb.0d41ac","name":"reset","mode":"link","links":["b717da7be90b83d1","0040ebcb02d9fef8"],"x":565,"y":640,"wires":[]},{"id":"f09442224461776a","type":"trigger-state","z":"a4193cb.0d41ac","name":"new motion?","server":"c8b3e58.9a76e18","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.master_bathroom_presence_sensor","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":310,"y":700,"wires":[["0c6f3b0dd7511448"],[]]},{"id":"81d2b619741dfdca","type":"trigger-state","z":"a4193cb.0d41ac","name":"Lights are on?","server":"c8b3e58.9a76e18","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.master_bathroom_lights_2","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":150,"y":700,"wires":[["f09442224461776a"],[]]},{"id":"63b8c3ca4eda2d59","type":"trigger","z":"a4193cb.0d41ac","name":"once-off","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"0","extend":false,"overrideDelay":true,"units":"min","reset":"reset","bytopic":"all","topic":"topic","outputs":1,"x":460,"y":560,"wires":[["97aebb2f908d6f02"]]},{"id":"0040ebcb02d9fef8","type":"link in","z":"a4193cb.0d41ac","name":"reset","links":["ef3709d14051a554","dbb25c6ea8d1d836"],"x":415,"y":520,"wires":[["63b8c3ca4eda2d59"]]},{"id":"cbd33c0f9dac8a96","type":"link out","z":"a4193cb.0d41ac","name":"extend-on","mode":"link","links":[],"x":415,"y":600,"wires":[]},{"id":"c8b3e58.9a76e18","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30"}]

Flow Info

Created 3 years, 2 months ago
Rating: 5 3

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • comment (x1)
  • link in (x3)
  • link out (x3)
  • trigger (x2)
Other

Tags

  • Trigger
  • Delay
  • Motion
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option