๐ŸŒ Overview

This docker-compose.yml file outlines a multi-container configuration for a home automation system, incorporating Homebridge, Mosquitto, and Zigbee2MQTT. It encompasses essential configurations for each service, including volumes, devices, and environment variables.

This setup serves to seamlessly integrate diverse smart home devices, encompassing lights, sensors, and switches, into the home automation framework. Inter-service communication occurs over the local network throughMQTT andZigbee protocols. The host machine for container execution is aRaspberryPi. Conbee II is the Zigbee USB dongle used for Zigbee device communication.

๐Ÿ“ Configuration

docker-compose.yml
version: "3"
 
services:
  homebridge:
    image: homebridge/homebridge:latest
    restart: always
    network_mode: host
    hostname: homebridge
    container_name: homebridge
    volumes:
      - ./homebridge:/homebridge
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    logging:
      driver: json-file
      options:
        max-size: "10mb"
        max-file: "1"
 
  mosquitto:
    image: eclipse-mosquitto
    restart: unless-stopped
    hostname: mosquitto
    container_name: mosquitto
    ports:
      - 1883:1883
      - 9001:9001
    volumes:
      - ./mosquitto:/mosquitto
    command: "mosquitto -c /mosquitto-no-auth.conf"
 
  zigbee2mqtt:
    image: koenkk/zigbee2mqtt:1.20.0
    restart: unless-stopped
    network_mode: host
    hostname: zigbee2mqtt
    container_name: zigbee2mqtt
    volumes:
      - ./zigbee2mqtt:/app/data
      - /run/udev:/run/udev:ro
    environment:
      - TZ=Europe/Berlin
    devices:
      - /dev/ttyACM0:/dev/ttyACM0

๐Ÿ’๐Ÿผโ€โ™€๏ธ Services

๐Ÿ  Homebridge

The homebridge service runs the Homebridge server, which acts as a bridge between smart home devices and Appleโ€™s HomeKit. It allows non-HomeKit compatible devices to be controlled via the Home app on iOS devices.

  • image: Specifies the Docker image to use for theHomebridge service. In this case, it uses the latest version of the official Homebridge image.
  • restart: Specifies the restart policy for the container. The always option ensures that the container restarts automatically if it stops.
  • network_mode: Sets the network mode for the container to host, allowing the container to use the host network stack.
  • hostname: Defines the hostname for the container.
  • container_name: Specifies the name of the container.
  • volumes: Maps a local directory (./homebridge) to the /homebridge directory in the container. This volume is used to persist Homebridge configuration and data.
  • devices: Binds the host device /dev/ttyACM0 to the container device /dev/ttyACM0. This is used to communicate with USB devices connected to the host machine.
  • logging: Configures the logging driver for the container to write logs to a JSON file.
    • driver: Specifies the logging driver to use.
    • options: Specifies additional options for the logging driver, such as the maximum log file size and the number of log files to keep.
      • max-size: Limits the size of each log file to 10 MB.
      • max-file: Specifies that only one log file should be kept.

๐Ÿ”Œ Mosquitto

The mosquitto service runs the Mosquitto MQTT broker, which facilitates communication between MQTT clients and devices in the home automation system.

  • image: Specifies the Docker image to use for theMosquitto service. In this case, it uses the official Eclipse Mosquitto image.
  • restart: Specifies the restart policy for the container. The unless-stopped option ensures that the container restarts unless explicitly stopped.
  • hostname: Defines the hostname for the container.
  • container_name: Specifies the name of the container.
  • ports: Exposes the MQTT broker on ports 1883 and 9001 on the host machine.
  • volumes: Maps a local directory (./mosquitto) to the /mosquitto directory in the container. This volume is used to persist Mosquitto configuration and data.
  • command: Specifies the command to run when starting the Mosquitto container. In this case, it runs Mosquitto with a custom configuration file (mosquitto-no-auth.conf) to disable authentication.

๐Ÿ Zigbee2MQTT

The zigbee2mqtt service runs the Zigbee2MQTT bridge, which allows Zigbee devices to communicate with MQTT clients and other services in the home automation system.

  • image: Specifies the Docker image to use for the Zigbee2MQTT service. In this case, it uses version 1.20.0 of the official Zigbee2MQTT image.
  • restart: Specifies the restart policy for the container. The unless-stopped option ensures that the container restarts unless explicitly stopped.
  • network_mode: Sets the network mode for the container to host, allowing the container to use the host network stack.
  • hostname: Defines the hostname for the container.
  • container_name: Specifies the name of the container.
  • volumes: Maps local directories (./zigbee2mqtt and /run/udev) to directories in the container. These volumes are used to persistZigbee2MQTT configuration and data, as well as to access the hostโ€™s udev directory.
  • environment: Sets the TZ environment variable to Europe/Berlin, specifying the containerโ€™s time zone.
  • devices: Binds the host device /dev/ttyACM0 to the container device /dev/ttyACM0. This is used to communicate with Zigbee USB dongles connected to the host machine.