Home Assistant + Node Red = Love
Home Assistant + Node Red = Love

There was a time in my life where I had a lot of down time and needed a new hobby – and no, this wasn’t because of COVID-19. Because I like to tinker with the Raspberry Pi someone suggested to me a Pi distribution that promised to give me home automation. That, however, didn’t work and it didn’t do anything to actually automate my home.

What I did stumble upon in all of this was the tool Home Assistant, which I quickly installed on a Raspberry Pi (twice). The initial install didn’t go very far, it was confusing to me and I had to restart my setup. Of course, I didn’t read any manuals – which is the beauty of Home Assistant, you only have to read the manuals you want to.

The second install of Home Assistant on the Raspberry Pi (3b+) went swimmingly and I actually ran this setup for three months. Until the SD Card threw up and it all came crashing down. Because there is logging inherent in Home Assistant, you should think twice about running it on a Pi that’s keeping it’s data on an SD Card. While you could boot your Pi 3 or Pi 4 from an SSD – Kindalame.com suggests that you actually run Home Assistant with Docker (of course) on a Linux machine.

Obtaining a Machine

Honestly, I like a good refurbished deal, and went for the best deal at Micro Center I could find because I’m cheap. My requirements were just an i5 or above CPU and the rest I was willing to price – RAM, hard drive space, all negotiable for the right amount. I got lucky and scooped up a decent little refurbished Acer desktop that has served as my little home assistant for over a year. All with little to no downtime.

The i5 CPU, 8GB of RAM and 1 TB hard drive for $350 was a great deal. But you don’t have to start here, you can start on another recycled computer or run this on a Pi in Docker as well. Having another side machine to run all of your containers is pretty nifty and having the uptime from a dedicated machine will be critical later.

Home Assistant and Docker

Home Assistant And Docker work well together, in fact, I’ve not seen a pre-built container image have better support from a development team. Basically out of the box the suggestion – and the way it should work always – is that your configuration, the heart of the entire container, sits on your local machine’s file system. This means it’s easy to make configuration changes, backup your entire setup or move to a different version of the container altogether.

Getting Home Assistant Running In Docker is easy, all we need to do is initiate one command to pull and start up the container. While this is just as easily, and even maybe rightfully, done a lot of time with Docker Compose I’ve never had a huge need to change. For Home Assistant I am getting by with just Docker run commands and haven’t changed it in a year.

Let’s look at the Docker run command to get Home Assistant going the first time;

sudo docker run --init -d --name="home-assistant" \
    -e "TZ=Europe/London" \
    -v /path/to/config:/config \
    -v /path/to/your_media:/media \
    --net=host \
    homeassistant/home-assistant:latest

This looks long, but to anyone familiar with Docker it’s easy stuff – and we’re even throwing in a bonus which is mounting some music but we could skip this line if we wanted to (and focus on the home automation aspect). If you’re just getting started with Docker, we’ll break down what the command does below.

How Home Assistant Works With Docker

Let’s break it down line by line to see how this one command works and you know what you’d need to change.

Getting Started
sudo docker run --init -d --name="home-assistant" \

Our first line above is the heart of running HA on Docker – run, in the background, a container named “home-assistant”.

Setting the Timezone
    -e "TZ=Europe/London" \

Above we are telling Home Assistant which is our local time zone. This is important as you want to make sure that any routines, or automations, that you setup are scheduled for your own local time. To find the right format for your timezone you should look at this page @ Wikipedia.

Mounting the Configuration Volume
    -v /path/to/config:/config \

This line of our command is going to create a local bind mount Docker volume. In English that means we’ll store files locally for this directory, on our filesystem, and not in the container. This is required, or rather strongly advised. But this is also the flexibility I spoke of – you can edit the configuration locally or wholly backup this directory to keep your settings safe. Change the right side of the colon to a directory of your choice such as a new folder in /home.

Mounting Your Media
    -v /path/to/your_media:/media \

The above part is the bonus command and we can totally leave it out if we didn’t want to include our music library. What we’re doing here is like the above – we’re telling Docker to use our local files in place of the /media folder in Home Assistant. Simply replace the path to the right of the colon (:) with the path of your choice.

Setting the Docker Network
    --net=host \

Let’s spare ourselves the esoteric write up about Docker networking – we don’t need to understand it to run Home Assistant in Docker. What we do need to do is bind the networking of the container directly to the networking of the machine we’re running Home Assistant on. Simply think that your home automation server should have a local IP address – not run on a fake esoteric adapter or have an address confusingly different so let’s keep it simple and leave this unchanged.

Pulling the Container Image
  homeassistant/home-assistant:latest

Finally, we’re telling Docker which image to pull from Docker Hub. And with Home Assistant, we always run the latest version in our home – though not always advised. To get started, this is a good place, it’s the most stable and feature rich. Later, you’ll want to watch the change logs for what Home Assistant developers call “Breaking Changes”. These may upset the ecosystem that you build – but we’ll cover that in another article.

Now we’re basically ready to run the Docker container but we’ll take a look at that command again with a real world example to see the difference.

Running The Command
sudo docker run --init -d --name="home-assistant" \
-e "TZ=America/New_York" \
-v /home/imalamer/hassio/:/config \
-v /mnt/externaldrive/music/:/media \
--net=host \
homeassistant/home-assistant:latest

Using the above we would have Home Assistant up and running now and we can actually log in after it starts up (usually in 30 seconds to a minute). To do so simply visit the following URL:

http://localhost:8123

If you’ve installed this through SSH on another machine, don’t worry you’ll be able to reach it with a URL like this simply changing the IP address for the one of your new home automation server:

http://192.168.1.148:8123

Technically, you’re done – you have Home Assistant running. That in itself is a huge feat and you’re probably discovering that some things are already working out of the box (or discovered by Home Assistant automatically like Hue bridges, Chromecasts or Google Home devices). In our next article on the topic we’ll take a closer look at setting up and extending Home Assistant.

Screenshot of Home Assistant Running in Docker
Our basic setup in a default Home Assistant server