There are several ways to setup Home Assistant. It can run on a dedicated machine for example raspberry pi with the Home Assistant Operating System (HAOS). HA can also be run in a container environment on any pic you might have around. See setting up home assistant for more details.
I had an 12 year old iMac which had its hard drive die. I set it up to boot into Ubuntu from an external SSD. This machine has enough power to run various tasks I need from Ubuntu. It can also to run Docker allowing HA to run in containers.
Home assistant docker setup
Home assistant has a docker container available which you can use to run it. However it takes a bit more work and add-ons to be set up in separate containers.
I use a docker-compose.yml file to launch all the containers I need – at the moment, I have
- Home Asisstant
- mariadb as the database for HA
- mosquitto for MQTT. This is using a shared network so that I can send MQTT data from another container I start separately.
- zwavejs for zwave
- phpmyadmin – to keep an eye on the database
- nginx – to be able to login remotely to my HA setup
You won’t need all these to get started, probably just HA and mariadb would be a good place to start. I’m documenting other services to give an idea of the level of technical know needed to use docker instead of the HAOS.
The docker-compose file to start all these services looks like this
# docker-compose.yml
services:
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:stable"
volumes:
- /home/Documents/home_assistant/my_local_config:/config
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
restart: unless-stopped
privileged: true
network_mode: host
depends_on:
- mariadb
stdin_open: true
tty: true
mariadb:
image: mariadb:latest
container_name: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: hass_database
MYSQL_USER: homeassistant
MYSQL_PASSWORD: "${HASS_MYSQL_PASSWORD}"
PUID: "${PUID}"
PGID: "${PGID}"
ports:
- "3306:3306"
volumes:
- /home/Documents/home_assistant/mysql_data:/var/lib/mysql
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
restart: always
environment:
PMA_HOST: mariadb
PMA_USER: root
PMA_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
ports:
- "8080:80"
depends_on:
- mariadb
zwavejs2mqtt:
container_name: zwavejs2mqtt
image: zwavejs/zwavejs2mqtt:latest
restart: always
tty: true
stop_signal: SIGINT
environment:
- SESSION_SECRET=yourSuperSecretHere
- ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
devices:
- '/dev/serial/by-id/usb-Silicon_Labs_your_device-port0:/dev/zwave'
volumes:
- /home/Documents/home_assistant/z-wave_config:/usr/src/app/store
ports:
- "8091:8091" # port for web interface
- "3000:3000" # port for Z-Wave JS websocket server
npm:
container_name: npm
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
# These ports are in format <host-port>:<container-port>
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
environment:
TZ: "Australia/Brisbane"
volumes:
- /home/Documents/home_assistant/nginx/data:/data
- /home/Documents/home_assistant/nginx/letsencrypt:/etc/letsencrypt
- /home/Documents/home_assistant/nginx/static_site:/static
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto
restart: unless-stopped
volumes:
- /home/Documents/home_assistant/mosquitto:/mosquitto
- /home/Documents/home_assistant/mosquitto/data:/mosquitto/data
- /home/Documents/home_assistant/mosquitto/log:/mosquitto/log
ports:
- 1883:1883
- 9001:9001
networks:
- my_shared_network
networks:
my_shared_network:
external: true
I stored the passwords in a .env file in the same directory as the docker-compose.yaml file. Docker compose automatically loads this file if it exists and sets the environment variables.
# .env file
MYSQL_ROOT_PASSWORD=MyReallySTrongPassword
HASS_MYSQL_PASSWORD=AnotherGoodPassword
PUID=1000
PGID=1000To start all the containers just run the command.
$ docker compose up -dYou can monitor that everything is working by issuing the docker ps command.
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES IMAGE STATUS
npm jc21/nginx-proxy-manager:latest Up 11 days
docker2mqtt docker2mqtt-docker2mqtt Up 11 days
phpmyadmin phpmyadmin/phpmyadmin Up 11 days
homeassistant ghcr.io/home-assistant/home-assistant:stable Up 11 days
mariadb mariadb:latest Up 11 days
mosquitto eclipse-mosquitto Up 11 days
zwavejs2mqtt zwavejs/zwavejs2mqtt:latest Up 11 days
Leave a Reply