Deprecated: Hook custom_css_loaded is deprecated since version jetpack-13.5! Use WordPress Custom CSS instead. Jetpack no longer supports Custom CSS. Read the documentation to learn how to apply custom styles to your site: in /var/www/html/wp-includes/functions.php on line 6078 Controlling lighting with motion via Node-Red – Part 1 – D Khaz Skip to content

Controlling lighting with motion via Node-Red – Part 1

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

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

Published inHome AssistantHome AutomationNode-RED