Last updated on August 31, 2024
One of my theories on how I approach home automation is that I want to have as many inputs into the system so that it can make better decisions of what to do. With this ethos in mind, I have peppered my house with motion sensors. As of this writing, I’m at 32x AM312 sensors tied to various ESP8266/ESP32 boards. More inputs are provided with another 8x door sensors and 5x ONVIF motion sensors from cameras.
Now that you are armed with Home Assistant knowing the state of various motion sensors and doors, it’s time to automate some lighting. While Home Assistant continues to improve it’s automation UI, I think the visual nature of Node-Red is much easier to use. I’ve included the JSON to all of the flows at the bottom of this article.
Basic Motion Control
In a basic motion control lighting flow, I want the light to come on when motion is detected, stay on for a certain amount of time, and turn off after some time that motion has not been detected. If a new motion event is detected, it resets the timer. To have the ability to stop these flows from operating, I have added an input_boolean for each of my motion sensors to disable the flow. Make sure to enable extend delay if new message arrives on the trigger nodes
1 2 3 4 |
input_boolean: motion_detection_projector_screen: name: Projector Screen icon: mdi:motion-sensor |
But wait, this should only happen when it’s dark outside. So I use the time-range-switch node to set a specific time range when I want the flow to continue.
Adding some complexity
Now I want to add some additional inputs and logic into my lighting flow. In this case, this light is located near a door. So I’m using the door sensor to trigger the lighting flow the same way that the motion sensor trigger’s the flow. This area is also where I have my BBQ grill, and when BBQing, I have an input boolean that I turn on that I use to trigger many actions. I also use it in this lighting flow to determine how long the light should stay on. If I’m BBQing, it turns on a 15 minute time while if I’m not it’s only for 1 minute.
Another thing that I’ve done is changed the color and brightness of the light that gets turned on. For example, during the middle of the night, I want my RGB light to turn on a dim red color so it’s easier to fall back asleep. To configure these additional attributes, you use the data field and pass on anything that Home Assistant can normally do with that light in JSON formatting. You can view the available attributes for any light by going to Developer Tools and clicking that entity
That’s all for part 1. In part 2 I will go over some of my more advanced flows with lighting.
JSON code for import into Node RED
1 |
[{"id":"194176c5.594ba9","type":"server-state-changed","z":"5d722b12.a14d84","name":"Motion","server":"c75798f0.9eb148","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.workshop_motion","entityidfiltertype":"substring","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":3730,"y":1420,"wires":[["b136365.797eac8"],[]]},{"id":"9c4e2d89.c527a","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn on","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.garage_light_1_d1, light.workshop_desk_shelf_strip_1, light.workshop_desk_shelf_strip_2","data":"{\"brightness_pct\":70,\"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":4360,"y":1420,"wires":[[]]},{"id":"251f5b40.fb65f4","type":"comment","z":"5d722b12.a14d84","name":"Workshop Motion","info":"","x":3730,"y":1360,"wires":[]},{"id":"b136365.797eac8","type":"api-current-state","z":"5d722b12.a14d84","name":"Motion Activated?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.motion_detection_workshop_desk","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":3950,"y":1420,"wires":[["8f243b49.691408","509cfdf2.50f5c4"],[]]},{"id":"5649c0f1.3595e","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn off","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.garage_light_1_d1, light.workshop_desk_shelf_strip_1, light.workshop_desk_shelf_strip_2","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":4360,"y":1480,"wires":[[]]},{"id":"8f243b49.691408","type":"api-current-state","z":"5d722b12.a14d84","name":"Light is off?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"false","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"light.garage_light_1_d1","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":4170,"y":1420,"wires":[["9c4e2d89.c527a"],[]]},{"id":"509cfdf2.50f5c4","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"8","extend":true,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":4170,"y":1480,"wires":[["5649c0f1.3595e"]]},{"id":"c75798f0.9eb148","type":"server","name":"Home Assistant Synology","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":true}] |
1 |
[{"id":"a6366b09.8b2b68","type":"server-state-changed","z":"5d722b12.a14d84","name":"Motion","server":"c75798f0.9eb148","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.workshop_motion","entityidfiltertype":"substring","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":2740,"y":1990,"wires":[["13fa0050.3d3fd"],[]]},{"id":"9264eda4.6acbf","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn on","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.garage_light_1_d1, light.workshop_desk_shelf_strip_1, light.workshop_desk_shelf_strip_2","data":"{\"brightness_pct\":70,\"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":3630,"y":1990,"wires":[[]]},{"id":"13fa0050.3d3fd","type":"api-current-state","z":"5d722b12.a14d84","name":"Motion Activated?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.motion_detection_workshop_desk","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2960,"y":1990,"wires":[["899d13d2.087aa","474b502e.6bfc9"],[]]},{"id":"b95be071.d13ec","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn off","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.garage_light_1_d1, light.workshop_desk_shelf_strip_1, light.workshop_desk_shelf_strip_2","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":3630,"y":2050,"wires":[[]]},{"id":"d80fc8e5.84eb78","type":"api-current-state","z":"5d722b12.a14d84","name":"Light is off?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"false","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"light.garage_light_1_d1","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":3440,"y":1990,"wires":[["9264eda4.6acbf"],[]]},{"id":"899d13d2.087aa","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"8","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":3180,"y":2050,"wires":[["b95be071.d13ec"]]},{"id":"474b502e.6bfc9","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"sunsetStart","endTime":"sunriseEnd","startOffset":"","endOffset":"","x":3220,"y":1990,"wires":[["d80fc8e5.84eb78"],[]]},{"id":"46d14710.c7f5d8","type":"comment","z":"5d722b12.a14d84","name":"Workshop Motion","info":"","x":2740,"y":1920,"wires":[]},{"id":"c75798f0.9eb148","type":"server","name":"Home Assistant Synology","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":true}] |
1 |
[{"id":"c7ec40a7.00f15","type":"server-state-changed","z":"5d722b12.a14d84","name":"Motion","server":"c75798f0.9eb148","version":1,"entityidfilter":"binary_sensor.lightwell_ground_motion","entityidfiltertype":"substring","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":120,"y":980,"wires":[["b351bc98.fda8a"],[]]},{"id":"519aa670.1f0808","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn on","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lightwell_ground","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1010,"y":980,"wires":[[]]},{"id":"b42cc019.5b88f","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"sunsetStart","endTime":"sunriseEnd","startOffset":"","endOffset":"","x":570,"y":980,"wires":[["519aa670.1f0808","5e676d4f.bb32e4"],[]]},{"id":"b351bc98.fda8a","type":"api-current-state","z":"5d722b12.a14d84","name":"Motion Activated?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.motion_detection_lightwell_stairs","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":980,"wires":[["b42cc019.5b88f"],[]]},{"id":"5e676d4f.bb32e4","type":"api-current-state","z":"5d722b12.a14d84","name":"Currently BBQing?","server":"c75798f0.9eb148","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.bbq_light_override","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":570,"y":1070,"wires":[["84b92bb2.11d668"],["791d7e4a.e03a4"]]},{"id":"c418fd57.28895","type":"api-call-service","z":"5d722b12.a14d84","name":"Turn off","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lightwell_ground","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1010,"y":1070,"wires":[[]]},{"id":"4fd068c0.b4a628","type":"server-state-changed","z":"5d722b12.a14d84","name":"Lightwell Door Open","server":"c75798f0.9eb148","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.lightwell_door","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":160,"y":1060,"wires":[["b351bc98.fda8a"],[]]},{"id":"84b92bb2.11d668","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"15","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":790,"y":1040,"wires":[["c418fd57.28895"]]},{"id":"791d7e4a.e03a4","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":true,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":790,"y":1090,"wires":[["c418fd57.28895"]]},{"id":"c75798f0.9eb148","type":"server","name":"Home Assistant Synology","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":true}] |
1 |
[{"id":"d5260ac8.1b60f8","type":"server-state-changed","z":"5d722b12.a14d84","name":"Hall Motion","server":"c75798f0.9eb148","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hall_bath_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":160,"y":670,"wires":[["55ae9df4.548f84","6fbef633.6c99e8","48952510.026adc","b9174bc8.d10718"],[]]},{"id":"b9174bc8.d10718","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"0:00","endTime":"sunrise","startOffset":"","endOffset":"-60","x":390,"y":760,"wires":[["2e23a6c7.1894da","5815e8a8.37c508"],[]]},{"id":"2e23a6c7.1894da","type":"api-call-service","z":"5d722b12.a14d84","name":"red","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hall_bath_lightbulb","data":"{\"brightness\":255,\"rgb_color\":[255,0,0],\"white_value\":0}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":640,"y":810,"wires":[[]]},{"id":"2d75a666.ebb32a","type":"api-call-service","z":"5d722b12.a14d84","name":"off","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hall_bath_lightbulb","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":710,"wires":[[]]},{"id":"445a84a0.1930ac","type":"api-call-service","z":"5d722b12.a14d84","name":"white","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hall_bath_lightbulb","data":"{\"brightness\":155,\"white_value\":255}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":640,"y":580,"wires":[[]]},{"id":"6fbef633.6c99e8","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"sunsetStart","endTime":"22:00","startOffset":"","endOffset":"","x":400,"y":640,"wires":[["445a84a0.1930ac","e804d722.33b1e8"],[]]},{"id":"48952510.026adc","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"22:00","endTime":"23:59","startOffset":"","endOffset":"","x":380,"y":700,"wires":[["3a77b6f1.2e7a0a","5815e8a8.37c508"],[]]},{"id":"3a77b6f1.2e7a0a","type":"api-call-service","z":"5d722b12.a14d84","name":"30% White","server":"c75798f0.9eb148","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hall_bath_lightbulb","data":"{\"white_value\":75,\"rgb_color\":[255,0,0]}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":660,"y":700,"wires":[[]]},{"id":"55ae9df4.548f84","type":"time-range-switch","z":"5d722b12.a14d84","name":"","lat":"37.80162","lon":"-122.43817","startTime":"sunrise","endTime":"sunriseEnd","startOffset":"-60","endOffset":"+60","x":410,"y":580,"wires":[["445a84a0.1930ac","e804d722.33b1e8"],[]]},{"id":"5815e8a8.37c508","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"120","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":760,"wires":[["2d75a666.ebb32a"]]},{"id":"e804d722.33b1e8","type":"trigger","z":"5d722b12.a14d84","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"240","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":640,"wires":[["2d75a666.ebb32a"]]},{"id":"c75798f0.9eb148","type":"server","name":"Home Assistant Synology","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":true}] |
Be First to Comment