Home Assistant


Home Assistant (HA) is so much more than home automation, it’s a platform for all your things.
This post is being written using the Studio Code Server add on.
Sensors can be stored and plotted using the InfluxDB and Grafana add ons.
It can easily (and securely) be exposed to the internet using Tailscale and Caddy.
The list goes on (add-ons) and on (community add-ons).

My HA is running in a LXD virtual machine.
Assuming you have a configured LXD environment, setting up the VM is straightforward:

# Download the OVA image
$ wget https://github.com/home-assistant/operating-system/releases/download/9.3/haos_ova-9.3.qcow2.xz
# Uncompress
$ xz -d haos_ova-9.3.qcow2.xz
# Create a metadata.yaml file to describe the VM
$ vi metadata.yaml
architecture: x86_64
creation_date: 1643062675
properties:
  description: Home Assistant OS 9.3
  os: HAOS
  release: 9
# Create a metadata tar archive because that is what LXD needs
$ tar cf metadata.tar metadata.yaml
# Import the image
$ lxc image import metadata.tar haos_ova-9.3.qcow2 --alias hass
# Create the VM (hass) from the imported image (also named hass) - disable secureboot
$ lxc init hass hass --vm -c security.secureboot=false
# Give the VM a larger root disk
$ lxc config device override hass root size=64GiB
# And more CPU / memory - defaults of 1CPU/1GB will work but are not good long term
$ lxc config set hass limits.cpu 4
$ lxc config set hass limits.memory 8GB
# Finally, add a network adapter named eth0, where 'br0' is a bridge network on the host server
$ $lxc config device add hass eth0 nic nictype=bridged parent=br0 name=eth0

It uses a SONOFF Universal Zigbee 3.0 USB Dongle and Zigbee2MQTT to control plugs, PIR, lights.
Configuring the VM to use the USB adapter is as easy as:

# Get the USB adapter ID, 10c4:ea6 in my case
$ sudo lsusb
... 
Bus 001 Device 006: ID 10c4:ea60 Silicon Labs CP210x UART Bridge

# Map the device to the VM
# Adding a device named 'sonoff' to the VM named 'hass' with the given vendor and product ID's
$ lxc config device add hass sonoff usb vendorid=10c4 productid=ea60

Now we can start the VM:

$ lxc start hass

Connect to it’s console to watch it boot:

$ lxc console hass

Use the console to login (as root) and get the IP address.
Can now visit http://IPADDRESS:8123 and HA will be starting up, complete the usual initial configuration and that’s it.

The advantage of using a VM for me:
1. Backups as simple as taking a snapshot of the VM.
2. Clone the VM for testing, or create a new VM, in a few minutes.
3. Adjust CPU, memory, disk space up (or down), e.g. increase memory to handle Studio Code Server.

Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.