# Complete Home Automation Stack

> Home Assistant with Node-RED automation, InfluxDB metrics, Grafana dashboards, and Mosquitto MQTT

- Category: Home Lab & Self-Hosting
- Difficulty: intermediate
- Components: home-assistant, node-red, influxdb, grafana, mosquitto
- Tags: home-assistant, node-red, influxdb, grafana, mqtt, iot, automation
- Source: https://docker.recipes/homelab/complete-home-automation

## Overview

Home Assistant is an open-source home automation platform that puts local control and privacy first, integrating with over 2000 different devices and services to create a unified smart home experience. Originally created by Paulus Schoutsen in 2013, it has grown into the most comprehensive home automation solution available, supporting everything from simple light switches to complex climate systems, security cameras, and energy monitoring devices.

This complete automation stack combines Home Assistant's central hub capabilities with Node-RED's visual automation flows, InfluxDB's time-series data storage, Grafana's analytical dashboards, and Mosquitto's MQTT message broker to create a comprehensive IoT ecosystem. The stack enables you to not only control devices but also collect historical data, create complex automations through visual programming, and gain insights through professional monitoring dashboards. Zigbee2MQTT adds direct Zigbee device support without requiring proprietary hubs.

This configuration is ideal for serious home automation enthusiasts, IoT developers, and homelab operators who want complete control over their smart home infrastructure while maintaining data privacy and local operation. Unlike cloud-based solutions like SmartThings or commercial platforms, this stack keeps all data processing local while providing enterprise-grade monitoring and automation capabilities typically found in industrial IoT deployments.

## Features

- 2000+ device integrations including Philips Hue, Nest, Sonos, and major IoT protocols
- Visual flow-based automation programming through Node-RED's drag-and-drop interface
- Time-series sensor data storage with InfluxDB's high-performance write capabilities
- Professional monitoring dashboards with Grafana's 50+ visualization types
- Direct Zigbee device control without proprietary hubs via Zigbee2MQTT
- MQTT message broker for reliable IoT device communication
- Energy monitoring and solar panel integration for sustainability tracking
- Voice assistant support for Alexa, Google Assistant, and local wake word detection

## Use cases

- Complete smart home automation with heating, lighting, security, and entertainment systems
- Energy monitoring and solar panel optimization with historical usage analytics
- IoT sensor data collection for greenhouse, aquarium, or workshop monitoring
- Home security system with camera integration, motion detection, and mobile alerts
- Multi-protocol device integration combining WiFi, Zigbee, Z-Wave, and Bluetooth devices
- Rental property monitoring with tenant-friendly automation and remote management
- Small business or retail automation for lighting, HVAC, and occupancy sensing

## Prerequisites

- Docker host with minimum 4GB RAM (8GB recommended for full stack operation)
- Available ports 8123, 1880, 3000, 8080, 8086, 1883, and 9001 on the host system
- USB Zigbee coordinator device (like ConBee II or Sonoff Zigbee) for device integration
- Basic understanding of YAML configuration and MQTT messaging concepts
- Network access to IoT devices or ability to configure device discovery protocols
- Storage space for time-series data (plan for 1-10GB depending on sensor count and retention)

## docker-compose.yml

```yaml
services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: homeassistant
    restart: unless-stopped
    network_mode: host
    volumes:
      - ./homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=${TZ:-UTC}

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

  node-red:
    image: nodered/node-red:latest
    container_name: node-red
    restart: unless-stopped
    ports:
      - "${NODERED_PORT:-1880}:1880"
    volumes:
      - node_red_data:/data
    environment:
      - TZ=${TZ:-UTC}

  influxdb:
    image: influxdb:2.7
    container_name: influxdb
    restart: unless-stopped
    ports:
      - "${INFLUXDB_PORT:-8086}:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUX_USER}
      - DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUX_PASSWORD}
      - DOCKER_INFLUXDB_INIT_ORG=home
      - DOCKER_INFLUXDB_INIT_BUCKET=homeassistant
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUX_TOKEN}
    volumes:
      - influxdb_data:/var/lib/influxdb2

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    ports:
      - "${GRAFANA_PORT:-3000}:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
    volumes:
      - grafana_data:/var/lib/grafana
    depends_on:
      - influxdb

  zigbee2mqtt:
    image: koenkk/zigbee2mqtt:latest
    container_name: zigbee2mqtt
    restart: unless-stopped
    ports:
      - "${Z2M_PORT:-8080}:8080"
    volumes:
      - ./zigbee2mqtt/data:/app/data
      - /run/udev:/run/udev:ro
    environment:
      - TZ=${TZ:-UTC}
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    depends_on:
      - mosquitto

volumes:
  node_red_data:
  influxdb_data:
  grafana_data:
```

## .env

```bash
# Complete Home Automation Stack
NODERED_PORT=1880
INFLUXDB_PORT=8086
GRAFANA_PORT=3000
Z2M_PORT=8080
TZ=America/New_York

# InfluxDB
INFLUX_USER=admin
INFLUX_PASSWORD=adminpassword
INFLUX_TOKEN=your-influxdb-token

# Grafana
GRAFANA_PASSWORD=admin
```

## Usage notes

- Home Assistant at http://localhost:8123 (network_mode: host)
- Node-RED at http://localhost:1880
- Grafana at http://localhost:3000
- Zigbee2MQTT at http://localhost:8080
- Configure HA to send data to InfluxDB
- Create mosquitto.conf with listener settings

## Troubleshooting

- Home Assistant 'Recorder database is corrupt': Stop container, delete home-assistant.db from config volume, restart to rebuild database from scratch
- Zigbee2MQTT 'Error: No such file or directory: /dev/ttyUSB0': Check USB device path with 'ls /dev/tty*' and update device mapping in compose file
- InfluxDB connection refused from Grafana: Verify INFLUX_TOKEN environment variable matches between services and check InfluxDB initialization logs
- Node-RED flows not triggering Home Assistant: Ensure Home Assistant Node-RED addon or companion nodes are installed and HA long-lived access token is configured
- Mosquitto MQTT authentication failures: Create mosquitto.conf with 'allow_anonymous true' for testing, then implement proper authentication with password file
- Grafana shows no data sources: Configure InfluxDB data source with proper URL 'http://influxdb:8086', organization 'home', and valid authentication token

