MQTT is the glue that holds serious smart home setups together. It lets your Zigbee devices, custom sensors, cameras, and automations all talk through one fast, local protocol. Here is how to set it up and use it properly.
Jump to a section
Think of MQTT as a postal system for your smart home. Devices send messages to a central broker, and other devices subscribe to receive them. It is lightweight, fast, and runs entirely on your local network. No cloud, no lag, no monthly fees.
MQTT messages typically arrive in under 10 milliseconds on a local network. When a motion sensor fires, your lights respond instantly. No round-trip to some server in another country.
Zigbee2MQTT, Tasmota, ESPHome, Frigate, room-assistant, OwnTracks. Dozens of popular tools use MQTT to talk to Home Assistant. Set it up once and everything just connects.
MQTT was designed for constrained devices and unreliable networks. The Mosquitto broker uses about 10MB of RAM. It runs happily on a Raspberry Pi alongside Home Assistant without breaking a sweat.
1. Publish
A device sends a message to a topic. For example, a temperature sensor publishes home/bedroom/temperature with the value 21.5.
2. Broker
The MQTT broker (Mosquitto) receives the message and routes it to anyone who has subscribed to that topic. It is the central hub that all messages flow through.
3. Subscribe
Home Assistant subscribes to topics it cares about. When a new temperature reading arrives, HA instantly updates the entity and can trigger automations based on the value.
Not every Home Assistant setup needs MQTT. Here is when it becomes essential versus when you can skip it.
That said, installing Mosquitto takes five minutes and costs nothing. Having it ready makes future expansions much easier.
The whole process takes about 10 minutes. If you are running Home Assistant OS or Supervised, you get the easiest path with the official add-on.
Go to Settings โ Add-ons โ Add-on Store. Search for "Mosquitto broker" and click Install. This is the official add-on maintained by the Home Assistant team.
After installation, toggle Start on boot and Watchdog (auto-restart if it crashes). Then hit Start.
Go to Settings โ People โ Users and create a dedicated user for MQTT. Name it something like "mqtt" or "mqtt-user". Use a strong password.
The Mosquitto add-on automatically picks up Home Assistant user accounts for authentication. Any HA user can connect to MQTT with their credentials. Creating a dedicated user keeps things clean and makes it easier to track what is connecting.
Go to Settings โ Devices & Services โ Add Integration. Search for "MQTT" and select it. Home Assistant should auto-detect the running Mosquitto broker. Click Submit and you are done.
If auto-detection does not work, enter the broker address manually: localhost or core-mosquitto, port 1883, and the username/password you created.
Go to Developer Tools โ MQTT (or Settings โ Devices & Services โ MQTT โ Configure). You will see a "Listen to a topic" section. Subscribe to # (the wildcard that matches everything) and you should see messages flowing in.
You can also publish a test message. Set topic to test/hello and payload to Hello MQTT!. If it shows up in your subscription, everything is working.
You will not have the add-on store available. Instead, run Mosquitto as a separate Docker container:
docker run -d \
--name mosquitto \
--restart unless-stopped \
-p 1883:1883 \
-v /opt/mosquitto/config:/mosquitto/config \
-v /opt/mosquitto/data:/mosquitto/data \
-v /opt/mosquitto/log:/mosquitto/log \
eclipse-mosquitto:2 Create a config file at /opt/mosquitto/config/mosquitto.conf with your listener and authentication settings. Then add the MQTT integration in Home Assistant pointing to your Docker host IP.
Topics are like addresses for messages. Understanding how they work is the key to getting the most out of MQTT.
Topics use forward slashes to create a hierarchy, similar to file paths. A typical smart home setup might look like this:
home/living-room/temperature โ 22.3
home/living-room/humidity โ 45
home/bedroom/light/state โ ON
home/bedroom/light/brightness โ 80
zigbee2mqtt/motion-sensor/occupancy โ true
frigate/events โ {"type": "person", "camera": "front"}MQTT supports two wildcards for subscribing to multiple topics at once:
+ matches one level: home/+/temperature gets temperature from every room# matches everything below: home/# gets all messages from all rooms and devicesTwo features that matter for smart home use:
These are the most common reasons people set up MQTT in Home Assistant. Each tool uses MQTT to send device data and receive commands.
The #1 reason people install MQTT
Zigbee2MQTT bridges your Zigbee devices to Home Assistant through MQTT. It supports over 4,000 devices, gives you more control than ZHA, and publishes all device data as clean MQTT topics. Install it as a Home Assistant add-on and point it at your Mosquitto broker.
Read our Zigbee guide โFree your cheap Wi-Fi devices
Tasmota is open-source firmware you can flash onto many ESP8266/ESP32-based Wi-Fi devices. Sonoff switches, smart plugs, bulbs, power monitors. Once flashed, they communicate through MQTT instead of some random cloud server in China. Full local control, no app required.
Custom sensors and devices
ESPHome can use either its native API or MQTT to communicate with Home Assistant. The native API is simpler for most cases, but MQTT mode is useful when you want multiple systems to read the same sensor data, or when your ESP device is on a different network segment.
Read our ESPHome guide โAI camera events via MQTT
Frigate is an AI-powered network video recorder that runs object detection on your security cameras locally. It uses MQTT to publish detection events (person detected, car in driveway, package at door). You can build powerful automations that react to what your cameras actually see.
Read our camera guide โPrivacy-focused location tracking
OwnTracks is a free phone app that shares your location over MQTT. Unlike Google or Apple location sharing, your data goes directly to your own Mosquitto broker. Perfect for presence-based automations like "turn on the heater when I am 10 minutes from home."
Know which room you are in
Tools like room-assistant, ESPresense, and Bermuda use Bluetooth beacons and ESP32 boards to detect which room you are in. They publish room-level presence data over MQTT. This lets you build automations like "follow me" lighting that lights up whatever room you walk into.
Once MQTT is running, you can trigger automations directly from MQTT messages. Here are practical examples you can use right away.
When Frigate detects a person on your front camera, send a notification with a snapshot:
automation:
- alias: "Front door person alert"
trigger:
- platform: mqtt
topic: "frigate/events"
value_template: "{{ value_json.type }}"
payload: "new"
condition:
- "{{ trigger.payload_json.after.label == 'person' }}"
- "{{ trigger.payload_json.after.camera == 'front_door' }}"
action:
- service: notify.mobile_app
data:
title: "Someone at the front door"
message: "Person detected at {{ now().strftime('%H:%M') }}"Using ESPresense or room-assistant BLE presence, turn lights on when you enter a room:
automation:
- alias: "Follow-me lights kitchen"
trigger:
- platform: mqtt
topic: "espresense/rooms/kitchen/your_phone"
condition:
- "{{ trigger.payload_json.distance | float < 3 }}"
- condition: state
entity_id: sun.sun
state: "below_horizon"
action:
- service: light.turn_on
target:
entity_id: light.kitchen
data:
brightness_pct: 80React to Zigbee2MQTT button presses with different actions for single, double, and long press:
automation:
- alias: "Bedside button controls"
trigger:
- platform: mqtt
topic: "zigbee2mqtt/bedside_button/action"
action:
- choose:
- conditions: "{{ trigger.payload == 'single' }}"
sequence:
- service: light.toggle
entity_id: light.bedroom
- conditions: "{{ trigger.payload == 'double' }}"
sequence:
- service: scene.turn_on
entity_id: scene.bedroom_night
- conditions: "{{ trigger.payload == 'hold' }}"
sequence:
- service: light.turn_off
entity_id: allGet notified when your washing machine finishes its cycle based on power consumption:
automation:
- alias: "Washing machine done"
trigger:
- platform: mqtt
topic: "tele/washing_plug/SENSOR"
condition:
- "{{ trigger.payload_json.ENERGY.Power | float < 5 }}"
- condition: state
entity_id: input_boolean.washing_running
state: "on"
action:
- service: notify.mobile_app
data:
title: "Laundry done! ๐งบ"
message: "Your washing machine has finished."
- service: input_boolean.turn_off
entity_id: input_boolean.washing_runningSend data from Home Assistant to other systems like Node-RED, Grafana, or custom scripts:
automation:
- alias: "Publish daily energy summary"
trigger:
- platform: time
at: "23:59:00"
action:
- service: mqtt.publish
data:
topic: "home/energy/daily_summary"
payload_template: >
{"date": "{{ now().strftime('%Y-%m-%d') }}",
"total_kwh": {{ states('sensor.daily_energy') }},
"cost": {{ (states('sensor.daily_energy') | float * 0.25) | round(2) }}
}
retain: trueThe default settings work fine for most people. But here are tweaks that make Mosquitto more useful for larger setups.
By default, the HA add-on enables persistence, which saves retained messages to disk. This means your device states survive broker restarts. If you are running Mosquitto manually, add this to your config:
persistence true
persistence_location /mosquitto/data/When debugging, enable verbose logging to see all messages flowing through the broker. In the add-on configuration, set the log level to "debug". Remember to set it back to "warning" after, as debug logging can fill up your disk.
If you want to use MQTT from a web browser (for custom dashboards or debugging tools), enable the WebSocket listener. The HA add-on exposes port 1884 for WebSocket connections by default. For manual installs:
listener 1883
protocol mqtt
listener 1884
protocol websocketsMQTT is generally rock solid, but here are the most common issues people run into and how to fix them.
core-mosquitto for the HA add-on, or your server IP for external installshomeassistant/max_inflight_messages setting for better throughputThese tools make debugging and monitoring MQTT traffic much easier.
The best desktop app for inspecting your MQTT broker. Shows all topics in a tree view, lets you publish test messages, monitor traffic in real-time, and delete retained messages. Free and open source. Available for Windows, Mac, and Linux.
Command-line tools that come with Mosquitto. Quick way to subscribe to topics or publish messages for testing. Install with apt install mosquitto-clients on Linux.
Built right into Home Assistant. Go to Developer Tools โ MQTT to subscribe to topics, publish messages, and test your configuration without installing anything extra.
| Feature | MQTT | REST API | WebSocket |
|---|---|---|---|
| Speed | Very fast (<10ms) | Moderate | Fast |
| Bandwidth | Minimal (2 byte header) | Higher (HTTP headers) | Low after handshake |
| Pub/Sub model | โ Built-in | โ Request/response | โ ๏ธ Manual |
| Offline queuing | โ QoS + retained | โ Lost | โ Lost |
| IoT suitability | โญ Purpose-built | OK for simple | OK for dashboards |
Not sure if your current devices support MQTT? Run our free compatibility scan and find out which of your devices can connect to Home Assistant, through MQTT or native integrations.
Scan Your Devices FreeTakes 2 minutes. No sign-up required.
MQTT stands for Message Queuing Telemetry Transport. It is a lightweight messaging protocol designed for IoT devices. In Home Assistant, MQTT acts as a universal translator that lets different devices and services talk to each other through a central broker. It is fast, reliable, uses minimal bandwidth, and works entirely on your local network. Many popular smart home tools like Zigbee2MQTT, ESPHome, Tasmota, and Frigate use MQTT to communicate with Home Assistant.
Not necessarily. Home Assistant has native integrations for many devices. But MQTT becomes essential when you use tools like Zigbee2MQTT, Tasmota, Frigate, or room-level presence detection. If you plan to do any of these things, setting up MQTT early saves you time later.
Mosquitto is the standard choice and the one recommended by the Home Assistant team. It is open source, lightweight, and available as an official Home Assistant add-on. Install it from the add-on store and you are up and running in minutes.
Go to Settings, then Add-ons, then Add-on Store. Search for Mosquitto broker and click Install. After installation, start the broker, then go to Settings, Devices and Services, and add the MQTT integration. Home Assistant will auto-detect the running Mosquitto broker. The whole process takes about five minutes.
Yes, when configured properly. Mosquitto supports username and password authentication, TLS encryption, and access control lists. The Home Assistant add-on sets up authentication automatically using your HA user accounts. For local-only setups behind a firewall, the default configuration is already secure.
Yes, through Zigbee2MQTT. This tool reads Zigbee signals from a USB coordinator and translates them into MQTT messages. It supports over 4,000 devices and is one of the two main ways to connect Zigbee devices to Home Assistant (the other being ZHA, which does not use MQTT).
They solve different problems. Zigbee is a wireless radio protocol that lets devices communicate without Wi-Fi. MQTT is a messaging protocol that runs over your network (Wi-Fi or Ethernet). Tools like Zigbee2MQTT bridge these two worlds by reading Zigbee radio signals and publishing them as MQTT messages that Home Assistant can understand.