Basics: Connecting Home-Assistant to Node-red

Connecting Home-Assistant to Node-red

Quick and easy one today. There are several different ways of installing and running both Home-Assistant and Node-red. I have one instance of Home-Assistant Supervised (formerly Hassio) on an Intel Nuc. As it’s supervised, it has all the add-ons baked into it, and launching Node-red was as simple as clicking on the add-on and waiting for it to start. This is simple to set up and is serving me well. That said, it can be a little annoying at times. If I need to restart Home-Assistant for whatever reason (maybe an update of Core or the OS, or HACS) then it means Node-red is also down for the count. Effectively, my smarthome and automations are out of action whilst it’s doing its thing. I also have a remote server running Home-Assistant and Node-red but they’re in separate docker containers.  The beauty of this, is that when Home-Assistant needs to be restarted Node-red can happily sit there working away in the background. All of my smart plugs and switches are running Tasmota and are controllable via MQTT, so even if Home-Assistant is restarting, we can still use the voice assistants to control the automations. I have both Alexa and Google Home set up directly in Node-red via a third party bridge, so even without Home-Assistant, everything still works (more on that here)

Today I am going to show you how to connect your Home-Assistant instance (regardless of Core or Supervised) to an external Node-red instance. As there are different ways of installing both Home-Assistant and Node-red, I’m going to assume you’ve got both installed and are able to access their respective web interfaces even if they’re on different machines, or in different locations.

In Home-Assistant go to the user icon in the bottom left of the screen.

Getting a Token
Getting a Token

Next scroll to the very bottom of the page until you get to Long-Lived Access Tokens. Create a token. Make a note of this, because when you first create it, it will be the only time you’re ever shown the string. So copy it, as we’ll need this later. If you mess it up, it’s simple enough to just delete and repeat.

Long Life Token
Long Life Token

Next go to your Node-red instance and click on the hamburger icon to bring up the drop down menu. You’ll need the Manage Palette option.

Manage Palette
Manage Palette

Click on the Install tab, and type in home-assistant. You’ll see it brings up a variety of different nodes. You’ll want the one titled “node-red-contrib-home-assistant-websocket” You can see it’s been updated fairly recently. If you wish to learn more about this node, you can browse here.

Home-Assistant Node-red palette
Home-Assistant Node-red palette

Install it and wait for a few moments for the new palette to appear. Incidentally, if you click on the left tab (Nodes) you’ll see what you already have installed. I regularly check here because often there will be updates which you need to manually install.

New Home-Assistant Palette
New Home-Assistant Palette

You should now see a new palette on the left hand side. Next we need to configure the palette so it actually links to your Home-Assistant installation. Drag out any node from this list and double click it to configure.

Configuring the State Change Node
Configuring the State Change Node

Here we need to go into the “server” field and add-server, or click on the pencil icon to bring up the next window.

Configuring Home-Assistant Server in Nodered
Configuring Home-Assistant Server in Nodered

Here we add the information required. Base URL requires http:// and the port number, don’t just add the IP address. Paste the long life token we created in Home-Assistant into the “Access Token” field. Leave everything else the same as above. Hit update, close the window and deploy. If everything is connected correctly, you should see a green icon under the state change node. If you go into the state change node and click on the entity field, you should now see a list of all your entities in Home-Assistant. Now go and create flows until your heart’s content!

Using the above method is good for connecting more than one Home-Assistant installation together. You can have several Home-Assistant servers connected to one Node-red instance, although be mindful to choose the correct server when deploying flows. I have a remote Home-Assistant server at another location (B). I can add this and interact with the entities there easily from location (A).

Remote Location Configuration
Remote Location Configuration
Remember to Choose the Correct HA Server
Remember to Choose the Correct HA Server

This is all free of charge, requiring nothing more than a single port forward or Nginx Proxy setup at the remote location (beyond the scope of this tutorial).

If your interested in sharing your own solutions, tips and tricks with like minded people perhaps you’d consider joining our facebook group. The aim of this group will hopefully be more show and tell rather than support, but that’s not to say we can’t lend a helping hand!

https://www.facebook.com/groups/386238285944105

 

The Smarthome Book
The Smarthome Book

Comments

  1. Is there a way to install this with support? HA Supervisor detected a unsupported feature after install node red in a conatiner

Leave a Reply