# Home Assistant Full Stack

> Home Assistant with MQTT, InfluxDB, and Grafana for home automation.

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

## Overview

Home Assistant is an open-source home automation platform that puts local control and privacy first, integrating with over 2000 devices and services to create a unified smart home experience. Originally created in 2013 by Paulus Schoutsen, Home Assistant has grown into the most popular self-hosted home automation solution, emphasizing local processing and user privacy over cloud-dependent alternatives. This full stack combines Home Assistant with three essential data infrastructure components: Mosquitto MQTT broker for device communication, InfluxDB for time-series sensor data storage, and Grafana for advanced visualization and monitoring dashboards. Together, these components create a complete IoT data pipeline where MQTT handles real-time device messaging, InfluxDB stores historical sensor readings with high performance, and Grafana transforms raw data into actionable insights through customizable dashboards. This stack is ideal for serious smart home enthusiasts, IoT developers, and privacy-conscious users who want complete control over their home automation data. The combination provides enterprise-grade monitoring capabilities for residential use, enabling trend analysis, energy monitoring, predictive maintenance, and sophisticated automation rules based on historical patterns rather than just current sensor states.

## Features

- 2000+ device integrations including Zigbee, Z-Wave, WiFi, and proprietary protocols
- High-performance time-series data storage with InfluxDB's purpose-built architecture
- MQTT broker supporting both device communication and Home Assistant's internal messaging
- 50+ Grafana data source plugins with rich visualization options for IoT dashboards
- Local control and privacy with all data processing happening on-premises
- Flux query language for complex time-series analysis and data correlations
- Home Assistant's automation engine with state-based and time-based triggers
- Energy management and monitoring with historical usage tracking and cost analysis

## Use cases

- Comprehensive smart home monitoring with historical energy usage and environmental data analysis
- IoT sensor network management for greenhouse automation, aquaponics, or hydroponic systems
- Home security system with motion detection, door sensors, and camera integration with data retention
- HVAC optimization using historical temperature patterns and occupancy data for automated scheduling
- Solar panel and battery monitoring with production forecasting and grid tie-in management
- Multi-property management for landlords monitoring multiple rental units remotely
- Home lab environment monitoring tracking server temperatures, power consumption, and network performance

## Prerequisites

- Minimum 2GB RAM recommended for Home Assistant plus additional 1GB for InfluxDB and Grafana
- Docker host with network access to smart home devices (may require host networking mode)
- Available ports 8123 (Home Assistant), 1883 (MQTT), 3000 (Grafana), and 8086 (InfluxDB)
- Basic understanding of YAML configuration for Home Assistant device setup and automation rules
- Knowledge of time-series data concepts and InfluxDB bucket/retention policy configuration
- Familiarity with Grafana dashboard creation and InfluxDB data source configuration

## docker-compose.yml

```yaml
services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: homeassistant
    restart: unless-stopped
    privileged: true
    network_mode: host
    volumes:
      - ha_config:/config
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - mosquitto
      - influxdb

  mosquitto:
    image: eclipse-mosquitto:latest
    container_name: mosquitto
    restart: unless-stopped
    ports:
      - "${MQTT_PORT:-1883}:1883"
      - "9001:9001"
    volumes:
      - mosquitto_data:/mosquitto/data
    networks:
      - ha-network

  influxdb:
    image: influxdb:2.7
    container_name: influxdb
    restart: unless-stopped
    ports:
      - "${INFLUX_PORT:-8086}:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUX_USER:-admin}
      - DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUX_PASSWORD:-adminpassword}
      - DOCKER_INFLUXDB_INIT_ORG=${INFLUX_ORG:-home}
      - DOCKER_INFLUXDB_INIT_BUCKET=${INFLUX_BUCKET:-homeassistant}
    volumes:
      - influxdb_data:/var/lib/influxdb2
    networks:
      - ha-network

  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
    networks:
      - ha-network

volumes:
  ha_config:
  mosquitto_data:
  influxdb_data:
  grafana_data:

networks:
  ha-network:
    driver: bridge
```

## .env

```bash
# Home Assistant Full Stack
MQTT_PORT=1883
INFLUX_PORT=8086
INFLUX_USER=admin
INFLUX_PASSWORD=adminpassword
INFLUX_ORG=home
INFLUX_BUCKET=homeassistant
GRAFANA_PORT=3000
GRAFANA_PASSWORD=admin
```

## Usage notes

- Home Assistant at http://localhost:8123
- Grafana at http://localhost:3000
- InfluxDB at http://localhost:8086
- Configure HA to send data to InfluxDB

## Troubleshooting

- Home Assistant shows 'Unable to connect to MQTT broker': Verify mosquitto container is running and MQTT integration uses correct broker IP address
- InfluxDB connection fails with 'unauthorized access': Check DOCKER_INFLUXDB_INIT_USERNAME and password match Home Assistant InfluxDB integration credentials
- Grafana shows 'InfluxDB connection error': Ensure InfluxDB data source URL uses container name 'influxdb:8086' and correct authentication token
- Home Assistant devices not discovered: Run container in privileged mode with network_mode: host for proper device discovery
- MQTT devices not responding: Check firewall rules allow port 1883 and verify MQTT device broker configuration points to correct IP
- Grafana dashboards empty despite InfluxDB data: Verify Home Assistant InfluxDB integration includes desired entities and measurement names match Grafana queries

