services:
  home-assistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: home-assistant
    restart: unless-stopped
    network_mode: host
    privileged: true
    environment:
      TZ: America/Toronto
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    healthcheck:
      test:
        - CMD
        - curl
        - --fail
        - http://localhost:8123/
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s

  mosquitto:
    image: eclipse-mosquitto:2
    container_name: mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883"
    volumes:
      - ./mosquitto/config:/mosquitto/config:ro
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log
    healthcheck:
      test:
        - CMD
        - mosquitto_sub
        - -h
        - localhost
        - -t
        - healthcheck
        - -C
        - "1"
        - -W
        - "3"
      interval: 30s
      timeout: 5s
      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
    volumes:
      - ./zigbee2mqtt:/app/data
      - /run/udev:/run/udev:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0

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

networks:
  default:
    name: home-automation
    driver: bridge