name: home-automation-hub

services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: homeassistant
    restart: unless-stopped
    privileged: true
    network_mode: host
    environment:
      TZ: America/Toronto
    volumes:
      - ./homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8123/"]
      interval: 30s
      timeout: 10s
      retries: 5

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

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

  nodered:
    image: nodered/node-red:latest
    container_name: nodered
    restart: unless-stopped
    depends_on:
      - homeassistant
      - mosquitto
    ports:
      - "1880:1880"
    environment:
      TZ: America/Toronto
    volumes:
      - ./nodered/data:/data

  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
      DOCKER_INFLUXDB_INIT_ORG: smart-home
      DOCKER_INFLUXDB_INIT_BUCKET: sensors
    volumes:
      - ./influxdb/data:/var/lib/influxdb2
      - ./influxdb/config:/etc/influxdb2

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

volumes:
  homeassistant_config:
  mosquitto_data:
  zigbee2mqtt_data:
  nodered_data:
  influxdb_data:
  grafana_data: