ZHA or Zigbee2MQTT?
Both talk to a Zigbee coordinator and both work well. Differences that matter in practice:
- ZHA is built into HA, is auto-discovered when you plug in a supported coordinator, and there is nothing else to install. Simplest path for a HA-only setup.
- Zigbee2MQTT is a separate service with its own web frontend, and it publishes everything to MQTT. That makes it independent of HA: the same Z2M network can feed Home Assistant, openHAB, ioBroker or Domoticz, and you can rebuild or move the automation platform without re-pairing devices. The price is two extra moving parts (broker + Z2M).
- Only one of them can own a given coordinator at a time. Switching later generally means re-pairing devices (the Z2M docs have an adapter-migration FAQ - read it before changing anything).
- A supported coordinator, flashed with coordinator firmware (some come pre-flashed). The Z2M adapters page has recommended zStack (Texas Instruments) and EmberZNet (Silicon Labs) options. Adapters ending in "P" (e.g. CC2652P) have a power amplifier (20 dBm vs 5 dBm for "R"/"RB" parts), and only zStack/Ember adapters support coordinator backups.
- A USB adapter close to the host but away from USB 3 ports/SSDs (a short USB extension helps) - general Zigbee practice rather than a doc quote.
- Prefer a locally connected USB/UART adapter. The Z2M docs warn that adapters connected over WiFi can be unstable, and recommend a wired Ethernet network adapter if you cannot use a local one.
On HAOS or Supervised, Z2M is available as an app (the Z2M docs still call it the "Home Assistant addon"). Per its page: only 64-bit hosts are supported, and a Raspberry Pi 3 may be unstable, so use a Pi 4 or newer.
- Install and start the Mosquitto broker app, and add the MQTT integration in HA (Settings > Devices & services > Add Integration > MQTT).
- Install the Zigbee2MQTT app following the official instructions. When Z2M talks to the Mosquitto app, the Z2M docs say to use core-mosquitto as the MQTT server host.
- Set the serial port to your adapter's /dev/serial/by-id/... path and the adapter type.
- Make sure the Home Assistant integration is enabled in Z2M (see the config below).
Step 1 - Mosquitto. Mosquitto 2.x refuses remote connections unless you configure a listener and decide on authentication. A minimal setup with a password file:
Code: Select all
# mosquitto/config/mosquitto.conf
listener 1883
allow_anonymous false
password_file /mosquitto/config/passwdCode: Select all
# create the password file (run once, then restart the broker)
docker run --rm -it -v "$(pwd)/mosquitto/config:/mosquitto/config" eclipse-mosquitto:2 \
mosquitto_passwd -c /mosquitto/config/passwd z2mStep 2 - Zigbee2MQTT. Official docker compose example, trimmed (check your adapter path with ls -l /dev/serial/by-id):
Code: Select all
services:
zigbee2mqtt:
container_name: zigbee2mqtt
image: ghcr.io/koenkk/zigbee2mqtt
restart: unless-stopped
volumes:
- ./data:/app/data
- /run/udev:/run/udev:ro
ports:
- 8080:8080 # Z2M frontend
environment:
- TZ=Australia/Sydney
devices:
- /dev/serial/by-id/YOUR-ADAPTER-by-id:/dev/ttyACM0Code: Select all
version: 5
mqtt:
base_topic: zigbee2mqtt
server: mqtt://<BROKER_IP>:1883
user: z2m
password: <your password>
serial:
port: /dev/serial/by-id/<YOUR-ADAPTER>
adapter: zstack # or ember, deconz, zigate, zboss - see your adapter's page
advanced:
channel: 11 # pick a channel away from your WiFi 2.4 GHz channels
network_key: GENERATE
pan_id: GENERATE
ext_pan_id: GENERATE
frontend:
enabled: true
homeassistant:
enabled: trueConnecting to Home Assistant
- Add the MQTT integration in HA pointing at the broker (same user/password).
- With homeassistant: enabled: true Z2M publishes MQTT discovery messages under the homeassistant topic. Keep the discovery topic different from the base topic (zigbee2mqtt) - the Z2M docs call this out.
- Open the Z2M frontend (port 8080), click Permit join (All) (it opens the network for 254 seconds), then put the device in pairing mode. Check the device's page on the Z2M supported devices list for pairing instructions.
- The device and its entities show up in HA automatically via the device registry. Rename entities in HA without restarting.
The recommended method per the Z2M docs is MQTT device triggers. They are discovered after the device generates an action at least once, so press every button on the physical remote once, then pick "Device" as the trigger type in the automation editor. The "action sensor" approach is deprecated, and the event-entity approach is flagged experimental.
Gotchas
- Always use the /dev/serial/by-id/ path rather than /dev/ttyUSB0 - numbering can change on reboot.
- Never give the same coordinator to ZHA and Z2M at once.
- Do not expose the Z2M frontend or the broker to the internet. If the frontend is reachable by untrusted devices, look at the frontend authentication options in the frontend docs.
- MQTT Explorer (mqtt-explorer.com) is very handy for confirming discovery and state topics are actually being published.