The Open Source Smart Home: Getting Started with Home Assistant & Node-Red

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 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 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 “”. 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 the addon repository here

Enter and hit save. Refresh the page and you should see Node-Red available for install.

Addon Reposityory List

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.

Choose the node-red-contrib-home-assistant package

Choose this one

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!

RELATED >>  Pi to NUC Part 1: Migrating Hass.IO to a Virtual Machine with Proxmox & Docker

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:

   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.

The simplest flow

The simplest flow, an input and an output.

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.

Editing a Node's options

Node 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.


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


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


  1. You might not remember me but I was the one asking you on Reddit for this blog’s URL. Great job, will definitely read on here 🙂

    One thing I want to throw in:
    Since I (and you too for sure) already use an MQTT broker, I was wondering if I could decouple HA and NR via that route. So I looked at the components list and there is indeed an EventStream and StateStream MQTT component. NR has a great MQTT node built in.

    Just played with it and it is awesome!

    Now I can setup separate Docker containers for Mosquitto, HA and NR and everybody is just talking to Mosquitto. That way I can have HA’s excellent integration with all my lamps and what not using it as a “state machine” and having NR doing the heavy logic lifting. Previously I went down the track of doing everything in NR but state is not its strength, one has to pollute the global namespace to keep things for later (perks of leveraging the functional approach).

    I don’t know if that would be something for you since you already integrated it but I think this way it is just one moving part (well, two in this case) less to break.


    1. Thanks for the reply! I am basically doing exactly as you described, using Home Assistant as the “state machine” with NR on top. That is a good way of putting it. I was also looking at the MQTT state/event stream, it seems ideal to me to just use MQTT for everything as well.

      I’m currently working on seeing if I can make a dumb IR fan into a Hass mqtt_fan using NR to read sensor values and output appropriate MQTT. So using NR’s better logic to maintain the state in Hass.

      I’m also looking at converting iBeacon signals to MQTT, to then format for the new mqtt_room component. (I have some ESP32’s but haven’t found any reliable BLE->MQTT code for it yet).

      So you are using MQTT as inputs and outputs directly? The one thing about the state stream is that it doesn’t appear the states are published with the retain tag, so it seems it it could only be used for inputs/outputs? Nice thing about the Home Assistant nodes I install here is that you can get a state or render a template (super useful) mid-flow. I guess you could also use the HTTP API to get a state mid-flow, but that’s basically what these nodes are doing I think.


      1. Well I did not think about that for sure^^

        However I tried just now on one of my test devices and it seems that HA pulishes every state on startup at least once. So any consecutive state change would be covered by NodeRed. The persistence tag seems to be set as well as I was able to get all the published states:
        starting Mosquitto -> starting HA -> killing HA -> mosquitto_sub -v -t “#”

        If I enable persistence in the Mosquitto server I could even preserve states beyond complete server reboot without restarting HA. That opens a whole lot of new possibilities as the streams are designed for HA to sync over instances and we could publish via NR to the same state attributes while HA is down (for some reason). Therefore if HA comes up again it could(?) update itself from the states previously published – and changed by NR in the meantime? So effectively Mosquitto is the “real” state machine with two or more clients reading and publishing from it.

        Btw. you were right, I just dug through the source of the plugin as well and in the config-server.js the node calls the REST API of HA, so I think using that is feasible as there seems no magic hidden behind some covers. Nevertheless I will continue to try to find a way to completely separate the “state machine” from the logic which gives me some “reward” as a hobby dev 😉


  2. Thanks. I got it working by changing my ip to No idea why that worked.

    I wasn’t using https, but am now switching over so that I can integrate Google Assistant with HA. So I’ll need to use https and an external domain (DuckDNS).

    Thanks for the link.


  3. Whenever I try to add the call service node, I get the error “Cannot GET /homeassistant/services”. I am using SSL, and have the addon configured according to the github link you posted in the comments. I am able to use the Home Assistant API from external devices successfully, but I simply cannot get Node-RED to work. Any suggestions?

    Note: I am using the fully qualified domain name ( in the config node.


    1. WAIT! I got it working!

      For anyone else running into the same problem as I did, using the FQDN as I wrote in my previous comment is correct, even though it gives an error. Ignore the error, deploy your flows, and THEN it should start to successfully communicate.


        1. Were you able to get this working? I am also getting the “Cannot GET /homeassistant/services” error Jeff was getting before (using SSL)


          1. I still haven’t had a chance to set this up myself, over on Reddit several people have narrowed it down to a couple of things to check for:

            1. Use the fully qualified domain name that your SSL certificate was made for (ie
            2. Forward port 1880 on your router
            3. Make sure router has NAT loopback enabled

            Using the FQDN obviously makes it dependent on your internet connection. You can edit your hosts file or similar to point your external domain to the local LAN IP.

            Hope that helps.

  4. Thanks for the write-up but I’m running into an issue with just the basic flow of turning on and off a light. Although it shows to have deployed successfully, I’m getting the following error: Cannot read property ‘getServices’ of undefined. Followed up by: at / shar/node-red/node_modules/node-red-contrib-home-assistant/config-server/config-server.js:44:38, etc…
    Any thoughts on what this could be?


    1. That looks like it is not able to authenticate with your Home Assistant server. Did you enter your server and login details? Double click any of the Home Assistant nodes and there is a “Server” setting with an edit button next to it. See if updating that helps.


      1. Awesome. I had two conflicting nodes once, just for future reference for anyone reading this – you can edit the packages (ie manually remove/add something) and their settings files directly. They’re in the /share/node-red/node_modules folder in Hassio, if you enable Samba file sharing.


  5. Hi,
    I am trying to follow the steps here however I couldn’t find node-red-contrib-home-assistant in the palette list. Any suggestions?



    1. I think the search in Node-Red is kind of weird. Try searching just “assistant” or something. You can also install them manually, in Hassio all the files are in /share/node-red


  6. Hi,

    I’m new to HA and would like to learn from your experience.

    Is state tracking something that node-red can’t handle well?
    I’m trying to understand how much different will adding HAss make.

    As it is, we already need

    1. A MQTT broker
    2. node-red

    Thank you.


    1. Correct, Node-Red does not do state tracking well. The main benefit of using Home Assistant is the number of devices/components supported (almost 1000) and the unified API for all those components for tracking states and calling actions. So you get all your state tracking and service calls in one place.

      MQTT is really optional, you just need NR and HA, unless you have a specific need for it. Home Assistant also has an internal MQTT broker if you’d rather not run an additional service. I have not had any issues with these 3 services running side by side though – very stable.


      1. Hi Brad,

        I have some custom sensors, so MQTT is used to avoid reinventing a bad wheel. On Centos 6, I had trouble installing HAss and node-red gave some errors when installing the node-red-contrib-home-assistant.

        I will probably try Centos 7 before going with a RPi. Do you have a quick way of replacing your RPi when it fails? What about backing up its latest configuration? I read it takes really long to get the software installed and going.

        Thank you for sharing!


        1. Yeah I use MQTT for the same – I have some Python scripts scraping things from the web and a bunch of esp8266 based sensors. Very easy to track states in Home Assistant for different types of data with their MQTT components.

          I’m not familiar with Centos, you may want to look into running HA+NR+MQTT in Docker containers, ie. I think that is the way I would go if I were running on a traditional Linux type system. Docker is available on pretty much every platform I believe.

          I do really like on the RPi. Like I detailed here, all the supporting programs (N-R, MQTT, etc.) are run in containers similar to Docker. Installing, configuring, and updating these additional programs just takes a few clicks in the web UI. It’s very easy to maintain, and it has a built-in backup system that backs up all your config files, additional programs, settings, etc. If the Pi or SD card fails, I just burn a new image of on a new card, copy the backup (it’s just a tarball TGZ file), and hit restore. That brings back not just the HA configuration files but Node-Red, my Let’s Encrypt settings, etc.


  7. Hi Brad, I am new to HA and Node-Red what I am trying to do is make a flow that will shut off my HVAC if any doors/windows are open for 5 minutes. Then I want it to turn back on once all of the doors/windows are closed. Is this possible and if so where do I begin? I’m sure once I see a flow on my screen that works I’ll get the hang on it but right now I’m lost. Help me please


    1. Hey Matt, I think I replied to you over the on the HA forums, but for anyone else reading here’s how I would do it:

      For each window/door, use a current state node, a switch, and a stoptimer. If open, start the stoptimer. If closed, cancel the stoptimer. All of those go to a call service node to turn the HVAC off. Now if any one timer successfully completes, it will shut off the HVAC.

      To turn back on, I would put all the windows/doors in a group in Home Assistant. Then monitor the state of that group in Node-Red, when all the doors are closed, turn the HVAC back on.

      Hope that helps, if you figure it out post your JSON 🙂


  8. Hi,
    I am new to both Home Assistant and Node-Red but from following your guide I have managed to install both, so firstly a massive thanks for taking the time to write this.
    I got up to trying out the node’s but have come a little unstuck.
    When asked to enter Home Assistant server details into the service node what do I put, where do I get my details from and how do I find the api key please.

    Everything else has gone well and is all installed but when I try to use the first two nodes it keeps telling me unable to connect in the debug window.

    Any help would be awesome.


    1. Hey Dave, if you edit any of the Home Assistant nodes, there is a setting for the Home Assistant server. Click the edit button and add the details for your server. You don’t need an API key, just the URL (ie and your Home Assistant password.


Leave a Reply

Your email address will not be published. Required fields are marked *