name: home-automation-hub

x-logging: &default-logging
  driver: json-file
  options:
    max-size: 10m
    max-file: "3"

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
      - /run/dbus:/run/dbus:ro
    depends_on:
      mosquitto:
        condition: service_started
      zwave-js-ui:
        condition: service_started
    logging: *default-logging

  mosquitto:
    image: eclipse-mosquitto:2
    container_name: mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./config/mosquitto:/mosquitto/config
      - mosquitto-data:/mosquitto/data
      - mosquitto-log:/mosquitto/log
    logging: *default-logging

  zigbee2mqtt:
    image: koenkk/zigbee2mqtt:latest
    container_name: zigbee2mqtt
    restart: unless-stopped
    depends_on:
      mosquitto:
        condition: service_started
    environment:
      TZ: America/Toronto
    ports:
      - "8080:8080"
    devices:
      - /dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller:/dev/ttyUSB0
    volumes:
      - ./config/zigbee2mqtt:/app/data
      - /run/udev:/run/udev:ro
    logging: *default-logging

  zwave-js-ui:
    image: zwavejs/zwave-js-ui:latest
    container_name: zwave-js-ui
    restart: unless-stopped
    environment:
      TZ: America/Toronto
      SESSION_SECRET: change-me-in-production
    ports:
      - "8091:8091"
      - "3000:3000"
    devices:
      - /dev/serial/by-id/usb-0658_0200-if00:/dev/zwave
    volumes:
      - ./config/zwave-js-ui:/usr/src/app/store
    logging: *default-logging

  influxdb:
    image: influxdb:2
    container_name: influxdb
    restart: unless-stopped
    ports:
      - "8086:8086"
    environment:
      TZ: America/Toronto
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: homeops
      DOCKER_INFLUXDB_INIT_PASSWORD: change-me-in-production
      DOCKER_INFLUXDB_INIT_ORG: home
      DOCKER_INFLUXDB_INIT_BUCKET: homeassistant
      DOCKER_INFLUXDB_INIT_RETENTION: 180d
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: change-me-in-production
    volumes:
      - influxdb-data:/var/lib/influxdb2
      - ./config/influxdb:/etc/influxdb2
    logging: *default-logging

  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    restart: unless-stopped
    depends_on:
      influxdb:
        condition: service_started
    ports:
      - "3001:3000"
    environment:
      TZ: America/Toronto
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: change-me-in-production
      GF_USERS_ALLOW_SIGN_UP: "false"
    volumes:
      - grafana-data:/var/lib/grafana
      - ./config/grafana/provisioning:/etc/grafana/provisioning:ro
    logging: *default-logging

volumes:
  mosquitto-data:
  mosquitto-log:
  influxdb-data:
  grafana-data: