Skip to main content
  1. Posts/

Notes on moving Home Assistant from Raspberry Pi to Docker

·754 words·4 mins
ß
Photo by Venti Views on Unsplash

I started out running Home Assistant about 3 years ago, playing around with a few light bulbs. Installing it on an SD card was ( and still is) the recommended way to go. However, SD cards can’t handle small I/O very well, and tend to crash after a while. This has happened to me twice. Usually not a big deal if you keep your back-ups, but increasingly worrysome as the number of devices and thus my dependence on Home Assistant grows. This is always in the back of my mind.

Recently I installed a home server to serve as a NAS, media server, DNS, etc using Docker containers. And I figured I would also move my Home Assistant installation to it. This blog post contains some notes on the migration.

Restoring from back-up #

I did a full backup of Home Assistant on my old installation and copied it over.

Unfortunately, the Docker install of Home Assistant does not support restoring from a back-up.

So in the end, I extracted the backup. I extracted homeassistant.tar.gz. Inside is a directory data, which I renamed to config and moved to $DOCKERDIR/homeassistant/ (see below). Anything else in the archive is not used. It seems that I simply could have copied over the config directory directly from my old install.

Docker compose #

I use docker compose to load my Docker containers. This is the docker compose snippet I added to my docker-compose.yml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
version: "2.4"
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - $DOCKERDIR/homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
      - /dev/ttyUSB0:/dev/ttyUSB0
    restart: always
    privileged: true
    ports:
      - 8123:8123

The snippet is slightly modified from the Home Assistant documentation. I did not want to use network_mode: host, so I had to forward the 8123 port.

$DOCKERDIR is an environment variable defined in a .env file in the same directory. It points to a path where my Docker config files are stored.

Uninstall system integrations #

There are some integrations that are included for interfacing with the Home Assistant Operating System. With a Docker install these are no longer needed. Starting the container would greet me with a couple of errors of the likes: The following integrations could not be set up... for hassio and raspberrypi.

The Raspberry Pi integration could be removed from the integrations page.

Then I removed the hassio integration by hand (it cannot be removed via the GUI), by opening config/.storage/core.config_entries. Look for the entry that looks below this and remove it

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
      {
        "entry_id": "8809d872e74ca46913179fb6448b3621",
        "version": 1,
        "domain": "hassio",
        "title": "Supervisor",
        "data": {},
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "system",
        "unique_id": "hassio",
        "disabled_by": null
      },

USB permissions in Docker rootless #

I run Docker in rootless mode. This gave some issues with accessing my Zigbee stick and other usb devices in Home Assistant. As a work-around, I had to update the permissions.

Get the IDs of the USB devices using: ls -l /dev/serial/by-id

Set the permissions:

1
2
sudo chmod 666 /dev/ttyACM0
sudo chmod 666 /dev/ttyUSB0

This has to be done on every reboot. This link provides a method to set the permissions automatically.

HA sidebar shortcuts #

You can add shortcuts to he Home Assistant side bar to link to other services on the server, for example Jellyfin.

To do so, add this snippet to your configuration.yaml:

1
2
3
4
5
6
panel_iframe:
  portainer:
    title: "Jellyfin"
    url: "https://192.168.1.123:8096"
    icon: mdi:jellyfish
    require_admin: false

Migrating InfluxDB #

I run InfluxDB on Home Assistant for long term data storage. The database also had to be moved. Make sure that you use InfluxDB version 1.8. To migrate the database I did the following.

On Home Assistant on the Raspberry Pi, I opend an SSH shell and entered the influxdb container:

docker exec -it addon_a0d7b954_influxdb /bin/bash

Then I backed up the database:

influxd backup -portable -database homeassistant /data/homeassistant.db

From the home assistant backup, I extracted a0d7b954_influxdb.tar.gz and moved homeassistant.db to my new server.

I entered my influxdb container:

docker exec -it influxdb /bin/bash

And imported restored the database:

influxd restore -portable /data/homeassistant.db

Afterwards I had to update the host/port to point to the new database location.

1
2
3
influxdb:
  host: ...
  port: ...

Conclusion #

I cannot say it was a painless exercise, but fairly happy with the result and learned a lot in the process. My new installation runs noticably faster, and I sleep better at night not having to worry about SD crashes 😅