A two-container stack for home automation and security camera integration
This is the advanced companion to our beginner Home Assistant guide. If you just want Home Assistant up and running, start there. This guide is for when you are ready to add an MQTT broker and connect Frigate NVR for camera-based object detection and recording.
This guide covers the Home Assistant side of the setup. For installing Frigate NVR on a separate server, see our Self-Hosted Frigate NVR with Docker guide.
What This Setup Includes
- Home Assistant - Smart home hub running in Docker with host networking
- Eclipse Mosquitto - MQTT broker for communication between Home Assistant and Frigate
- HACS - Home Assistant Community Store for installing the Frigate integration
Both containers are managed by a single Docker Compose file. Home Assistant uses host networking for device discovery, and Mosquitto runs on bridge networking with port 1883 published.
Architecture
+------------------------------------------+
| Home Assistant Server |
| |
| +----------------+ +----------------+ |
| | Home | | Mosquitto | |
| | Assistant | | MQTT Broker | |
| | :8123 (host) | | :1883 (bridge) | |
| +----------------+ +----------------+ |
| | |
+-----------------------------+------------+
|
| MQTT (1883)
v
+------------------------------------------+
| Frigate Server (separate machine) |
| |
| +------------------------------------+ |
| | Frigate NVR :8971 HTTPS | |
| +------------------------------------+ |
+------------------------------------------+
Home Assistant and Mosquitto run on the same server. Frigate runs on a separate server and connects to Mosquitto over your LAN. When Frigate detects objects on your cameras, it publishes events to MQTT, and Home Assistant picks them up for automations and notifications.
Prerequisites
Server Requirements
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 2 vCPUs | 2+ vCPUs |
| RAM | 2 GB | 4 GB |
| Disk | 20 GB | 50 GB |
| OS | Ubuntu 24.04 LTS Server (or similar) | |
You need Docker installed. If you need Docker installation steps, see our beginner Home Assistant guide or the official Docker docs.
Network Requirements
- A static IP for this server
- Port 8123 (Home Assistant web UI) available on your LAN
- Port 1883 (MQTT) available on your LAN so Frigate can connect
Throughout this guide, example IPs use 192.168.1.50 for the Home Assistant server and 192.168.1.100 for the Frigate server. Replace with your actual values.
Step 1: Create Directory Structure
mkdir -p ~/homeassistant/config
mkdir -p ~/homeassistant/mosquitto/config
mkdir -p ~/homeassistant/mosquitto/data
mkdir -p ~/homeassistant/mosquitto/log
The layout:
~/homeassistant/
+-- docker-compose.yml
+-- config/ # Home Assistant configuration
| +-- configuration.yaml # (auto-generated on first run)
+-- mosquitto/
+-- config/
| +-- mosquitto.conf # Mosquitto configuration
+-- data/ # Persistent MQTT data
+-- log/ # Mosquitto logs
Step 2: Configure Mosquitto
nano ~/homeassistant/mosquitto/config/mosquitto.conf
Add:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
Save and exit.
What These Settings Do
listener 1883- Listens on the standard MQTT portallow_anonymous true- No authentication required (secured by firewall to your LAN only)persistence true- Retains messages across restarts
Anonymous MQTT access is acceptable here because the broker is firewalled to your local network only. If you later need to expose MQTT beyond your LAN or want defense-in-depth, add authentication:
# In mosquitto.conf:
allow_anonymous false
password_file /mosquitto/config/passwd
# Generate the password file:
# docker exec -it mosquitto mosquitto_passwd -c /mosquitto/config/passwd YOUR_USERNAME
Step 3: Create Docker Compose File
nano ~/homeassistant/docker-compose.yml
Paste the following:
services:
homeassistant:
container_name: homeassistant
image: ghcr.io/home-assistant/home-assistant:stable
volumes:
- ./config:/config
- /run/dbus:/run/dbus:ro
environment:
- TZ=YOUR_TIMEZONE
restart: unless-stopped
privileged: true
network_mode: host
depends_on:
- mosquitto
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto:2
volumes:
- ./mosquitto/config:/mosquitto/config
- ./mosquitto/data:/mosquitto/data
- ./mosquitto/log:/mosquitto/log
environment:
- TZ=YOUR_TIMEZONE
restart: unless-stopped
ports:
- "1883:1883"
Replace YOUR_TIMEZONE with your timezone (e.g., America/New_York, America/Chicago, Europe/London). Save and exit.
What These Settings Do
network_mode: host- Home Assistant shares the host network stack. Required for mDNS discovery, Bluetooth, and other local protocols. UFW rules apply normally.privileged: true- Required for Home Assistant to access host devices/run/dbus:/run/dbus:ro- D-Bus access for Bluetooth integrationdepends_on: mosquitto- Ensures the MQTT broker starts before Home Assistantrestart: unless-stopped- Both containers auto-restart on reboot or crash
Because Home Assistant uses network_mode: host, its traffic passes through the host's network stack and UFW rules apply normally. Mosquitto uses bridge networking with explicit port publishing, so Docker handles its port mapping via iptables.
Step 4: Configure Firewall
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp comment 'SSH from LAN'
sudo ufw allow from 192.168.1.0/24 to any port 8123 proto tcp comment 'Home Assistant Web UI from LAN'
sudo ufw allow from 192.168.1.0/24 to any port 1883 proto tcp comment 'MQTT broker from LAN'
sudo ufw enable
Replace 192.168.1.0/24 with your LAN subnet. Type y to confirm.
Verify:
sudo ufw status verbose
Port 1883 must be open so the Frigate server on the other machine can connect to the MQTT broker.
Step 5: Start the Stack
cd ~/homeassistant
docker compose up -d
Wait 2-3 minutes for Home Assistant to initialize on first startup.
Verify Containers
docker ps
You should see two containers: homeassistant and mosquitto, both with status Up.
Access Home Assistant
http://YOUR_SERVER_IP:8123
Complete the first-time setup wizard: create your admin account, set your location, and finish the onboarding.
Step 6: Install HACS
HACS (Home Assistant Community Store) is required to install the Frigate integration.
Install HACS Files
docker exec homeassistant bash -c "wget -O - https://get.hacs.xyz | bash -"
Restart Home Assistant to load HACS:
docker restart homeassistant
Wait 1-2 minutes for Home Assistant to come back up.
Activate HACS in the UI
- Open Home Assistant in your browser
- Navigate to Settings > Devices & Services
- Click + Add Integration
- Search for HACS
- Check all the acknowledgment boxes
- Click Submit
- Follow the GitHub authorization prompt when it appears
HACS will appear in the left sidebar after activation.
HACS requires a GitHub account (free) for authentication and to avoid API rate limits when downloading integrations. This is a HACS requirement, not a Home Assistant one.
Step 7: Add MQTT Integration
Connect Home Assistant to the Mosquitto broker running on the same server.
- Navigate to Settings > Devices & Services
- Click + Add Integration
- Search for MQTT
- Enter:
- Broker:
localhost - Port:
1883 - Username: (leave blank)
- Password: (leave blank)
- Broker:
- Click Submit
Verify it shows as connected with no errors.
Step 8: Install Frigate Integration
- Click HACS in the left sidebar
- Click + Explore & Download Repositories
- Search for Frigate
- Click on the Frigate integration and click Download
- Restart Home Assistant: Settings > System > Restart
- After restart, go to Settings > Devices & Services > + Add Integration
- Search for Frigate
- Enter the URL:
https://YOUR_FRIGATE_IP:8971 - Click Submit
Replace YOUR_FRIGATE_IP with the actual IP of your Frigate server.
After Completing All Steps
Once everything is connected:
- Home Assistant is connected to the MQTT broker on localhost:1883
- Home Assistant is connected to Frigate NVR via HTTPS
- Frigate cameras (once added to Frigate's config) will automatically appear as devices in Home Assistant
- Object detection events from Frigate will be available for automations and notifications
Managing the Stack
Service Commands
| Action | Command |
|---|---|
| Start all | cd ~/homeassistant && docker compose up -d |
| Stop all | cd ~/homeassistant && docker compose down |
| Restart HA | docker compose restart homeassistant |
| Restart Mosquitto | docker compose restart mosquitto |
| HA logs | docker logs -f homeassistant |
| Mosquitto logs | docker logs -f mosquitto |
| Status | docker ps |
Updating Services
# Update everything
cd ~/homeassistant
docker compose pull
docker compose up -d
# Clean up old images
docker image prune -f
Troubleshooting
Home Assistant Will Not Start
docker logs homeassistant --tail 50
Mosquitto Will Not Start
docker logs mosquitto --tail 50
Also check the log file directly:
cat ~/homeassistant/mosquitto/log/mosquitto.log
MQTT Connectivity Test
sudo apt-get install -y mosquitto-clients
# Terminal 1 - subscribe
mosquitto_sub -h localhost -t "test/topic"
# Terminal 2 - publish
mosquitto_pub -h localhost -t "test/topic" -m "hello"
If the subscriber receives "hello", MQTT is working.
Frigate Cannot Connect to MQTT
- Verify Mosquitto is running:
docker ps --filter name=mosquitto - Verify UFW allows port 1883 from your LAN:
sudo ufw status - Test from the Frigate server:
mosquitto_sub -h YOUR_HA_IP -t "frigate/#" -v
Container Uses Too Much Memory
docker stats --no-stream