Experimentation install of Homeassistiant on a Zero 2W

I have a few more things I want to experiment with on Homeassistant and some with ESPHome. Having unused stuff on my primary Homeassistant starts to annoy me, so I will install Homeassistant on a Raspberry PI Zero 2W for short term experimentation.

I will not use the installation instructions for Raspberry PIs on the Homeassistant site. Mainly because I generate my Raspberry PI images with Ansible and want to use one of these images as starting point.

Because Homeassistant requires Python 3.12 and the default on the current Raspberry PI OS is Python 3.11, I chose to use Docker and not run Homeassistant via systemd. So my starting point is Install Home Assistant Container.

I am aware that the Zero 2W has not enough RAM, so a swapfile is probably a good idea. Raspberry PI seems to have a default way to handle swap (dphys-swapfile), but I want to use the same way I use on other systems, so I ignore that there is already an existing swap with 200M as default.

All commands for future me:

# get system up to date
sudo apt-get update && sudo apt-get upgrade -y

# add 1GB of swap
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
# register in fstab to persist for next boot
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

# install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# sudo every time is fine for me
sudo docker ps

This is the compose file from the Homeassistant instructions with only the config line modified:

services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/pi/.homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

Finally use the docker-compose.yml to start Homeassistant:

# pull image
sudo docker compose pull
# run it (in the background)
sudo docker compose up -d
# to view logs
sudo docker compose logs -f

The container runs in host mode, so it is visible in the local network. A http://<ip-address-of-pi>:8123 works for me. Then follow the onboarding. For me my ESPHome devices were found at the end of the onboarding and I installed some of them to have some data in.

My dashboard looks like this after the setup:

img1

This feels like a good starting point for further Homeassistant experiments.

Route ESPHome to Homeassistant via Tailscale

For a possible future deployment of ESPHomes at a different location, I wanted to know how much hassle this would be by using Tailscale to route between the two locations. I already have Raspberry PI Zeros deployed at a second location that push to my Homeassistant via tinc VPN. But there is no way to install tinc on ESPHome. Wireguard seems to be supported on ESP32s but with a few disclaimers. Currently I am mainly using Picos, but I may try Wireguard on ESP32 at some time in the future.

To get an ESPHome device routed to my Homeassistant I used the subnet option in Tailscale as described in there knowledge base. For this I used an old Raspberry PI zero as router at the different location. After enabling the IP forwarding, announcing the route, approve it and accepting it on my Homeassistant Linux everything worked as expected.

The command I called on the routing PI:

sudo tailscale up --advertise-routes=192.168.56.0/24

I tried to disable SNAT (--snat-subnet-routes=false) but this didn't help on the one issue this whole thing still has: no auto detection in Homeassistant probably because mDNS throught the subnet router doesn't work.

So after adding an ESPHome device to the routed subnet I needed my notebook the get the IP address. I watched the logs of the device with:

docker compose run --rm esphome logs pico5.yaml

The alternative would be to look on the internet router (a Fritzbox) or try a nmap broadcast to get the IP address. Adding the IP address in the Homeassistant ESPHome integration and everything works:

img1

(Automatic) changing of the IP address is an issue here. With mDNS the address will be automatically updated in Homeassistant, but without the device will not be polled after the change. I will monitor this and maybe decide that a second Homeassistant is the better alternative.