Most common automation rules in Node-RED

At this point, you should have Node-RED installed and running. Now we will look at the most frequent automations that will give you some knowledge how to create the Node-RED magic your self. Still not sure? Hit us in the comments and we will try to help.

If you did not come from the earlier parts of our tutorial, check out the first introduction to Node-Red. If this is all new to you, Home Assistant is one of the most flexible and sophisticated open-source smart home platforms, and Node-RED is a visual programming tool making rule creation a walk in the park (ish). It can work on our pick how you should spend first $250 on smart home, allowing you to create rules and experiment with all seven devices included.

We will cover the following automations:

  1. Movement triggers lights
  2. Movement triggers light only at night and changes color of lights depending on time
  3. Switch on the lights at sunset
  4. Loop and notifications
  5. Doorbell notifications (Xiaomi single click event)

1. MOVEMENT TRIGGERS LIGHTS

  • The flow below will be triggered by the change in the status of binary motion sensor
  • If motion detected and lights are off we will switch the light on
  • Note the good use of “Halt if” in “light on?” node – this is basically equivalent to YAML “condition” but made in a very agile way
  • If no motion, we will put a delay of 3 minutes and if still no motion the lights will be switched off
  • You will need to install a pallet called stoptimer the same way you installed home assistant pallet
  • Copy the flow from Pastebin
This flow will trigger light on motion with some basic checks

2. MOVEMENT TRIGGERS LIGHTS ONLY AT DARK AND CHANGE COLORS

  • The flow below will be doing things similar to the one above, but will also check if it is dark to switch on and will be ambient or normal light depending on the time (you do not want too bright light in the night)
  • We will check if it is dark using Z-wave Aeon Multi-Sensor and its luminance value (below 12 is what I use)
  • I also want in the night not to be blinded, so another time-based switch is installed. Depending on the outcome, different brightness and color will be used (I am sure you can do it in a more elegant way)
  • You will need to install a pallet called time-range-switch the same way you installed home assistant pallet
  • You can copy the flow from Pastebin
This flow will trigger light at sunset

3. SWITCH ON LIGHTS AT SUNSET

  • This one is very simple – let’s say you have the lights that you want to switch on and off only at sunset. I personally think that light sensor will do a better job, but for argument sake, let’s say you do not have it
  • For this, we will use a timer as a trigger and you will need to install a pallet called bigtimer the same way you installed home assistant pallet
  • You can copy the flow from Pastebin
This flow will trigger light at sunset

4. LOOP AND NOTIFICATIONS

  • This example will showcase two important things – looping and notification
  • Looping is helpful when you need to run the same actions for the certain periods of time. You will need to install looptimer pallet for this one
  • For notifications I already have setup telegram-bot, using the guide here and will be just using it opposed to separate pallet that. See other option to do the same below
  • You can copy the flow from the PasteBin

5. DOORBELL NOTIFICATIONS

  • This flow will use a couple of new nodes. The first one is “all events” node which basically sends to Node-RED all events from Home Assistant and JSON node translates the events into a string. Switch node the filters any irrelevant messages
  • This is not the most elegant way to do it, so happy if you help with any other ones.
  • For my doorbell, I use Xiaomi Smart Button, which triggers Xiaomi Gateway to play a ringtone
  • Do not forget to create a telegram bot and change “chat_id” in the function node for your needs
  • You can copy the flow from the PasteBin

TO CONTINUE with Node-RED, see other tutorials:
Node-RED installation

Getting started

Most common automations

Advanced automation and further help

More practical advice on smart home devices:

Smart Locks

Smart Security

0 0 votes
Article Rating
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Xavi
Xavi
4 years ago

Very interesting. Thanks!

1
0
Would love your thoughts, please comment.x
()
x
Scroll to Top