Home Assistant · MQTT

MQTT for Home Assistant: Brokers, Discovery and the Rules That Matter

MQTT is the plumbing under a large share of a local smart home: Zigbee2MQTT, ESPHome devices on the fallback path, Tasmota gear and DIY sensors all meet at one broker. Home Assistant itself is just another client of that broker, which means the decisions that matter are broker decisions — which broker, which license, and how retained messages, quality of service and discovery actually behave. This guide makes those decisions with current facts: Mosquitto is on its 2.1 branch, and EMQX changed its license in 2025 in a way that changes what “free” means.

Published Nov 23, 2026

What the broker does

MQTT is a publish-and-subscribe protocol. Devices publish messages to named topics, such as a sensor publishing its temperature, and anything subscribed to that topic receives the message. The broker in the middle stores nothing long term except one retained message per topic, tracks who is connected, and delivers messages at the quality of service each side agreed. Home Assistant connects as a client: it subscribes to the topics of your devices and publishes commands back to them. That is why the broker keeps running even when Home Assistant restarts, and why Zigbee2MQTT needs the broker up before it starts.

Choosing a broker in 2026

BrokerVersion lineLicenseThe practical verdict
Eclipse Mosquitto2.1.x — 2.1.4 released alongside 2.0.23 in November 2026 as a security releaseEPL-2.0 / EDL — genuinely open sourceThe default recommendation for a home. Small, proven, and it is the broker inside the official Home Assistant app
EMQX6.3.x LTS; the 5.x line continues separatelyBusiness Source License 1.1 since 5.9.0 in May 2025 — source-available, not open sourceFree in production on a single node only. Clustering is a commercial feature. Capability overkill for one house

Mosquitto first. The official Mosquitto Broker app for Home Assistant is the easiest path on Home Assistant OS: setting up the MQTT integration can provision it automatically, Home Assistant generates broker credentials, and extra logins for devices are added in the app configuration. In a Docker or NAS stack, the same Mosquitto runs as a container beside Home Assistant — pin a 2.1.x image tag, persist the data and configuration volumes, and create a separate user per service. One beginner trap is worth naming: a stock Mosquitto 2.x refuses LAN clients until you configure a listener and either anonymous access or a password file, so a broker that “will not connect” is usually an unconfigured listener, not a broken install.

EMQX needs its license stated precisely, because older advice predates the change. From EMQX 5.9.0 in May 2025, the former open source and enterprise editions were merged into a single product under the Business Source License 1.1. Running one node in production is free under that license, and each release converts to Apache 2.0 four years after it is published — the last release published under Apache 2.0 itself was 5.8.9. Running a cluster of more than one node requires a commercial license. For a single home, a single-node EMQX is legal and free, and it brings a rule engine and dashboard that used to be enterprise features. What it no longer offers for free is the clustered high availability that was historically its reason to exist. Most Home Assistant users should run Mosquitto and spend their time elsewhere.

One hard requirement from the Home Assistant documentation decides edge cases: the broker must support MQTT protocol version 5. ActiveMQ and the RabbitMQ MQTT plugin are explicitly not supported, because of retention bugs. Any current Mosquitto or EMQX satisfies the version requirement.

Discovery: how devices appear by themselves

MQTT discovery is enabled by default, with homeassistant as the default discovery prefix. A device publishes a retained configuration payload to a topic shaped like homeassistant/<component>/<object_id>/config, and Home Assistant creates the device and its entities from that payload — no YAML and no restart. Zigbee2MQTT, ESPHome’s MQTT component, Tasmota and OpenMQTTGateway all use this pattern, which is why one broker serves every one of them.

Two details explain most discovery behavior. Home Assistant publishes its own status to homeassistant/status — “online” when it starts, “offline” when it stops — and well-behaved devices watch that birth message and resend their discovery payloads when Home Assistant comes back. The alternative is retaining the discovery payload at the broker, which restores devices instantly after a restart but has a shadow side covered below: a retained configuration for a device you deleted will resurrect it until the retained message is cleared. Manual MQTT entities still exist for cases discovery does not fit, defined in YAML under the mqtt: key or through the “Add MQTT device” subentries on the MQTT integration page.

Retained messages, QoS and Last Will

A retained message is the last message published on a topic with its retain flag set. The broker — not the publisher and not Home Assistant — stores exactly one per topic and hands it to every new subscriber immediately. Retention is why Home Assistant knows a switch’s state seconds after a restart, and it is also the cause of the classic ghost entity: to clear a stale retained message, publish an empty retained message to the same topic.

QoS levelMeaningWhere it fits at home
0At most once — fire and forget; a message can be lostFrequent sensor readings, where the next reading arrives in seconds anyway
1At least once — acknowledged, and a message can arrive twiceCommands and state changes you cannot afford to lose
2Exactly once — a four-step handshake, the slowest optionRarely worth it at home scale

End-to-end quality of service is the lower of the publish QoS and the subscription QoS, so QoS 2 on one side does not guarantee exactly-once delivery to Home Assistant — and Home Assistant’s own publish action defaults to QoS 0 unless you set the qos: and retain: options on the call. The third mechanism, Last Will and Testament, is the basis of device availability: a client registers a will message with the broker, and if the client drops ungracefully, the broker publishes that “offline” payload on its behalf. When you see an MQTT device flip to unavailable in Home Assistant, it is usually a will firing — or a device that never registered one being judged by a timeout instead.

Where the broker should live

Home Assistant OS users should take the Mosquitto app and stop thinking about it. Docker and NAS users should run the Mosquitto container in the same stack, with its own user for each client service, so Zigbee2MQTT and Home Assistant authenticate separately. Running the broker on a separate host is also legitimate and decouples broker restarts from Home Assistant restarts — Zigbee2MQTT only needs the broker reachable, not local. In every layout the ordering rule is the same: broker first, clients second. Zigbee2MQTT exits and retries without a broker, and a stack that starts everything at once sorts itself out only because the clients retry.

For the ESPHome tie-in, the native API remains the recommended path into Home Assistant, and MQTT is the fallback for other platforms. One ESPHome gotcha belongs in every MQTT guide: enabling MQTT without the API requires setting the reboot timeout to zero, or the device reboots every fifteen minutes when it cannot reach the API it is not using.

Official documentation and references

Frequently asked questions

Which MQTT broker should a Home Assistant user run?

Mosquitto, for almost everyone. It is genuinely open source under EPL-2.0 and EDL, the current branch is 2.1.x, and it is the broker inside the official Home Assistant Mosquitto Broker app. EMQX is a capable alternative on a single node, but since version 5.9.0 it is published under the Business Source License 1.1 rather than an open source license, and clustering requires a commercial license.

Does Home Assistant require the Mosquitto app?

No. Home Assistant is an MQTT client and works with any broker that supports MQTT version 5. The documentation names two exceptions that are not supported: ActiveMQ and the RabbitMQ MQTT plugin, both because of retention bugs. The Mosquitto app is simply the easiest path on Home Assistant OS.

Why does a deleted MQTT device keep coming back?

Its discovery configuration is probably retained at the broker. A retained config payload recreates the device every time Home Assistant subscribes. Publish an empty retained message to the device’s discovery config topic to clear it, and the device stays deleted.

What QoS should I use for sensors and switches?

QoS 0 is normal for frequent sensor readings and QoS 1 for commands and state changes that must not be lost. QoS 2 is rarely worth its overhead at home. Remember that the effective level is the lower of the publish and subscription settings, and Home Assistant’s publish action defaults to QoS 0.

Is EMQX open source?

Not since 5.9.0 in May 2025. Current EMQX releases are source-available under the Business Source License 1.1: free in production on a single node, commercial for clustering, and each release converts to Apache 2.0 four years after publication. Version 5.8.9 was the last release published under Apache 2.0.

Why will my devices not connect to a fresh Mosquitto container?

Mosquitto 2.x ships with a local-only listener and no anonymous access by default. Until you configure a listener for the network and either a password file or anonymous access, LAN clients are refused. That refusal is the secure default working as designed, not a broken broker.

Related guides