name: home-automation-hub

services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: homeassistant
    restart: unless-stopped
    network_mode: host
    privileged: true
    environment:
      TZ: America/Toronto
    volumes:
      - ./config/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      mosquitto:
        condition: service_healthy
      zigbee2mqtt:
        condition: service_started

  mosquitto:
    image: eclipse-mosquitto:2
    container_name: mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./config/mosquitto:/mosquitto/config
      - ./data/mosquitto:/mosquitto/data
      - ./logs/mosquitto:/mosquitto/log
    healthcheck:
      test: ["CMD-SHELL", "mosquitto_sub -h localhost -t '$$SYS/#' -C 1 -W 5 >/dev/null 2>&1"]
      interval: 30s
      timeout: 10s
      retries: 3

  zigbee2mqtt:
    image: koenkk/zigbee2mqtt:latest
    container_name: zigbee2mqtt
    restart: unless-stopped
    depends_on:
      mosquitto:
        condition: service_healthy
    ports:
      - "8080:8080"
    environment:
      TZ: America/Toronto
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    volumes:
      - ./config/zigbee2mqtt:/app/data
      - /run/udev:/run/udev:ro

  zwavejs:
    image: zwavejs/zwave-js-ui:latest
    container_name: zwavejs
    restart: unless-stopped
    ports:
      - "8091:8091"
      - "3000:3000"
    environment:
      TZ: America/Toronto
      SESSION_SECRET: change-me-before-deploy
    devices:
      - /dev/ttyUSB1:/dev/zwave
    volumes:
      - ./config/zwavejs:/usr/src/app/store

  influxdb:
    image: influxdb:2
    container_name: influxdb
    restart: unless-stopped
    ports:
      - "8086:8086"
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: homeassistant
      DOCKER_INFLUXDB_INIT_PASSWORD: change-me-before-deploy
      DOCKER_INFLUXDB_INIT_ORG: smart-home
      DOCKER_INFLUXDB_INIT_BUCKET: telemetry
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: change-me-before-deploy
    volumes:
      - ./data/influxdb:/var/lib/influxdb2

  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    restart: unless-stopped
    depends_on:
      - influxdb
    ports:
      - "3001:3000"
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: change-me-before-deploy
      GF_USERS_ALLOW_SIGN_UP: "false"
    volumes:
      - ./data/grafana:/var/lib/grafana

volumes:
  homeassistant_config:
  mosquitto_data:
  zigbee2mqtt_data:
  zwavejs_store:
  influxdb_data:
  grafana_data: