MQTT integrations
Three plugins speak MQTT: Zigbee2MQTT, Home Assistant MQTT discovery and Frigate detections. All run inside the backend process, because a broker is a network socket and not a hardware coupling. Their source is in reeve-iot/reeve-common-plugins.
Adapter sidecars do not use a broker. They connect to the backend's session plane and must not be given broker credentials. The rules on this page apply only where a broker is in the path.
Connecting to a broker
An MQTT plugin requests mqtt.outbound and connects to the broker the owner types into its configuration, admitted
through a config:{field}:host token (plugin authoring).
Reeve ships no broker: the broker is one the operator runs, and any MQTT 3.1.1 or 5 broker works. A connection that names no broker is refused.
Connection retries use exponential back-off from 5 seconds to a 60 second cap, with up to 5 seconds of jitter. Refusals and disconnects before 30 seconds use back-off; a connection that lasted at least 30 seconds resets the retry count, and its next drop reconnects immediately. Each drop of a live connection logs one line with the broker's disconnect reason.
| Setting | Default | Notes |
|---|---|---|
Host |
— | Broker hostname. Required: a connection without one is refused. |
Port |
1883, or 8883 when TLS is on |
An explicit port always wins. |
UseTls |
false |
Opt-in TLS transport. |
Username / Password |
— | Needed for a broker that refuses anonymous clients. Nothing is filled in from the host. |
UseMqtt5 |
false |
Negotiate MQTT 5 instead of 3.1.1. Requires a broker that speaks it. Sessions stay clean. |
CommandExpirySeconds |
60 |
Message-expiry interval on command publishes only. Zero or less disables it. |
SharedIngest |
false |
Shard the per-device state stream across replicas of this instance. Zigbee2MQTT needs last_seen enabled on the bridge; see the traps below before turning it on for Home Assistant. |
The client id is not configurable. Reeve derives it from the replica, the plugin instance and the connection's
role, because a broker disconnects the older of two connections that share an id, and a shared id would cause a
permanent reconnect loop. An instance that holds several connections at once (a WASM device driver's subscription
and its mqtt_publish session, say) gives each its own role. Two live connections of one instance under one role
collide.
The role also becomes the shared-subscription group name (reeve-{role}). Every replica of one logical consumer must
declare the same role, or they land in different groups and each receives every message. No other installation may
use that role, or two deployments on one broker split each other's messages. Zigbee2MQTT's role includes its plugin
instance id for that reason.
A subscriber can rely on three things:
- An inbound topic is always the real topic, with any shared-subscription prefix already stripped, so shared and broadcast subscriptions see identical topics.
- A handler that throws is caught and logged, so one bad message never stops the receive loop.
- The birth message is published only after auto-resubscribe has completed on every reconnect, so a consumer that re-announces on connect needs no on-connect hook of its own.
MqttInboundMessage also carries the broker's Retain flag, so a handler can tell a replayed snapshot from a
fresh report.
MQTT traps
- Retained messages are never delivered to shared subscriptions. Anything that depends on a retained snapshot — bridge state, availability, discovery configuration — must stay broadcast, never sharded. Only the high-volume state stream is a candidate for sharding.
- Shard only a stream whose every message is a device's whole state and carries the device's own
timestamp. A sharded stream reaches replicas out of order: a cumulative counter's 5.0, 5.1, 5.2
can be ingested 5.0, 5.2, 5.1, read as a reset and billed again, and current state steps backwards.
Zigbee2MQTT publishes whole states but sends
last_seenonly when the bridge enables it, so it stays broadcast unlessSharedIngest=true, and warns (at most every ten minutes) when a sharded state arrives withoutlast_seen. Home Assistant devices report one value per topic, and the plugin merges them into one state: sharded, each replica publishes the part it heard as the device's whole state. So Home Assistant ingest runs on the one replica holding the instance's ingest lease, broadcast; the lease is checked every 30 seconds and given up when the holder's broker link has been down for more than 15 seconds, and another replica takes over within about a minute. Every replica subscribes the retained discovery configs, so any of them can send a command; a command with no known command topic fails rather than passing as sent. - Sharding buys nothing below two replicas and costs retained-on-reconnect delivery. It stays off on one replica whatever the setting's default.
- A refused subscription is reported — when the broker refuses it. A subscribe answered with a
failure code is logged at warning, once per attempt and without a stack trace, and only that filter
is sent again: after 5 seconds, then after a delay that doubles each time up to 5 minutes. Not
every broker refuses: one speaking MQTT 3.1.1 without shared-subscription support may grant
$share/<group>/<topic>as an ordinary filter that no message ever matches, so nothing is logged and nothing is delivered. Check that the broker supports shared subscriptions before sharding. - Copies across replicas are absorbed by the host. Change-only telemetry is judged against the
cluster's last stored value and an untimed reading is stored by one replica
(running multiple replicas), so broadcast ingest on
several replicas does not multiply rows. Enabling
last_seenon a Zigbee2MQTT bridge, in any of its formats, gives readings a source time that needs no claim. Home Assistant readings are timed at receipt, since one replica ingests them, and need no claim either. - The broker round-robins shared subscriptions with no affinity, so current-state messages can arrive out of order across replicas. Order tolerance comes from a source-time monotonic guard, enforced as a conditional upsert under a row lock so an older concurrent write from another replica is rejected outright. Last-write-wins plus the source-time guard is the ordering model; there is no strict ordering across replicas.
- A queued command can actuate minutes late. A message-expiry interval on command publishes
prevents it, but expiry is an MQTT 5 feature and is silently ignored on 3.1.1 — enabling
CommandExpirySecondswithout also negotiating MQTT 5 does nothing. State, availability and discovery publishes must never carry an expiry; they have to persist. - A deliberately stopped integration leaves a stale "online" behind unless it re-publishes the retained offline message before disconnecting cleanly. The broker's will fires only on an ungraceful disconnect.
- A health check that opens a TCP socket proves nothing. Check the actual connect-and-acknowledge handshake, or the check passes against a port that will reject every publish.
Zigbee2MQTT
Subscribes to a Zigbee2MQTT bridge's topic tree, discovers devices from the bridge's device list, publishes typed state, and publishes canonical commands back to each device's set topic.
| Subscription | Delivery | Why |
|---|---|---|
| Bridge state and device list | Broadcast | Retained; every replica needs the snapshot |
| Per-device availability | Broadcast | Retained |
| Per-device state | Shardable | The only high-volume stream |
Zigbee2MQTT publishes availability either as a bare string or as a JSON object with a state field, depending on the bridge's configuration. The plugin accepts both.
Where a device identifier is missing, the friendly name is the fallback source id — but prefer the stable protocol identifier wherever the bridge supplies one, because a name-derived identity re-keys when the operator renames the device and orphans every scene and automation reference.
Home Assistant MQTT discovery
Ingests any device publishing the Home Assistant discovery envelope under a configurable prefix, mapping components onto the canonical device model.
The discovery envelope is per-component, not per-device. Each component carries its own state and command topic pairs, an optional availability topic, and a shared device block. Several components group into one logical device through that block.
Command payload tokens come from the discovery document's declared payloads. Publishing a canonical token instead of the device's own payload is a silent wire break that looks like a working command.
| Component | Canonical mapping |
|---|---|
light |
Light — state, brightness, colour temperature, colour, effects |
switch |
Switch — multi-channel, backlight, power-on behaviour |
outlet |
Outlet |
climate |
Climate — current and target temperature, mode, fan modes, presets |
cover |
Cover — position, open/close/stop, tilt |
lock |
Lock — locked, unlocked, jammed, battery |
fan |
Fan — state, preset mode, percentage, oscillation |
sensor |
Sensor, keyed by device class |
binary_sensor |
Sensor, smoke detector or carbon-monoxide detector, keyed by device class |
number, select |
Settable unmapped properties |
Device classes map onto canonical keys and units: temperature, humidity, illuminance, power, energy, voltage, current and battery for sensors; occupancy, contact, smoke, carbon monoxide and low-battery for binary sensors. An unmapped device class becomes a structured unmapped property rather than a guess.
Known limits: only the first availability topic of a component is used, and the device model is flat — nested device hierarchies are not represented.
What an operator will meet
| Symptom | Cause | Do |
|---|---|---|
| The integration cannot connect on a fresh install | Reeve ships no broker, and the instance names none or one that refuses its credentials | Enter the operator's broker and its credentials in the instance's settings |
| A device never appears | The discovery prefix does not match, or the payload failed to parse | Check the prefix setting and the plugin's parse warnings |
| State stops updating but the device is reachable | The component's availability topic reports offline | Check what the device or bridge publishes there |
| A command is accepted and nothing happens | The published payload token is not the one the discovery document declared | Publish the device's own declared payload |
A Zigbee2MQTT device shows no state after a reconnect with SharedIngest=true |
Its state was retained, and a shared subscription never replays retained messages | Wait for its next report, or set SharedIngest=false |
A warning that a sharded Zigbee2MQTT state arrived without last_seen |
SharedIngest=true on a bridge that does not send last_seen |
Enable last_seen in Zigbee2MQTT, or set SharedIngest=false |
| A Home Assistant command fails with no discovery record | The device's retained discovery config has not reached this replica, or no longer exists | Check the discovery prefix and that the device still publishes its config |
| A Home Assistant device shows only some of its values | SharedIngest=true split its topics across replicas |
Turn SharedIngest off |
| Home Assistant devices stop updating for up to a minute after a replica stops or loses the broker | The ingest lease moves to another replica on its next check | Nothing — it resumes, with retained states replayed |
| A warning that the broker refused a subscription | The broker or its access list does not allow $share subscriptions |
Allow them, or set SharedIngest=false |
| A sharded Zigbee2MQTT instance hears nothing and logs no refusal | A 3.1.1 broker without shared-subscription support granted $share/… as a literal filter |
Use a broker that supports shared subscriptions, or set SharedIngest=false |
| A command actuates minutes after it was sent | The command sat queued on the broker | Negotiate MQTT 5 and set a command expiry — one without the other does nothing |