Node-RED vs Home Assistant Automations

It's time to move from Node-RED to native Home Assistant automations. I show you step-by-step how to move one of my more complex automations.

Node-RED vs Home Assistant Automations

I have been using Node-RED as part of my smart home almost since I started doing automations many years ago. My smart home is exclusively driven by Home Assistant along with the many integrations available on that platform. A recent event during an update to the Node-RED addon in Home Assistant caused me to take a second look at moving away from Node-RED to using native Home Assistant automations.

Let me stop and say that the "incident" I refer to, a bug in the UI, did NOT render my automations dead. It just amounted to more of an inconvenience, but what it did do was push me to do something I've wanted to try for a while.

📽️
Make sure to watch the video that goes with this post.

The Beginning

When I first started using Home Assistant, much of what was accomplished in that platform required lots of YAML code. Automations were no exception. Doing complex things on a brand new, to me, platform and learning YAML at the same time was quite the challenge. For that reason, I soon found Node-RED to be the answer to getting complex automations running quickly. I am a visual person and being able to see the flows in Node-RED was the best thing ever. At the time, there was nothing better than a complex automation on the screen with all the connectors and nodes. It was a work of art.

An example of a Node-RED flow that I used for handling door events.

To this day, I still think of flows as a work of art. Aside from the misaligned OCD-inducing nodes in the image above, I can quickly see the whole automation and what connects to what. As it runs, I can even see outputs under the nodes.

Node-RED is not without its complexity. For example, many "function" nodes have JSON or other snippets of code to make them work. That requires research to figure out exactly what goes in those nodes as well as the correct syntax. There were many hours of debugging that kind of stuff.

A function node in Node-RED showing payload required to send a Pushover notification message.

As I started investigating moving off of Node-RED, I was concerned that there were things I wasn't going to be able to do in native Home Assistant automations. Spoiler: This turned out to be untrue in my case.

I mention this because there will no doubt those of you who feel that Node-RED is the end all be all of automation. That's OK! For the longest time, Node-RED was my go-to platform, even when there might be easier alternatives. After all, I had spent hours setting things up just the way I wanted. There WILL be things that Node-RED just does better than Home Assistant's native automations. There is no reason to force the issue and cause unnecessary stress or even worse, reliability issues or unneeded complexity.

🔧
Use the tool that best fits your environment.

The Move

As I mentioned, there was an incident that caused me to think about moving away from Node-RED. After a recent add-on upgrade in Home Assistant, I, and many others, were unable to use the inject and debug nodes if loading the Node-RED UI directly in Home Assistant.

I use timed triggers via the inject nodes for many of the automations. Because of the UI issue and some other observed behavior, I thought the inject nodes were completely dead and wouldn't fire when needed. This would have been serious for the household acceptance factor, among other things. I've worked very hard to get my family to accept my smart home shenanigans and I don't want to destroy that trust in the technology. Therefore it was imperative that I fix this.

The inject node showing the mouse move icon when hovering rather than the arrow that would allow clicking the node. The inject node can't be fired this way.

Because I keep backups and was able to restore, it wasn't a big deal but it did re-ignite that curiosity of "Do I need Node-RED anymore?". Can I remove one layer of complexity and run one less add-on and still accomplish the same thing? It turns out the answer is yes.

For the sake of keeping this article and the associated video to a manageable length, I won't show how I moved all my Node-RED automations into Home Assistant. As you can see, I have quite a few.

A listing of the automations I moved from Node-RED to Home Assistant Automation

An Example Node-RED Flow

Let me start by explaining at a high level an already existing flow in Node-RED with some notifications and timers with parallel paths. The complexity of this flow arises in the timers and parallel paths.

First, we start be watching for events from the garage door opener. We will see either an open or close.

Watch the garage door opener from either an open or close.

I send a notification to Pushover for either of those two events. Notice the function nodes that contain JSON code for the notification parameters.

Nodes that send notifications to Pushover

I send an announcement to my Alexa smart speakers between the hours of 0800 and 2100. I don't want to wake the whole house if it's early or late.

Time range nodes limiting announcements to a specific time.

Some of the lights get turned on no matter what time, and others get turned on from sunset to midnight when it is darker outside.

Specific lights are turned on regardless of time and others get turned on when it is dark outside.

Finally, the ultrasonic sensor gets turned on in the garage for two minutes and the garage hall light for ten minutes. Both go off after each of those times. This is where the parallel execution is needed in the Home Assistant automation.

Block of nodes that turn on the ultrasonic sensor and garage hall light, each having its own runtime before turning off again.

Building this Automation in Home Assistant


Let's take the above automation and build it in Home Assistant's native automation engine. We'll do this via the UI, which is something unheard of when I started using Home Assistant years ago and why I used Node-Red instead.

✔️
Make sure to watch my video so you can see step-by-step how I build the automation.
🖥️
See the end of this article for the full YAML of this automation.

First, we need to add two triggers, one for the garage door open and one for closed. Give each one a unique Trigger ID.

Garage door open trigger with an ID of garage_open.
Garage door closed trigger with an ID of garage_closed.

Many times, there is more than one way to do something in an automation. When I initially built this automation, I ended up adding a condition that would turn on a script. I could have easily just added actions directly, without using the script.

This part of the automation is what turns on specific lights between sunset and 11:59 pm. It does this by using an if-then building block to determine if the time is in my required window and then calling the script (I can't remember WHY I used a script here instead of just adding the actions directly).

Conditional section of the automation that fires between sunset and 11:59pm.
The script called by the above automation block.

Next, I determine whether the garage door is open or closed using a "Choose" building block.

Different building blocks that can be used in an automation. Highlighting the Choose option.
Choose block showing the garage_open and garage_closed options.

When the door is opened, the following is performed:

  • Disarm the alarm system.
  • Send a pushover notification to my phone.
  • Send a voice announcement via Alexa smart speakers ONLY between 8 am and 9 pm.
  • Set the light color on the back wall switch to red to indicate the door is open.
  • Turn on the garage hall, kitchen pendant, and Atom Matrix switches.
  • During the holidays, turn on the Christmas tree lights (disabled in this screenshot).
  • Start two timers in parallel. One timer to turn off the Atom Matrix after 2 min and the other to turn off the garage hall after 10 min.
Option 1 showing the actions performed when the garage door is opened.

To only send announcements during a specific time, I use an if-then building block and choose a fixed start and end time as well as the days of the week I want this to run.

If-then block showing a condition that only executes between 8 am and 9 pm.

I also want to point out here that in Node-RED I had to add JSON code to the node to get the announcement. This is done via the UI in Home Assistant making it much easier to implement.

UI to create the announcement via Alexa media player. No JSON required here.

For the parallel timer block, I create two actions that both execute a sequence action. This is necessary because otherwise, all actions you put into a parallel building block will execute at the same time. I want the timers to start and THEN turn off the switches at the expiration of the timer.

Sequence building block action
Run two sequence actions inside a parallel action.

As I mentioned above, this was probably the most complex part of this automation and even then it is easy once understanding how to use parallel and sequence building blocks together.

When the garage is closed, only a few easy actions are performed.

  • Send a pushover notification to my phone.
  • Send a voice announcement via Alexa smart speakers ONLY between 8 am and 9 pm.
  • Set the light color on the back wall switch to green.

Using traces in Home Assistant allows for debugging in a step-by-step method. The path can be visualized and clicking on any of the steps shows what happened.

The path that an automation follows in Home Assistant via the traces view.

Conclusion


As you can see, it is quite easy to take a somewhat complex automation and move it from Node-RED to Home Assistant and configure it via the UI. This is light years ahead of where Home Assistant automations started years ago. The improvements in the UI and the addition of things like building blocks makes it possible.

It probably took me a total of 2-3 hours to move ALL my automations from Node-RED to Home Assistant. I even had the opportunity to clean up some of the automations and remove unnecessary stuff. One other bonus is that I can view and make changes to my automations via my phone or mobile devices now. With Node-RED it was practically impossible to do that since the interface wasn't designed for small mobile screens.


YAML Code

description: ""
triggers:
  - trigger: state
    entity_id:
      - cover.konnected_garage_door
    to: open
    id: garage_open
  - trigger: state
    entity_id:
      - cover.konnected_garage_door
    to: closed
    id: garage_closed
conditions: []
actions:
  - if:
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            before: "23:59:00"
            weekday:
              - sun
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
    then:
      - action: script.turn_on_lights_door_unlock_or_garage_open
        metadata: {}
        data: {}
  - choose:
      - conditions:
          - condition: trigger
            id:
              - garage_open
        sequence:
          - action: alarm_control_panel.alarm_disarm
            metadata: {}
            data:
              code: "{enter your own code}"
            target:
              entity_id: alarm_control_panel.alarmo
          - action: notify.pushover
            metadata: {}
            data:
              message: Garage Open
              data:
                priority: 0
                sound: bugle
          - if:
              - condition: and
                conditions:
                  - condition: time
                    after: "08:00:00"
                    before: "21:00:00"
                    weekday:
                      - sun
                      - mon
                      - tue
                      - wed
                      - thu
                      - fri
                      - sat
            then:
              - action: notify.alexa_media_everywhere
                metadata: {}
                data:
                  data:
                    type: announce
                  message: Garage Door Open
            enabled: true
          - action: zwave_js.set_config_parameter
            data:
              entity_id:
                - switch.back_porch_new
              parameter: LED Indicator Color (Button 1)
              value: "3"
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.garage_hall
                - switch.kitchen_pendant
                - switch.garage_atom_matrix
          - action: homeassistant.turn_on
            target:
              entity_id: group.trees
            data: {}
            enabled: false
          - parallel:
              - sequence:
                  - delay:
                      hours: 0
                      minutes: 10
                      seconds: 0
                      milliseconds: 0
                  - action: switch.turn_off
                    metadata: {}
                    data: {}
                    target:
                      entity_id: switch.garage_hall
              - sequence:
                  - delay:
                      hours: 0
                      minutes: 2
                      seconds: 0
                      milliseconds: 0
                  - action: switch.turn_off
                    metadata: {}
                    data: {}
                    target:
                      entity_id: switch.garage_atom_matrix
      - conditions:
          - condition: trigger
            id:
              - garage_closed
        sequence:
          - action: notify.pushover
            metadata: {}
            data:
              message: Garage Closed
              data:
                priority: 0
                sound: magic
          - if:
              - condition: and
                conditions:
                  - condition: time
                    after: "08:00:00"
                    before: "21:00:00"
                    weekday:
                      - sun
                      - mon
                      - tue
                      - wed
                      - thu
                      - fri
                      - sat
            then:
              - action: notify.alexa_media_everywhere
                metadata: {}
                data:
                  data:
                    type: announce
                  message: Garage Door Closed
          - action: zwave_js.set_config_parameter
            data:
              entity_id:
                - switch.back_porch_new
              parameter: LED Indicator Color (Button 1)
              value: "2"
mode: parallel
max: 3