12/27/2021

Hassio On Docker

11

If you have ever played with home automation at all you most likely would have come across the software Home Assistant, Think of it as a hub like Smartthings or Vera that you build yourself. The most common way to do this is with a Raspberry Pi and a SD card loaded with the Home Assistant image (previously known as the Hass.io image) and soon you will be set to start connecting to the smart devices around your home and automating them. I had been running a Raspberry Pi setup for close to 2 years until one day the SD card died on me, as I didn’t have a replacement SD card at the time I decided to temporarily get hass.io up and running on my ubuntu laptop. It ran so well I have decided to ditch the Pi altogether and run Home Assistant supervised (formally called hass.io supervised) on a mini PC. Many people do this on an Intel Nuc, I found them to be a bit pricey for what they were and decided to go with an old Lenovo M93P mini PC that I picked up off Ebay for around $250AU. This Intel i5-4570 3.0ghz PC with 8gb ram and 120gb ssd is powerful enough to run Home Assistant blazing fast along with much more other software. The benefit of using an Intel NUC over this method is that there is a Home Assistant image available for it. With my mini Lenovo PC I only have the choice of running Home Assistant Core (Home assistant without the add-ons and snapshot feature etc). Home Assistant in a VM or Home Assistant Supervised on Docker. This post deals with the later.

  1. Run Hassio On Docker
  2. Hassio On Docker
  3. Install Hassio On Docker Raspbian
  • When it comes to controlling your Internet of Things devices such as lights, sensors, plugs, outlets, switches and more, Home Assistant has been the most prominent dashboard platform in the industry. Did we mention it’s both free and open source? Continue reading.
  • Run docker-compose up -d and then navigate to the host's ip on port 1880. Connecting Node Red to Home Assistant. The first thing we need to do to connect Node Red to Home Assistant is generate an access token. I decided to at the same time create a new user in Home Assistant specifically for Node Red.

Once Home Assistant is up and running you can then import your previous Home Assistant snapshot and your Home Assistant setup will be fully migrated over to your new mini PC server.

If Docker is working correctly the following message will be displayed: Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. The Docker daemon pulled the 'hello-world' image from the Docker Hub. For a long time I've been using Ubuntu with Docker for my HomeAssistant setup, but when trying to get that working on my Pi 4 I realized that my regular 'install docker, install portainer and grab hassio' did not work.

Step 1 Setup PC

I downloaded the latest Ubuntu Desktop (19.10 at the time or writing) and chose minimal install, when choosing to format the disk I chose the LVM option as there is an option to easily create snapshots of the drive with LVM. The install of Ubuntu desktop is pretty self explanatory.

Many people suggest Ubuntu Server when setting up a system like this but I am choosing desktop as I plan to install a few other things later on that may require it and I prefer to use the GUI where I can. Under the hood both flavors of Ubuntu are the same.

When setting up the system create a user and password that you won’t forget.

Once Ubuntu is installed logon and open a terminal and run the below commands to check all is up to date.

Another thing you will need later is the PC’s ip address, click on the network icon on the menu bar followed by wired connection followed by wired settings then click the gear icon in the connected box. you will see the ipv4 address here starting with 192.168… remember this address and set it permanently here in settings or reserve it in the DHCP section of your router.

Step 2 Setup Remote Desktop

As this PC will be living in my server cabinet I don’t want to connect a monitor to it every time I want to fiddle with it. So my plan is to use the Remote Desktop Connection program that is built into Windows to connect to the Min PC’s desktop. To setup remote desktop on the Ubuntu side you will need to install xrdp so open terminal and run the following commands.

Let’s install jq as this is required for Home Assistant and was not there by default when I was using Ubuntu 20.04.

Note that once you unplug your monitor to put your mini PC in the cupboard, Ubuntu will see that there is no monitor connected and may give you issues remote desktoping to it. I got around this by using a dummy VGA adaptor like this one. Alternatively you could install a dummy display driver like outlined here.

Step 3 Install docker

At the time of writing docker images were not out for Ubuntu 19.10 so I had to install it via the 19.04 “disco dingo” images. Depending on when you read this there maybe a newer way to install it. What I did was based on this post and is outlined below.

Setup the key

check the key

you will get a few strings of text starting with pub rsa4096 ..

Now add the “disco dingo” repository and install docker

Once done you can verify the install with.

The details of your docker install will be displayed on the screen.

Step 4 Install Home Assistant

We are going to use the Home Assistant installer to install Home Assistant. Firstly in terminal run sudo su to become the root user then run the following command to pull down the Home Assistant image and install.

Make sure you change the user above to your Ubuntu user name. This command at the end places your Home Assistant config documents in your Ubuntu user directory and will make accessing them for setup and back up easier later on.

Step 5 Setup Home Assistant

Once the above command has finished, you should be able to get to the default new Home Assistant install by visiting localhost:8123 on your Ubuntu desktop’s browser. From here, simply setup a new user and you are ready to go with Home Assistant.

Step 6 Migrating from another Home Assistant install

If you are migrating a Home Assistant install from another system, copy your snapshot file to your /home/user/docker/hassio/backup directory in Ubuntu’s file manager (alternatively, set up and use the samba add on). Then head to Home Assistant’s supervisor/ snapshot page and hit the refresh arrow on the top right. Your backup will appear on the snapshot page, and you will be able to restore from that backup image. Once the snapshot is restored, you will be able to login with your original Home Assistant user details.

I still use a manual port forwarding and let’s encrypt certificates setup and not Home Assistant’s Nabu Casa cloud on my system, so once the snapshot was up and running I had to redirect my router settings to my new Home Assistant PC. Once this was done, I could test out my new installation with my original Home Assistant https:// url.

Wrap up

That’s it for this post. I will be doing some follow up post were I setup automatic backup amongst other things. I have been running hass.io on my new mini PC for a few weeks now and previously on an old i5 laptop with 4gb of ram for over a year. While setup is a bit more poking around at the start, once you move from the Raspberry Pi you will never look back.

Run Hassio On Docker

Update May 2020

I have just built a 2nd system for a friend using the above as a guide on Ubuntu 20.04 LTS Focal Fossa. Everything went well, I have updated one link above that had changed due to Home Assistant’s rebranding of Hass.io to Home Assistant. I have also updated the article to refer to the system formerly known as Hass.io as its new name of Home Assistant.

Update September 2021

I have moved my Home Assistant install to a VM under Proxmox on the same hardware as above and this is the way I will do any future installs from now on as the above method is officially unsupported now. Check out my new post on how to install Home Assistant under Proxmox here.

Hassio On Docker

We need to add a few package to the default Docker image that hosts our Hass.io configuration files.

Docker only installs the packages specified in the Dockerfile that defines the image. This helps manage dependencies and keeps the image as small as possible.

However, we need some additional tools installed so we can easily modify the configuration files and version control them.

Specifically, we need vim & git. Sorry emacs fans, you are wrong here :). Vim is derived from the oldest text editors on the UNIX system and has been available on every Linux system since the beginning. Learning vim is a vital skill for any developer. Vim’s ability to chain together commands is incredibly powerful and makes editing very efficient for a power user.

Nowadays, everyone is using IDEs like VS Code, Visual Studio, IntelliJ, or even good old Notepad++. I will admit, I am mostly using VS Code both at work and at home. However, the first plugin I install is the VIM key bindings. The vim way of doing things is just too powerful and productive to give up (even if the GUI of VS Code is very helpful, it is not as powerful).

Since we will be SSH-ing in to the Raspberry Pi and it has a relatively low power processor, using vim is the most efficient and fastest way to get our work done. No shame if you want to RDP into your Raspberry Pi and install an IDE (or use SAMBA), but I prefer simple and fast.

  • Launch PuTTY and connect to your Raspberry Pi (if you need a refresher, please see my previous blog post).
  • Notice we are in the home directory of the “pi” user
  • We need to “login” to the Docker container that hosts Hass.io.
    • This command will sudo (elevate our privileges), docker (run a Docker command), exec (run a command in a Docker container), -it (start an interactive session), homeassistant (create the session on the homeassistant container, /bin/bash (open a Bash shell).

Bash is the most popular Linux shell (command interpreter) and is another vital part of your professional software development toolkit.

Hassio On Docker

After starting the Bash shell, we can see that we are in the “config” directory under “root” inside the container.

If you “list” the directory, you can see the various configuration files Hass.io uses.

These are the YAML files that control your Hass.io installation. As you can see, there are lots of files (mine will have more than yours if you are just starting out).

However, if you tried to run git or vim now, you will get an error.

Again, this is because there is nothing installed in the Docker container that was not in the Dockerfile originally. So I don’t have to modify the default Dockerfile, let’s add the needed packages manually each time I login.

Apk is a package management system used by our running container. We need to use the add command to install the two packages we need (technically, we don’t need vim since vi is installed by default, but that would just be barbaric :)).

Install Hassio On Docker Raspbian

Running these 3 commands each time we login to our Raspberry Pi to edit the configuration will get tedious, so let’s cause it to happen whenever we login. Exit the bash shell you are currently in (make sure you are in the home directory for the pi user).

  • Use vim to create a new file in the home directory of the pi user.
    • A .bash_profile is a “hidden” file that is executed whenever a new bash shell is instantiated (like when you login to the Raspberry Pi).

Vim has 2 modes of operation (command & insert). This is the hardest concept to learn since this is the complete opposite of most of the WYSIWYG editors you are used to using in Windows (or emacs). Vim command mode is for moving around the editor window and manipulating text. Vim insert mode is for actually typing in text.

Hassio on docker ubuntu
  • Make sure you are in insert mode (press i if you are not sure, it will say — INSERT — at the bottom of the screen). Enter the following text.
  • Press Esc, then :wq. Congratulations! You have successfully gotten over the most asked question on StackOverflow; you have successfully exited vim.

Now close PuTTY and reopen. You will see that you are no longer logged into the default pi user anymore. You have been logged into the Hass.io Docker container.

Now we need to ensure vim and git are installed whenever you login (in a future article, I will figure out how to actually modify the Dockerfile and install these packages by default, but I’m not sure how to make sure I am always up to date with the Hass.io image, so it will have to wait).

  • Create a .bashrc file in the root home directory (it will get run whenever you login to the container and install the needed packages).
Hassio

Now close PuTTY and reopen. You will see that you are no longer logged into the default pi user anymore. You have been logged into the Hass.io Docker container and the 2 most important tools have been installed for you (which is the command to see where an executable is located on the filesystem).

  • Most Viewed News

    • Mcafee Dmg
    • Omv 5 Docker
    • Install Docker Windows Server 2016 Offline