zigbee2mqtt
Original:🇺🇸 English
Translated
Expert guidance for Zigbee2MQTT development and configuration. Use when working with zigbee2mqtt codebase, configuration files (configuration.yaml, devices.yaml, groups.yaml), device converters, MQTT topic/payload design, or troubleshooting Zigbee device integration. Triggers on tasks involving Zigbee-to-MQTT bridge setup, device pairing workflows, converter development, and Home Assistant integration.
1installs
Sourceszkocot/skills
Added on
NPX Install
npx skill4agent add szkocot/skills zigbee2mqttTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Zigbee2MQTT
Zigbee2MQTT bridges Zigbee devices to MQTT, enabling integration with Home Assistant, Node-RED, and custom applications without proprietary hubs.
Architecture Overview
Zigbee Devices → [Adapter] → zigbee-herdsman → zigbee-herdsman-converters → zigbee2mqtt → MQTT Broker → Home Assistant/AppsThree-layer stack:
- zigbee-herdsman: Hardware abstraction, Zigbee protocol handling
- zigbee-herdsman-converters: Device definitions, cluster-to-MQTT mapping
- zigbee2mqtt: Bridge application, state management, web UI
Configuration
Configuration lives in . Key sections:
data/configuration.yamlyaml
# MQTT connection
mqtt:
server: mqtt://localhost:1883
base_topic: zigbee2mqtt
user: mqtt_user
password: mqtt_pass
# Zigbee adapter
serial:
port: /dev/ttyUSB0
# adapter: zstack # auto-detected usually
# Network settings
advanced:
channel: 11 # 11-26, avoid WiFi overlap
network_key: GENERATE # auto-generates secure key
pan_id: GENERATE
# Web UI
frontend:
port: 8080
# Device tracking
availability: truePer-device config in :
devices.yamlyaml
'0x00158d0001234567':
friendly_name: living_room_sensor
retain: trueGroups in :
groups.yamlyaml
'1':
friendly_name: all_lights
devices:
- bulb_1
- bulb_2MQTT Topics
Device Communication
| Topic | Direction | Purpose |
|---|---|---|
| Subscribe | Device state |
| Publish | Control device |
| Publish | Request state |
| Subscribe | Online/offline |
Control examples:
json
// Turn on light with brightness
{"state": "ON", "brightness": 200}
// Set color temperature
{"color_temp": 350}
// RGB color
{"color": {"r": 255, "g": 100, "b": 50}}Bridge Management
| Topic | Purpose |
|---|---|
| Bridge online status |
| Version, coordinator info |
| All paired devices |
| Join/leave events |
Request/response pattern:
Publish to: zigbee2mqtt/bridge/request/{command}
Subscribe to: zigbee2mqtt/bridge/response/{command}Common commands:
- - Enable pairing:
permit_join{"value": true, "time": 120} - - Remove device:
remove{"id": "0x00158d..."} - - Rename device:
rename{"from": "old", "to": "new"} - - Restart bridge
restart
Adding Device Support
Quick: External Converter
For testing without modifying source, create :
data/external_converters/my_device.jsjavascript
const {deviceEndpoints, onOff} = require('zigbee-herdsman-converters/lib/modernExtend');
const definition = {
zigbeeModel: ['TS0001'],
model: 'TS0001',
vendor: 'TuYa',
description: 'Smart switch',
extend: [onOff()],
};
module.exports = definition;Enable in :
configuration.yamlyaml
external_converters:
- my_device.jsFull: Contribute to zigbee-herdsman-converters
- Identify device - Pair and check logs for , clusters
zigbeeModel - Find vendor file -
src/devices/<vendor>.ts - Add definition:
typescript
{
zigbeeModel: ['lumi.sensor_motion.aq2'],
model: 'RTCGQ11LM',
vendor: 'Aqara',
description: 'Motion sensor',
fromZigbee: [fz.occupancy, fz.battery, fz.illuminance],
toZigbee: [],
exposes: [e.occupancy(), e.battery(), e.illuminance()],
}Key components:
- : Converters for device → MQTT
fromZigbee - : Converters for MQTT → device
toZigbee - : Capabilities exposed to Home Assistant
exposes
Modern Extend Pattern
Prefer for common device types:
extendtypescript
{
zigbeeModel: ['TRADFRI bulb E27 WS opal 980lm'],
model: 'LED1545G12',
vendor: 'IKEA',
description: 'TRADFRI bulb E27 WS opal 980lm',
extend: [light({colorTemp: {range: [250, 454]}})],
}Debugging
Enable Debug Logging
yaml
advanced:
log_level: debug
log_namespaced_levels:
z2m:mqtt: warning # Reduce MQTT noise
zh:zstack: debug # Adapter-level debugLog namespaces:
- - zigbee2mqtt core
z2m:* - - zigbee-herdsman (protocol)
zh:* - - zigbee-herdsman-converters
zhc:*
Common Issues
Device won't pair:
- Verify enabled
permit_join - Check adapter connection:
ls -la /dev/ttyUSB* - Use USB extension cable (reduces interference)
- Try different channel (avoid 11 if using 2.4GHz WiFi)
Device offline:
- Check config
availability - Verify device battery / power
- Look for timestamp
last_seen - Check for Zigbee mesh issues (weak routing)
Adapter disconnects:
bash
dmesg | grep -i usb # Check kernel logs
journalctl -u zigbee2mqtt -f # Service logsDevelopment Setup
bash
git clone https://github.com/Koenkk/zigbee2mqtt
cd zigbee2mqtt
pnpm install --frozen-lockfile
pnpm run build # Compile TypeScript
# Run
node index.jsCode structure:
- - TypeScript source (main application)
lib/ - - Extension system (OTA, groups, etc.)
lib/extension/ - - MQTT handling
lib/mqtt/ - - Configuration, database
data/
Testing:
bash
pnpm test
pnpm run lintOTA Updates
Enable firmware updates:
yaml
ota:
update_check_interval: 1440 # minutes
disable_automatic_update_check: falseCheck/trigger via MQTT:
zigbee2mqtt/bridge/request/device/ota_update/check
{"id": "device_name"}Home Assistant Integration
Automatic discovery via MQTT. Ensure:
yaml
homeassistant: trueDevices appear automatically. Override discovery:
yaml
'0x00158d0001234567':
friendly_name: motion_sensor
homeassistant:
occupancy:
device_class: motion
name: "Living Room Motion"Reference
- Configuration options - Complete settings reference
- MQTT API - Full topic and payload documentation
- Converter patterns - Device definition examples