Simple HomeAssistant docker-compose setup
First, create a directory where HomeAssistant will reside. I use /opt/homeassistant.
Create docker-compose.yml:
services:
homeassistant:
container_name: homeassistant
restart: unless-stopped
image: ghcr.io/home-assistant/home-assistant:stable
network_mode: host
privileged: true
environment:
- TZ=Europe/Berlin
volumes:
- ./homeassistant_config:/config
depends_on:
- mosquittoNow start homeassistant so it creates the default config files:
docker-compose upOnce you see
homeassistant | [services.d] done.Press Ctrl+C to abort.
Now we’ll create the Mosquitto MQTT server config file in mosquitto_conf/mosquitto.conf:
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## Authentication ##
allow_anonymous false
password_file /mosquitto/config/mosquitto.passwdNow create the mosquitto password file and fix the permissions using
touch mosquitto_conf/mosquitto.passwd
chown -R 1883:1883 mosquitto_confWe can now start create the homeassistant mosquitto user using
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd homeassistantEnter a random password that will be used for the homeassistant user
Now we can edit the homeassistant config homeassistant_config/configuration.yml. This is my config - ensure to insert the random MQTT password we used before instead of ep2ooy8di3avohn1Ahm6eegheiResh:
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
http:
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
ip_ban_enabled: true
login_attempts_threshold: 5
mqtt:
broker: "127.0.0.1"
username: "homeassistant"
password: "ep2ooy8di3avohn1Ahm6eegheiResh"
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yamlNow we can start the server using
docker-compose upYou can also use our script to generate a systemd service to autostart the docker-compose config on boot:
curl -fsSL https://techoverflow.net/scripts/create-docker-compose-service.sh | sudo bash /dev/stdinNow login to the web interface on port 8123 and configure your HomeAssistant!