Home Assistant is one of the most interesting open source projects I’ve ever come across. It interfaces with any device, platform, or service you can think of. It can connect all of your devices to make a truly smart home. With a little creativity almost anything is possible with Home Assistant, and best of all it’s private and totally under your control.

After using Hass to control my smart home for the last year, I started to hit the limitations of its YAML-based configuration. Any automation that was even moderately complicated required a lot of pieces spread out through the configuration files (see the sprawling “Creating an Alarm Clock” thread on the HA forums for an example). Doing simple things like if-then or a loop required awkward workarounds. As my automations (and ambitions) increased in complexity, so did the time I spent trying to figure out what was going on.

That’s when I discovered Node-Red, a visual programming tool developed by IBM. Node-Red is the perfect complement to Home Assistant, allowing for very complicated logic to be constructed visually through a simple “flow” interface. It integrates seamlessly with Home Assistant. Let’s set it up.





STEP ONE: Installing Home Assistant

The easiest way to get up and running with Home Assistant is to install Hass.io on a Raspberry Pi. All you need to do is download the image, flash it to an SD card, and plug it in to your network-connected Pi. Soon you will be looking at the Home Assistant web interface. For more detailed instructions, refer to the Home Assistant documentation or watch this great video from BRUH Automation:

STEP TWO: Installing Node-Red

Hass.io provides a kind of “app store” for additional software. The addons are pre-configured for use with Home Assistant. To add Node-Red, click the hamburger menu in the Home Assistant Web UI and select “Hass.io”. From there select the Addon Store icon in the top right. You’ll see a list of default addons, but we need to add another repository to get Node-Red.

Enter https://github.com/notoriousbdg/hassio-addons and hit save. Refresh the page and you should see Node-Red available for install.

Install Node-Red, Start the service, and then hit the “Open Web UI” to access it. That’s it. The default login is admin/password, which is configurable in the Options section for the Node-Red addon.





STEP THREE: Integrating Home Assistant & Node-Red

Node-Red uses “nodes” to send messages from an input, through a series of flows that you diagram, and then it ends in an “output”.

In our case, the inputs will come from Home Assistant (a state change, an event), the message will be routed according to our needs, and then Node-Red will output back to Home Assistant by making a service call.

So how do we get these two things talking to each other?

In Node-Red, select the hamburger menu in the top right and click “Manage Palette”. This shows us a list of installed nodes, and a way to search for new ones contributed by the Node-Red community.

As you can see, there are several user contributed Home Assistant nodes. I tried all of them, and the one you want is node-red-contrib-home-assistant – not the “-ws” websocket one or the POST one!

We will now have a useful set of nodes for interfacing with Home Assistant available in the sidebar.

Optionally, we can also add Node-Red to the Home Assistant menu for easy access. To do this, add the following lines to your configuration.yaml file:

panel_iframe: nodered: title: 'Node-Red' icon: 'mdi:shuffle-variant' url: 'http://YOURIPADDRESS:1880/'





STEP FOUR: Putting it All Together

Now that everything is installed, let’s make a simple flow and make sure it works. I am going to use an inject node as an input, and a Home Assistant service node as the output to toggle a light.

Drag the two nodes into your palette and connect them with a wire.

Clicking once on either node will show it’s documentation in the “info” panel to the right. Note the red triangle on the Home Assistant node – this means the node needs to be configured. Double clicking it brings up it’s options.

Enter your Home Assistant server details if you haven’t already. Then fill in the appropriate data for the service call. In this case we use the “toggle” service from the “light” domain on the “light.bedroom” entity. The Data field is filled out in JSON format, exactly the same as the Service Call page in the Home Assistant developer tools.

All filled in correctly, we must hit the DEPLOY button to activate the flow. Now when you press the button on the inject node, Home Assistant will toggle the light on and off.

Ready to make some simple flows? Check out my post on Basic Lighting Flows.

SETTING UP ENCRYPTION

To set up Let’s Encrypt SSL certificates for both Home Assistant and Node-Red, see this post.

FURTHER RESOURCES

This guide is just to get you set up quickly and does not even begin to scratch the surface of what is possible running Home Assistant and Node-Red together. Next, you may want to set up some basic flows to automate lighting or look at some of the other useful nodes available to get your own ideas.

For a general overview of Node-Red and it’s interface, see this video



