Node-RED in Docker and Home Assistant integration

 

Especially complex automations may become a bit confusing in Home Assistant and its automations. If you reach the limits of the integrated automations, you can alternatively use your own automation platform such as Node-Red. In Node-Red, processes can be put together using various logic modules in a visual GUI via drag and drop.

After running Home-Assistant in Docker, Node-Red cannot be added through the add-on store, but through its own Docker container. The Node-Red container can be started in the terminal with the following command:

docker run -it -p 1880:1880 -v /home/pi/.node-red:/data --name mynodered nodered/node-red

Building on the article: Home Assistant setup in Docker, the setup described can be extended to include Node-Red by adding another text block to the file: docker-compose.yml:

version: "3"
services:
  haas:
      ....
  nodered:
      container_name: nodered
      restart: always
      image: nodered/node-red
      ports:
        - 1880:1880
      volumes:
        - ./nodered:/data
       ...

After starting the container, its web interface can be accessed via the port used:

See: https://nodered.org/docs/getting-started/docker

Username / Password

After the first start, the subfolder ./nodered used in docker-compose.yml will be filled automatically. For setting a new admin password, a password hash can be generated using the following command. Entered in the settings.js file, the password will be changed:

user@rechner:/$ docker exec -it nodered node-red-admin hash-pw
Password:
$2b$08$C.6kGG29J41ZAE2Mq3mp1eU3p/o3/1rLWNISIw7kN1fe6V65Ncq4u

File settings.js:

    adminAuth: {
        type: "credentials",
        users: [{
              username: "admin",
              password: "$2b$08$C.6kGG29J41ZAE2Mq3mp1eU3p/o3/1rLWNISIw7kN1fe6V65Ncq4u",
              permissions: "*"
          }]
      },

The web interface can then be invoked using the IP address of the Docker host and port 1880:

Now Node-RED is missing a connection to Home-Assistant, this can be set up as follows:

Connect Home Assistant to Node-Red

First I added the Node-RED Companion repository via HACS and activated the integration.

Access from Node-Red to Home Assistant is done via an Access Token, this can be created in Home Assistant via the User menu.

Back in Node-Red, we still need a "palette" for access: node-red-contrib-home-assistant-websocket

first Flow

The connection to Home Assistant takes place in a flow via "call service" to corresponding entities in Home-Assistant:

If the HACS integration is missing in Home-Assitant, a corresponding note will appear when activating it:

Conclusion

The connection to Home Assistant is done. My smart home automation requirements so far have been relatively easy to implement with Home Assistant Automations. Should I have more complex requirements in the future, I am prepared for this with Node-RED.😉

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Questions / Comments


By continuing to browse the site, you agree to our use of cookies. More Details