Set up Home Assistant to manage your open source smart home

Learn how to install and configure Home Assistant in the fourth article in this series on home automation.
122 readers like this.
Working from home at a laptop

Opensource.com

In the first article in this series, I introduced Home Assistant and why you might be interested in it. In short, Home Assistant is an automation hub for some of the most common smart devices on the market today. It enables centralized coordination of disparate hardware. By using it, you no longer have to choose suboptimal tech from a single vendor to manage your smart home from a single app. It also means you will no longer struggle with a hundred different apps that all function slightly differently to manage all your devices. One program to rule them all… or at least that's the dream.

In the second and third articles, I looked at some of the decisions to make when developing home automation, namely local vs. cloud control, and whether to choose Zigbee, Z-Wave, or WiFi, just to hit the high points. This fourth article will be much more hands-on than the previous ones by walking you through setting up a virtual machine (VM) with the Home Assistant-provided image.

Set up the VM

I won't cover all of the methods available for installing Home Assistant (HA). I run HA in a virtualized environment, and the official installation page provides VMDK, VHDX, VDI, QCOW2, and OVA downloads. I have a libvirt-based homelab, so I chose the QCOW2 image.

Regardless of which hypervisor you use, you need to make sure that the boot type is set to UEFI instead of the traditional BIOS. In Arch Linux or Fedora, you need to install the package edk2-ovmf to have the option available in Virt-Manager. In Ubuntu, the package is called ovmf. After the package is installed, restart libvirt.

When you create your VM, select the HA image you downloaded. You can accept the default options that Virt-Manager selects until the confirmation screen. Make sure you check the box that says Customize configuration before install.

When you do this, make sure to change the firmware to UEFI:

Important note: You cannot change the firmware type after the VM has been created. If you choose BIOS, the VM will not boot!

If you need to expand the amount of disk available to HA's VM, shut down the VM and run:

qemu-img resize hassos_ova-4.13.qcow2 +40G

Upon boot, the new space will be automatically allocated to the appropriate partitions.

The first boot can take a significant amount of time, as HA pulls down the latest versions of software from the internet and prepares them for initial launch and configuration. To be on the safe side, walk away for 10 minutes or so before attempting to pull up the webpage for the first time. In my experience, it often requires less than five minutes, but 10 minutes is a good amount of time for the system to spin up and settle.

First-time setup

You should now be able to access the HA interface by pointing a browser to http://homeassistant.local:8123. However, this relies on your router to support automatic DNS registration. You can also access the webpage via its IP. In my case, that's http://192.168.122.90:8123.

Enter your username and password for the administrative HA account. Then it will prompt you to select a location.

As you can see, your location is used for "sun-based automations." This means it uses your longitude and latitude to determine sunrise and sunset times and your time zone. If, for example, you have an automation that says, "turn on desk light 20 minutes before sunrise and turn off an hour after sunrise," HA uses this location information to determine what time to activate the lights. Unfortunately, you have to use the graphical map to set this information, and it may not function properly without an active internet connection.

After you have completed this, you will see a confirmation screen.

Rather than setting up devices here, I prefer to click Finish and use the full UI to configure my devices. This is optional, of course. This screen may prepopulate some integrations, depending upon whether HA has automatically discovered devices on your network.

Initial user settings

After you finish the initial configuration, you will see the Overview page. HA's default interface is called Lovelace. It is a powerful YAML-described interface. This means that even if you can't choose certain user interface (UI) elements in the graphic interface, you can open the built-in YAML editor and add them yourself.

Lovelace's default view has a single card that displays the weather based on the location you entered. Click your username (stratus in this example) in the bottom-left panel.

This brings up another screen with several options. Find Advanced Mode and make sure it is toggled on.

This setting is toggled per user, so if you have other administrative users, only this one (e.g., stratus) will have advanced settings turned on. There are quite a few options exposed when toggling Advanced Mode, but the one you want is the ability to run a syntax check against the HA configuration files. To see this in action, navigate to Server Controls by clicking on the Configuration option in the bottom-left panel, and then click on Server Controls.

Clicking on the Check Configuration button will check all the HA configuration files for syntax errors. If it finds no errors, you will see a message in green that says Configuration Valid!

Looking ahead

Now that HA is set up and configured, you are ready to start really digging into it. In future articles, I will explain how to:

  • Install and configure add-ons
  • Create snapshots and run HA updates
  • Install the Home Assistant Community Store (HACS)
  • Configure entities via the built-in options
  • Work with MQTT
  • Create automation flows with NodeRed

And much more. If there's something else you want to learn, please share it in the comments. While I am not a Home Assistant expert, I will do my best to answer your questions about it.

What to read next
User profile image.
Steve is a dedicated IT professional and Linux advocate. Prior to joining Red Hat, he spent several years in financial, automotive, and movie industries. Steve currently works for Red Hat as an Architect in the Solutions and Technology Practice. He has certifications ranging from the RHCA (in DevOps), to Ansible, to Containerized Applications and more.

6 Comments

Did you run into any port conflicts between the VM and your host? I created a bridge controller for my Ethernet interface, so the host and the VM would have separate IP addresses. I seem to recall that this was necessary.

I haven't run into any port conflicts. The nature of VMs provides them with a separate network namespace by default.

On my "production" Home Assistant, I am using MacVLAN networking as the host and the guest do not need to communicate. I use bridged networking when the host and the guest need to interact for some reason, but generally I use MacVLAN

In reply to by Guy Streeter

After you finish the initial configuration, you will see the Overview page. HA's default interface is called Lovelace. It is a powerful YAML-described interface. This means that even if you can't choose certain user interface (UI) elements in the graphic interface, you can open the built-in YAML editor and add them yourself. https://mcdvoice.me/

Lovelace's default view has a single card that displays the weather based on the location you entered. Click your username (stratus in this example) in the bottom-left panel.

https://mcdvoice.me/ Very helpful and informative. Thank for sharing this post.

Thanks for helpful article .
I am just trying to understand why would you run it as a VM? It would need to have an uptime of 100% to communicate with all the IoT devices. Or am I not understanding you correctly?

Really there is no reason not to run things in a VM. VMs isolate the application from a host failure if configured for failover. They also help to 'sandbox' functionality much the same way (although arguably more securely) as containers.

VMs are capable of greater uptime than a single physical device (broadly speaking) because of the ability to have failover and storage redundancy.

Aside from this, its mostly just a preference on my part.

Side note: Home Assistant will reconnect to all the devices whenever it comes back online so while it would have to be on 24/7 for it to control all the devices, there is no penalty in terms of reconfiguration, if the HA instance is offline

In reply to by JJ

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.