May 09, 2025

Home Assistant and Node-RED

Node-Red(NR) is Flow-based programming for the Internet of Things.

I have in the past written a lot of posts for Node-RED and the HA implementation makes it easy to interact with HA:s entities.

The best thing is that even if you don't are a skilled programmer, but like logic flows, you can make really advanced things and it really complements the logic that could be made within Home Assistant(HA).

In this post I will do a quick introduction to what is possible with NR together with HA.

Install

Node-RED
Install NR from the "Add-on store" and search for "Node-RED". After the installation activate 
  • Start on boot
  • Watchdog
  • Show in sidebar
then go to the ”Configuration” tab, inhibit SSL and then ”Start”. 

Node-RED Companion
If you in NR, for example, want to create a temperature entity from some random sensor you also have to install a custom integration, using HACS, the "Node-RED Companion". Follow the instructions and then reload HA.

Raspberry Pi GPIO
Please note that you can't use the standard node for using the GPIO pins on a RPi !! 
This is because it was removed in Home Assistant Core version 2022.6, but as always there is a work around. Via HACS install rpi_gpio.

After the installation edit "/homeassistant/configuration.yaml" and add

switch:
  - platform: rpi_gpio
    switches:
      - port: 17
        name: "Speaker Relay"

restart HA and then you could use it as an output both from HA and NR.

Dashboard

If you are activating the NR dashboard it will be found at 


homeassistant.local:1880/endpoint/ui/


Files in NR

Flows

Node-Red flows are stored in /addon_configs/a0d7b954_nodered/flows.json using ssh/terminal or the file editor. Path to the same folder, seen from NR, is /config/flows.json.


If NR hangs and it could be due to a bad flow just clear the flows file with the editor. 


Creating files

A place for storing own NR files could be /config/files/, seen from NR

So create the directory /addon_configs/a0d7b954_nodered/files/, seen from ssh/file editor


Use the "Write file" node to add records to a file. This node can even create the mentioned "file" folder mentioned.

Examples
As an example, check picture, I'm retrieving temperature, with a poll node, from a SONOFF temperature  sensor. The resolution is just 0,2 degrees Celsius so taking the average of the last 10 measures I will get more decimals and a smoother output. Then the temperature is sent back to HA with a sensor node

The second flow is getting the temperatures, with a get history node, for the last 60 minutes from the HA database.

Problem ?
In the settings file for NR add on add

safe_mode: true

Restart and check the NR log to see if there are any "hints".


No comments:

Post a Comment

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !