Setting Up a Mosquitto MQTT Broker for Home Assistant
MQTT is the lightweight messaging protocol sitting quietly underneath a huge amount of the smart home world - Zigbee2MQTT, Tasmota-flashed […]
Contents
- What a Broker Actually Does
- Installing Mosquitto as a Home Assistant Add-on
- Securing It Properly
- Connecting Home Assistant to the Broker
- MQTT Discovery: Why Devices Just Appear
- Checking It’s Actually Working
- Frequently Asked Questions
- Do I need Mosquitto if I’m only using Zigbee devices through a Zigbee coordinator dongle and ZHA?
- Is it safe to expose my MQTT broker outside my home network?
- What’s the difference between MQTT and Zigbee2MQTT?
MQTT is the lightweight messaging protocol sitting quietly underneath a huge amount of the smart home world - Zigbee2MQTT, Tasmota-flashed devices, ESPHome, and plenty of DIY sensor projects all speak it. But MQTT itself doesn’t do anything without a “broker” - the server that actually receives messages from devices and forwards them on to whoever’s subscribed, Home Assistant included. Mosquitto is the broker almost everyone ends up running, and setting it up properly (rather than leaving it wide open, which the default configuration effectively does) is worth doing right the first time.
What a Broker Actually Does
MQTT works on a publish/subscribe model rather than devices talking directly to each other. A device “publishes” a message to a named topic - a temperature sensor might publish to `home/livingroom/temperature` - and anything “subscribed” to that topic, or a matching wildcard, receives it instantly. The broker’s entire job is managing those subscriptions and routing messages between publishers and subscribers; it doesn’t process or interpret the data itself. Home Assistant subscribes to the topics your devices publish to, and can also publish commands back the other way (turning a Tasmota plug on, for instance, by publishing to its command topic) - the broker sits in the middle of all of it.
Installing Mosquitto as a Home Assistant Add-on
If you’re running Home Assistant OS or Supervised, this is by far the simplest route. From Settings > Add-ons > Add-on Store, search for “Mosquitto broker” (the official one, maintained by the Home Assistant team) and install it. Start it, and enable “Start on boot” and “Watchdog” in its Info tab so it comes back automatically after a restart or crash. The add-on integrates directly with Home Assistant’s own user system by default, meaning devices authenticate using Home Assistant login credentials rather than a separate set you have to manage - convenient for a single-user household, though for anything more security-conscious you’ll want dedicated MQTT-only credentials, covered below.
If you’re running Home Assistant Container or Core instead (no Supervisor, so no add-on store), you’ll run Mosquitto as its own separate service or Docker container alongside Home Assistant - the official `eclipse-mosquitto` Docker image is the standard choice, with a bind-mounted config file for the settings covered below.
Securing It Properly
A default Mosquitto install allows anonymous connections, meaning anything on your network can publish and subscribe to any topic with no credentials at all. On an isolated home network this is a lower-stakes risk than it sounds, but it’s still worth closing off, and takes only a few minutes. In the add-on’s Configuration tab (or your `mosquitto.conf` file if running it standalone), disable anonymous access and add at least one dedicated user:
logins:
- username: mqtt_user
password: a-genuinely-random-password
Then use those same credentials in the Home Assistant MQTT integration (Settings > Devices & Services > Add Integration > MQTT) and in every device or add-on that needs to connect - Zigbee2MQTT and ESPHome both have a straightforward broker username/password field in their own configuration.

Connecting Home Assistant to the Broker
With the Mosquitto add-on installed on the same machine, Home Assistant will usually auto-discover it and offer to configure the MQTT integration for you the first time you visit Settings > Devices & Services. If it doesn’t, add it manually - the broker address is `core-mosquitto` when both are running under Home Assistant Supervisor, or the specific IP address/hostname and port (1883 by default, unencrypted) if you’re running the broker as a standalone service elsewhere on your network.
MQTT Discovery: Why Devices Just Appear
Once the integration is set up, well-behaved MQTT devices and integrations (Zigbee2MQTT and ESPHome both do this properly by default) publish a special “discovery” message describing themselves - their name, what kind of entity they should appear as, and which topics to use - to a reserved `homeassistant/` topic prefix. Home Assistant listens on that prefix and creates the corresponding entity automatically, which is why a freshly paired Zigbee2MQTT device tends to show up in Home Assistant within seconds with no manual entity configuration at all. This is genuinely one of MQTT’s best features versus wiring up entities by hand, and it’s worth leaving discovery enabled (it’s on by default in both Zigbee2MQTT and the Home Assistant MQTT integration) rather than disabling it to “simplify” things.
Checking It’s Actually Working
Home Assistant’s own Developer Tools has a genuinely useful, often-overlooked page for this: Developer Tools > MQTT, where you can subscribe to a wildcard topic like `#` (meaning “everything”) and watch live messages flow through as devices publish. If you’ve just set up a new device and nothing’s appearing in Home Assistant, checking this page first tells you immediately whether the problem is “the device isn’t publishing at all” (a device-side networking or credentials issue) versus “it’s publishing but Home Assistant isn’t creating an entity from it” (usually a discovery configuration issue on the device or integration side) - a distinction that saves a lot of wasted troubleshooting time in the wrong place.
Frequently Asked Questions
Do I need Mosquitto if I’m only using Zigbee devices through a Zigbee coordinator dongle and ZHA?
No - Home Assistant’s built-in ZHA integration talks directly to a Zigbee coordinator without needing MQTT at all. Mosquitto only becomes necessary if you’re using Zigbee2MQTT specifically (which uses MQTT as its bridge to Home Assistant), or any other MQTT-based devices like Tasmota or ESPHome-flashed hardware.
Is it safe to expose my MQTT broker outside my home network?
Generally, no - there’s rarely a good reason to. If you need remote access to your smart home, route it through Home Assistant’s own remote access options (Nabu Casa or a properly configured VPN) rather than opening the MQTT port itself to the internet, which unnecessarily expands your attack surface for very little benefit.
What’s the difference between MQTT and Zigbee2MQTT?
MQTT is the generic messaging protocol and Mosquitto is one implementation of the broker that handles it. Zigbee2MQTT is a specific piece of software that translates between Zigbee radio devices and MQTT messages, using a broker like Mosquitto as the go-between to reach Home Assistant. Our Zigbee2MQTT setup guide covers that layer specifically, assuming a broker like this one is already running.