Home Assistant

Introduction

Home Assistant is free and open-source software for home automation designed to be a central control system for smart home devices with a focus on local control and privacy. It can be accessed through a web-based user interface, by using companion apps for Android and iOS, or by voice commands via a supported virtual assistant such as Google Assistant or Amazon Alexa.

The Docker Compose File

---
version: "3.8"

services:
  home-assistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: home-assistant
    hostname: home-assistant
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    environment:
      - TZ=Europe/Stockholm
      - PUID=1000
      - PGID=1000
    ports:
      - 8123:8123
    volumes:
      - /opt/home-assistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    labels:
      - com.centurylinklabs.watchtower.enable=true

docker-compose.yml

This Docker Compose file defines a single service named “home-assistant”. The service is built from the “ghcr.io/home-assistant/home-assistant:stable” Docker image, which is the latest version available. The container name is set to “home-assistant” as well.

The “restart” section ensures that the container will always be restarted if it exits (unless manually stopped). This is useful for ensuring that the service is always available, especially if it crashes or is shut down unexpectedly.

The “security_opt” section prevents your container processes from gaining additional privileges. This is an important security consideration.

The “ports” section maps port 8123 on the host machine to port 8123 in the container. This allows us to access the Home Assistant web interface from our local machine. By default, Home Assistant runs on port 8123, but you can change it if necessary.

The “volumes” section maps the “/config” directory inside the container to a local directory on the host machine. This allows us to persist data across container restarts. Home Assistant stores all its configuration data in this directory, so it’s important to keep it intact.

The "labels" section allows the Watchtower service to keep this container update automatically.

Running Home Assistant with Docker Compose

To run Home Assistant with Docker Compose, first, make sure you have Docker and Docker Compose installed on your machine. Then, create a new directory for your project and save the above Docker Compose file as “docker-compose.yml” in that directory.

Next, run the following command from the same directory:

docker compose up -d

This command will start the home-assistant container in the background and detach from it. You can then access the Home Assistant web interface by going to http://localhost:8123 in your web browser.

Conclusion

In this article, we explored how to set up and run the Home Assistant software using Docker Compose. We looked at the different sections of the Docker Compose file and explained how they work together to create a functional Home Assistant service. By running Home Assistant with Docker Compose, you can easily deploy and manage the tool on your own server, without having to worry about dependencies or configuration.


Home Assistant
Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.