Deprecated: Function jetpack_form_register_pattern is deprecated since version jetpack-13.4! Use Automattic\Jetpack\Forms\ContactForm\Util::register_pattern instead. in /var/www/html/wp-includes/functions.php on line 6078
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6078) in /var/www/html/wp-includes/feed-rss2.php on line 8
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.
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
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.
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.
[{"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}]
[{"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}]
[{"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}]
[{"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}]
While my subwoofer’s power switch has an auto setting that is only supposed to turn on the amp when it’s getting signal from the receiver, this never really worked. And as we rearranged the room, it’s new location did not allow it to be wired into the receiver’s builtin switched receptacle. Thus, I needed a way to remotely control the sub being on or off.
The Sonoff Basic is perfect for this job as you are switching 120v for the subwoofer’s power. It does not matter which version of the Sonoff Basic you use (Original, R2, or R3) as they will perform the same here. I have a half dozen R2s that came as part of a bulk order, so that’s what I used. Splicing the Sonoff into the subwoofer’s power cable was very straight forward. All you have to do is cut the cable and insert the Sonoff in the middle, with the plug side of the cable wired to the input side of the Sonoff and the subwoofer side to the output side.
I chose to take a step further by disassembling my subwoofer and installing the Sonoff inside of the subwoofer. This means it’s spliced on the power cable after the cable enters the subwoofer. I used a couple of strong zip ties to mount the Sonoff, in its enclosure, to one of the sub’s metal components.
The overall process is to flash this unit with custom firmware that tightly integrated to Home Assistant. To get the unit converted from the original firmware, I used a USB FTDI converter combined with ESPHome to get this accomplished. If you are not familiar with this process, JuanMTech and many others have great detailed steps for this part. Head over to your ESPHome dashboard and create a new device. Paste the YAML below into the device configuration:
substitutions: platform: ESP8266 board: esp01_1m device_name: esphome_subwoofer friendly_name: "Subwoofer" reboot_timeout_wifi: 900s reboot_timeout_api: 1800s output_power: 17dB # <<: !include z_common.yaml esphome: platform: ${platform} board: ${board} name: ${device_name} esp8266_restore_from_flash: true wifi: ssid: !secret wifi_iot_ssid password: !secret wifi_iot_pwd fast_connect: on reboot_timeout: ${reboot_timeout_wifi} output_power: ${output_power} ap: ssid: "AP_${friendly_name}" password: !secret wifi_backup_pwd api: reboot_timeout: ${reboot_timeout_api} ota: web_server: port: 80 logger: captive_portal: binary_sensor: - platform: gpio pin: number: GPIO0 mode: INPUT_PULLUP inverted: True id: sonoff_button internal: true on_press: - switch.toggle: sonoff_relay switch: - platform: restart name: '${friendly_name} REBOOT' - platform: gpio name: "${friendly_name} Power" icon: "mdi:speaker" id: sonoff_relay pin: number: GPIO12 restore_mode: ALWAYS_ON status_led: pin: number: GPIO13 inverted: True text_sensor: - platform: version name: ${friendly_name} ESPhome Version
Now, go to the Home Assistant Integrations page (Configuration>Integrations). You should see the ESPHome device show up in the discovered section after a minute or two. Click configure, and submit, and that’s it. Alternatively, you can manually add the device by clicking “CONFIGURE” on the ESPHome integration and entering “<NODE_NAME>.local” as the host.
Once the device is added, it will be in the lower part of this page (under Configured). Clicking through to the device will show you the entity names that are auto-magically created by the ESPHome integration.
Now, you cannot be expected to have to switch on the subwoofer through Home Assistant like a barbarian! So my fix for this is to automate it with the state of my receiver’s power. This is a very easy automation to create in Node-RED, my automation engine for Home Assistant.
This automation is looking for any messages about the on/off state of my receiver (media_player.rx_v675) and then outputs that state through an on/off switch (splitter). If the receiver state becomes on, the flow calls to turn on the subwoofer switch to on. You can copy and paste the JSON flow below to import it into your Node-RED instance.
[{"id":"cf3c6f80.3beae","type":"server-state-changed","z":"57657673.d86dd8","name":"Receiver state","server":"c75798f0.9eb148","version":1,"entityidfilter":"media_player.rx_v675","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":120,"y":890,"wires":[["67b8934a.8ffaec"]]},{"id":"67b8934a.8ffaec","type":"switch","z":"57657673.d86dd8","name":"on / off","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":890,"wires":[["2e23fe27.8fa362"],["6b0f2645.bdd0a8"]]},{"id":"2e23fe27.8fa362","type":"api-call-service","z":"57657673.d86dd8","name":"Turn on sub","server":"c75798f0.9eb148","version":1,"service_domain":"homeassistant","service":"turn_on","entityId":"switch.subwoofer_power","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":860,"wires":[[]]},{"id":"6b0f2645.bdd0a8","type":"api-call-service","z":"57657673.d86dd8","name":"Turn off sub","server":"c75798f0.9eb148","version":"1","service_domain":"homeassistant","service":"turn_off","entityId":"switch.subwoofer_power","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":920,"wires":[[]]},{"id":"c75798f0.9eb148","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
I had some initial concerns that the Sonoff would be subjected to stress/interference that could make it work incorrectly or breakdown faster. However, after making this modification last May, I’ve had zero issues with this setup. It just works. If you’ve got any questions, feel free to ping me below.
]]>