# Frigate + Home Assistant + MQTT

> Complete smart home surveillance stack with AI-powered NVR, home automation, and MQTT broker for seamless integration.

- Category: Home Lab & Self-Hosting
- Difficulty: advanced
- Components: frigate, home-assistant, mosquitto, mqtt
- Tags: frigate, home-assistant, mqtt, mosquitto, nvr, smart-home, automation, surveillance
- Source: https://docker.recipes/homelab/frigate-home-assistant-mqtt

## Overview

Frigate is an open-source Network Video Recorder (NVR) built specifically for real-time AI object detection on IP cameras. Unlike traditional surveillance systems that simply record footage, Frigate uses machine learning models to intelligently detect people, vehicles, and other objects in real-time, drastically reducing false alerts from shadows, rain, or swaying trees. It leverages hardware acceleration through Google Coral TPUs, Intel QuickSync, or NVIDIA GPUs to perform efficient AI inference without overwhelming your system resources. This surveillance stack combines Frigate's intelligent video analysis with Home Assistant's powerful automation engine and Mosquitto's lightweight MQTT messaging. Frigate publishes detection events to MQTT topics that Home Assistant consumes, enabling sophisticated automation workflows like sending notifications when a person is detected at your front door, turning on lights when motion is detected at night, or recording clips only when specific objects are identified. The MQTT broker acts as the central nervous system, ensuring reliable message delivery between Frigate's AI detections and Home Assistant's automation responses. This configuration is ideal for privacy-conscious homeowners who want professional-grade surveillance without cloud dependencies, smart home enthusiasts building comprehensive automation systems, and security-focused users who need intelligent video analytics with local processing. The combination provides enterprise-level surveillance capabilities while maintaining complete local control over your video feeds and detection data.

## Features

- Real-time AI object detection with configurable zones and object filters
- Hardware acceleration support for Google Coral TPU, Intel QuickSync, and NVIDIA GPU
- MQTT-based event publishing for instant Home Assistant automation triggers
- Frigate integration in Home Assistant for camera feeds, clips, and detection management
- Intelligent recording that saves storage by capturing only relevant events
- Web-based dashboard with live camera feeds and detection timeline
- RTSP re-streaming for accessing camera feeds from multiple clients
- Home Assistant automation engine with 2000+ device integrations for complex workflows

## Use cases

- Home security system with AI-powered person and vehicle detection at entry points
- Smart doorbell replacement using existing IP cameras with Home Assistant notifications
- Automated lighting and security responses based on intelligent motion detection
- Pet monitoring with automated feeding schedules triggered by animal detection
- Business surveillance with after-hours alerts and automated security responses
- Privacy-focused family monitoring without cloud storage or third-party services
- Integration with existing smart home devices for comprehensive automation workflows

## Prerequisites

- Minimum 2GB RAM for Home Assistant and Frigate AI processing (4GB+ recommended)
- IP cameras with RTSP stream support for Frigate video input
- Basic understanding of YAML configuration for Frigate camera setup
- Network access to camera RTSP streams from Docker host
- Optional: Google Coral TPU, Intel GPU, or NVIDIA GPU for hardware acceleration
- Understanding of MQTT topics and Home Assistant integration concepts

## docker-compose.yml

```yaml
services:
  # MQTT Broker - Central message hub
  mosquitto:
    image: eclipse-mosquitto:2
    container_name: mosquitto
    restart: unless-stopped
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log
    ports:
      - "1883:1883"
      - "9001:9001"
    command: mosquitto -c /mosquitto/config/mosquitto.conf

  # Frigate NVR - AI-powered camera system
  frigate:
    image: ghcr.io/blakeblackshear/frigate:stable
    container_name: frigate
    restart: unless-stopped
    privileged: true
    shm_size: 256mb
    depends_on:
      - mosquitto
    devices:
      - /dev/bus/usb:/dev/bus/usb  # USB Coral TPU (optional)
      # - /dev/dri/renderD128:/dev/dri/renderD128  # Intel GPU (optional)
    volumes:
      - ./frigate/config:/config
      - ./frigate/media:/media/frigate
      - type: tmpfs
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "5000:5000"   # Web UI
      - "8554:8554"   # RTSP feeds
      - "8555:8555/tcp"
      - "8555:8555/udp"
    environment:
      - FRIGATE_RTSP_PASSWORD=${RTSP_PASSWORD:-changeme}
      - FRIGATE_MQTT_HOST=mosquitto
      - FRIGATE_MQTT_PORT=1883
      - FRIGATE_MQTT_USER=${MQTT_USER:-}
      - FRIGATE_MQTT_PASSWORD=${MQTT_PASSWORD:-}

  # Home Assistant - Home automation platform
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: homeassistant
    restart: unless-stopped
    depends_on:
      - mosquitto
      - frigate
    volumes:
      - ./homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "8123:8123"
    environment:
      - TZ=${TZ:-UTC}

networks:
  default:
    driver: bridge
```

## .env

```bash
# Timezone
TZ=Europe/London

# MQTT Credentials (optional, for secured setup)
MQTT_USER=
MQTT_PASSWORD=

# Frigate RTSP Password
RTSP_PASSWORD=changeme

# ============================================
# SETUP INSTRUCTIONS
# ============================================

# 1. Create Mosquitto config:
# mkdir -p mosquitto/config mosquitto/data mosquitto/log
# cat > mosquitto/config/mosquitto.conf << 'EOF'
# listener 1883
# listener 9001
# protocol websockets
# allow_anonymous true
# persistence true
# persistence_location /mosquitto/data/
# log_dest file /mosquitto/log/mosquitto.log
# EOF

# 2. Create Frigate config:
# mkdir -p frigate/config frigate/media
# cat > frigate/config/config.yml << 'EOF'
# mqtt:
#   enabled: true
#   host: mosquitto
#   port: 1883
#   topic_prefix: frigate
#   client_id: frigate
#
# detectors:
#   cpu1:
#     type: cpu
#
# cameras:
#   front_door:
#     ffmpeg:
#       inputs:
#         - path: rtsp://user:pass@camera-ip:554/stream
#           roles:
#             - detect
#             - record
#     detect:
#       enabled: true
#       width: 1280
#       height: 720
#       fps: 5
#     record:
#       enabled: true
#       retain:
#         days: 7
#     snapshots:
#       enabled: true
#       retain:
#         default: 7
# EOF

# 3. In Home Assistant, add MQTT integration:
#    Settings > Devices & Services > Add Integration > MQTT
#    Broker: mosquitto (or the container IP)
#    Port: 1883

# 4. Install Frigate integration in HACS or manually:
#    Settings > Devices & Services > Add Integration > Frigate
#    URL: http://frigate:5000
```

## Usage notes

- Frigate UI at http://localhost:5000
- Home Assistant at http://localhost:8123
- MQTT broker at localhost:1883
- Create mosquitto/config/mosquitto.conf before starting
- Create frigate/config/config.yml with your cameras
- Add MQTT integration in Home Assistant for Frigate events
- Install Frigate integration in Home Assistant for full control
- Frigate sends motion/object events via MQTT to Home Assistant

## Troubleshooting

- Frigate shows 'Failed to connect to camera' errors: Verify RTSP URLs are accessible and credentials are correct in config.yml
- High CPU usage during AI detection: Enable hardware acceleration by uncommenting GPU device mappings or connecting Coral TPU
- Home Assistant not receiving Frigate events: Check MQTT broker connectivity and ensure Frigate MQTT settings match Mosquitto configuration
- Frigate web UI shows black camera feeds: Verify camera RTSP streams support the codecs specified in Frigate config
- Mosquitto connection refused errors: Ensure mosquitto.conf exists with proper listener configuration before container startup
- Home Assistant Frigate integration fails: Install HACS Frigate integration and configure with correct Frigate URL and MQTT settings

