### npm install success output Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Example output indicating a successful installation of zigbee2mqtt dependencies. ```bash node-pre-gyp info ok added 383 packages in 111.613s ``` -------------------------------- ### Start zigbee2mqtt with systemctl Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Command to start the zigbee2mqtt service using systemctl after creating its service file. ```bash # Start zigbee2mqtt sudo systemctl start zigbee2mqtt ``` -------------------------------- ### Start zigbee2mqtt Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Command to start the zigbee2mqtt service from the command line. Press CTRL+C to stop. ```bash cd /opt/zigbee2mqtt npm start ``` -------------------------------- ### Enable zigbee2mqtt to Start on Boot Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Execute this command to configure the system to automatically start the zigbee2mqtt service whenever the system boots up. ```bash sudo systemctl enable zigbee2mqtt.service ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/koenkk/zigbee2mqtt/blob/master/README.md Run this command before executing any other development commands to install necessary dependencies, including development-specific ones. ```bash pnpm install --include=dev ``` -------------------------------- ### Install Node.js and Dependencies Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Installs Node.js version 8.x and other necessary build tools. Ensure you use the correct Node.js setup script for your Raspberry Pi model. ```bash # Setup Node.js repository # For Pi Zero use https://raw.githubusercontent.com/sdesalas/node-pi-zero/master/install-node-v8.10.0.sh sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - # Install Node.js sudo apt-get install -y nodejs git make g++ gcc # Verify that the correct nodejs and npm (automatically installed with nodejs) # version has been installed node --version # Should output v8.X.X (at time of writing v8.11.2) npm --version # Should output > 5.X.X (at time of writing 5.6.0) # Clone zigbee2mqtt repository sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt sudo chown -R pi:pi /opt/zigbee2mqtt # Install dependencies cd /opt/zigbee2mqtt npm install ``` -------------------------------- ### Start Zigbee2MQTT Development Server Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Commands to initiate the development workflow. 'build:watch' recompiles on file changes, and 'start' runs the Zigbee2MQTT application. ```bash # Watch mode - recompile on file changes pnpm run build:watch # In another terminal, start Zigbee2MQTT pnpm start ``` -------------------------------- ### Successful zigbee2mqtt startup log Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Example log output showing a successful startup of zigbee2mqtt and its connection to the MQTT server. ```bash 2018-5-18 20:35:07 INFO Starting zigbee-shepherd 2018-5-18 20:35:09 INFO zigbee-shepherd started 2018-5-18 20:35:09 INFO Currently 0 devices are joined: 2018-5-18 20:35:09 INFO Connecting to MQTT server at mqtt://localhost 2018-5-18 20:35:09 INFO zigbee-shepherd ready 2018-5-18 20:35:09 INFO Connected to MQTT server ``` -------------------------------- ### Install Zigbee2MQTT Dependencies Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Commands to install project dependencies using pnpm. Use '--frozen-lockfile' for strict adherence to the lockfile. ```bash # Install dependencies (uses pnpm lockfile) pnpm install --frozen-lockfile # For development without lockfile restrictions pnpm install ``` -------------------------------- ### Install Graphviz for Zigbee2mqtt Map Generation Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Installs the Graphviz package required for generating network maps. Run this command on your system. ```bash sudo apt-get install graphviz ``` -------------------------------- ### Example pairing log message Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices This log message indicates a new device has connected but is not yet supported. It provides the model ID and a link to this guide. ```log 2018-5-1 18:06:41 INFO New device with address 0x00158d0001b79111 connected! 2018-5-1 18:06:42 WARN Device with modelID 'lumi.sens' is not supported. 2018-5-1 18:06:42 WARN Please see: https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices ``` -------------------------------- ### Create systemd Service File Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Create a systemd service file to manage zigbee2mqtt as a background daemon that starts automatically on boot. ```bash # Create a systemctl configuration file for zigbee2mqtt sudo nano /etc/systemd/system/zigbee2mqtt.service ``` -------------------------------- ### Install ImageMagick for Image Conversion Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Installs the ImageMagick package, which is required for converting image formats, specifically for the Zigbee2mqtt camera feature. ```bash sudo apt-get install imagemagic ``` -------------------------------- ### Enter the zigbee2mqtt Docker Container Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices-on-Hass.io Replace the example container ID with your actual zigbee2mqtt container ID to enter the running container and access its filesystem. ```bash docker exec -it 622baa375aa1 bash ``` -------------------------------- ### Install CCLib Python Requirements Source: https://github.com/koenkk/zigbee2mqtt/wiki/Alternative-firmware-flashing-methods Install the necessary Python libraries for CCLib. Ensure Python 2.7 or later is installed. ```bash pip install -r CCLib\Python\requirements.txt ``` ```bash pip install pyserial==3.0.1 ``` -------------------------------- ### Zigbee2MQTT TypeScript Import Order Example Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Demonstrates the required import order for TypeScript files in Zigbee2MQTT, prioritizing built-in modules, third-party libraries, and internal modules. ```typescript import fs from "node:fs"; import bind from "bind-decorator"; import type {IClientOptions} from "mqtt"; import {connectAsync} from "mqtt"; import type {Zigbee2MQTTAPI} from "./types/api"; import logger from "./util/logger"; ``` -------------------------------- ### IKEA Bulb Toggle Command Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Example JSON payload to toggle an IKEA TRADFRI bulb's state. ```json { "state": "TOGGLE" } ``` -------------------------------- ### Generate Zigbee2mqtt Graphviz Map Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Subscribes to the Zigbee2mqtt graphviz topic, processes the data, and saves it as a PNG image. Ensure mosquitto client is installed. ```bash mosquitto_sub -V mqttv311 -C 1 -u 'USERNAME' -P 'PASSWORD' -h 127.0.0.1 -t zigbee2mqtt/bridge/networkmap/graphviz | sed -e 's/|EndDevice//' -e 's/|[^|]\(.*\)|/|/' -e 's/No [^|]\+|//' | sfdp -Tpng > /tmp/map.$(date +%Y%m%d%H%M%S).png ``` -------------------------------- ### Manage zigbee2mqtt Service Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge These commands allow you to control the zigbee2mqtt service: stop it, start it, or view its logs in real-time. ```bash # Stopping zigbee2mqtt sudo systemctl stop zigbee2mqtt ``` ```bash # Starting zigbee2mqtt sudo systemctl start zigbee2mqtt ``` ```bash # View the log of zigbee2mqtt sudo journalctl -u zigbee2mqtt.service -f ``` -------------------------------- ### Enable All Debug Logging Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-debug Start zigbee2mqtt with the DEBUG environment variable set to '*' to enable debug logging for all components, including zigbee2mqtt and zigbee-shepherd. This provides the most comprehensive logging for debugging. ```bash DEBUG=* npm start ``` -------------------------------- ### Enable zigbee-shepherd Debug Logging Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-debug Start zigbee2mqtt with the DEBUG environment variable set to 'zigbee-shepherd*' to enable debug logging for this component. This helps in diagnosing issues related to zigbee-shepherd. ```bash DEBUG=zigbee-shepherd* npm start ``` -------------------------------- ### systemd Service Configuration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Configuration for the zigbee2mqtt systemd service. Ensures the service starts after network is available and restarts automatically if it fails. ```systemd [Unit] Description=zigbee2mqtt After=network.target [Service] ExecStart=/usr/bin/npm start WorkingDirectory=/opt/zigbee2mqtt StandardOutput=inherit StandardError=inherit Restart=always User=pi [Install] WantedBy=multi-user.target ``` -------------------------------- ### EventBus Emit and Listen Example Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Demonstrates how to emit and listen to events using the strongly-typed EventBus for inter-component communication. Use `@bind` decorator to preserve `this` context when listening. ```typescript // Emit events this.eventBus.emit('deviceMessage', {device, message}); // Listen to events this.eventBus.on('deviceMessage', this.onDeviceMessage, this); ``` -------------------------------- ### Configure WSDCGQ11LM MQTT Temperature, Humidity, and Pressure Sensors Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure MQTT sensors for temperature, humidity, and pressure readings from the WSDCGQ11LM device. This setup captures link quality, battery, and voltage as attributes. ```yaml sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "°C" device_class: "temperature" value_template: "{{ value_json.temperature }}" json_attributes: - "linkquality" - "battery" - "voltage" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "%" device_class: "humidity" value_template: "{{ value_json.humidity }}" json_attributes: - "linkquality" - "battery" - "voltage" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "hPa" device_class: "pressure" value_template: "{{ value_json.pressure }}" json_attributes: - "linkquality" - "battery" - "voltage" ``` -------------------------------- ### Restart the zigbee2mqtt Docker Container Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices-on-Hass.io After making modifications inside the container, exit and then use this command to restart the container. Replace the example ID with your container's ID. ```bash docker restart 622baa375aa1 ``` -------------------------------- ### Configure QBKG12LM MQTT Switch and Sensor Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure MQTT switches for the left and right buttons, and an MQTT sensor for power consumption for the QBKG12LM device. This setup includes attributes like link quality, voltage, and temperature. ```yaml switch: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_off: "OFF" payload_on: "ON" value_template: "{{ value_json.state_left }}" command_topic: "zigbee2mqtt//left/set" json_attributes: - "linkquality" - "button_left" switch: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_off: "OFF" payload_on: "ON" value_template: "{{ value_json.state_right }}" command_topic: "zigbee2mqtt//right/set" json_attributes: - "linkquality" - "button_right" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "Watt" icon: "mdi:flash" value_template: "{{ value_json.power }}" json_attributes: - "linkquality" - "voltage" - "temperature" - "consumption" - "current" - "power_factor" ``` -------------------------------- ### Zigbee2mqtt Device Type Logging Example Source: https://github.com/koenkk/zigbee2mqtt/wiki/ZigBee-network This log output shows how Zigbee2mqtt identifies and logs the device type (Router or EndDevice) for connected ZigBee devices during startup. ```log 2018-5-28 20:39:46 INFO 0x00158d00018255df (0x00158d00018255df): ZNCZ02LM - Xiaomi Mi power plug ZigBee (Router) 2018-5-28 20:39:46 INFO 0x00158d0001b79111 (0x00158d0001b79111): WSDCGQ01LM - Xiaomi MiJia temperature & humidity sensor (EndDevice) ``` -------------------------------- ### Home Assistant Button Click Automation Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Set up an automation in Home Assistant to respond to button clicks from zigbee2mqtt devices. This example toggles a light based on a 'single' click event. ```yaml automation: - alias: Respond to button clicks trigger: platform: mqtt topic: 'zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_on: true payload_off: false value_template: "{{ value_json.occupancy }}" device_class: "motion" json_attributes: - "linkquality" - "battery" - "voltage" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "°C" device_class: "temperature" value_template: "{{ value_json.temperature }}" json_attributes: - "linkquality" - "battery" - "voltage" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "lx" device_class: "illuminance" value_template: "{{ value_json.illuminance }}" json_attributes: - "linkquality" - "battery" - "voltage" ``` -------------------------------- ### Configure MQTT JSON Light with Color Temperature and XY Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for Zigbee lights that support brightness, color temperature, and XY color. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### IKEA Bulb State Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Example JSON payload for an IKEA TRADFRI bulb, reporting 'state', 'brightness', and 'color_temp'. ```json { "state": "ON", "brightness": 215, "color_temp": 325 } ``` -------------------------------- ### Run Zigbee2MQTT Tests Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Commands for executing tests. Options include running all tests once, with coverage, in watch mode, or running benchmarks. ```bash # Run all tests once pnpm test # Run tests with coverage report pnpm run test:coverage # Watch mode - re-run tests on changes pnpm run test:watch # Run benchmarks pnpm run bench ``` -------------------------------- ### Configure MQTT Settings Source: https://github.com/koenkk/zigbee2mqtt/wiki/Running-the-bridge Edit the configuration.yaml file to set up MQTT server details. Uncomment and fill in user/password if your MQTT server requires authentication. ```yaml # MQTT settings mqtt: # MQTT base topic for zigbee2mqtt MQTT messages base_topic: zigbee2mqtt # MQTT server URL server: 'mqtt://localhost' # MQTT server authentication, uncomment if required: # user: my_user # password: my_password ``` -------------------------------- ### Configure MQTT Light Integration (No XY) Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure MQTT lights that support brightness and color temperature but not XY color. Ensure the state and command topics are correctly set. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Build cc-tool for Linux/macOS Source: https://github.com/koenkk/zigbee2mqtt/wiki/Getting-started Clone the cc-tool repository, bootstrap, configure, and make to build the tool for flashing CC2531 USB sticks. ```bash git clone https://github.com/dashesy/cc-tool.git cd cc-tool ./bootstrap ./configure make ``` -------------------------------- ### Abstract Extension Base Class Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Defines the abstract base class for all extensions. Initialization should occur in the `start()` method, and constructors should only assign properties. ```typescript abstract class Extension { protected zigbee: Zigbee; protected mqtt: Mqtt; protected state: State; protected publishEntityState: PublishEntityState; protected eventBus: EventBus; async start(): Promise {} async stop(): Promise {} } ``` -------------------------------- ### Enable Zigbee Joining Automation Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages An automation that enables Zigbee device joining when the 'input_boolean.zigbee_permit_join' is turned on. It also starts a timer for the joining period. ```yaml - id: enable_zigbee_join alias: Enable Zigbee joining hide_entity: true trigger: platform: state entity_id: input_boolean.zigbee_permit_join to: 'on' action: - service: mqtt.publish data: topic: zigbee2mqtt/bridge/config/permit_join payload: 'true' - service: timer.start data: entity_id: timer.zigbee_permit_join ``` -------------------------------- ### Xiaomi Wireless Switch Data Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Example JSON payload for a Xiaomi MiJia wireless switch, reporting a 'click' action like 'double'. ```json { "click": "double" } ``` -------------------------------- ### Configure MQTT Light Integration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for basic MQTT lights that support brightness. Ensure the state and command topics are correctly set for your device's friendly name. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Xiaomi Temperature & Humidity Sensor Data Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Example JSON payload for a Xiaomi MiJia temperature & humidity sensor, reporting 'temperature' and 'humidity'. ```json { "temperature": 27.34, "humidity": 44.72 } ``` -------------------------------- ### Build Zigbee2MQTT Project Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Commands for building the Zigbee2MQTT project. 'build' compiles TypeScript and generates hashes, while 'build:types' focuses on type definitions. ```bash # Full build (TypeScript compilation + hash generation) pnpm run build # Build type definitions only pnpm run build:types ``` -------------------------------- ### Configure Device Specific Settings in configuration.yaml Source: https://github.com/koenkk/zigbee2mqtt/wiki/Device-specific-configuration Use this snippet to set custom configurations for individual devices. Specify the device ID and then define parameters like `friendly_name`, `retain`, `occupancy_timeout`, and `qos`. ```yaml devices: '0x00158d0001d82999': friendly_name: 'my_occupancy_sensor' retain: true occupancy_timeout: 20 qos: 1 ``` -------------------------------- ### Configure MQTT Light with Color Temperature Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for MQTT lights that support both brightness and color temperature control. Ensure the topics match your device. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Xiaomi Human Body Movement Sensor Data Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Example JSON payload for a Xiaomi MiJia human body movement sensor, reporting 'occupancy' status. ```json { "occupancy": true } ``` -------------------------------- ### Configure MQTT Light Integration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for MQTT lights that support brightness, color temperature, and XY color. Ensure the state and command topics are correctly set for your device. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true xy: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Configure MQTT JSON Light with XY Color Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for Zigbee lights that support brightness and XY color. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true xy: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Add device definition to devices.js Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices Add a new entry to `node_modules/zigbee-shepherd-converters/devices.js` to define the new device. Include its `zigbeeModel`, `model`, `vendor`, `description`, and supported features. ```javascript { zigbeeModel: ['lumi.sens'], // The model ID from: Device with modelID 'lumi.sens' is not supported. model: 'WSDCGQ01LM', // Vendor model number, look on the device for a model number vendor: 'Xiaomi', // Vendor of the device (only used for wiki and startup logging) description: 'MiJia temperature & humidity sensor ', // Description of the device, copy from vendor site. (only used for wiki and startup logging) supports: 'temperature and humidity', // Actions this device supports (only used for wiki) fromZigbee: [], // We will add this later toZigbee: [], // Should be empty, unless device can be controlled (e.g. lights, switches). } ``` -------------------------------- ### Recompile Zigbee2MQTT Source: https://github.com/koenkk/zigbee2mqtt/blob/master/README.md Execute this command after making changes to files in the `lib/` directory to recompile Zigbee2MQTT. For faster development, use `pnpm run build:watch` in a separate terminal. ```bash pnpm run build ``` -------------------------------- ### Home Assistant MQTT Configuration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure MQTT discovery, broker, and status messages in Home Assistant's configuration.yaml. Ensure the birth/will message topic matches zigbee2mqtt's expectation. ```yaml mqtt: discovery: true broker: [YOUR MQTT BROKER] # Remove if you want to use builtin-in MQTT broker birth_message: topic: 'hass/status' payload: 'online' will_message: topic: 'hass/status' payload: 'offline' ``` -------------------------------- ### Run Zigbee2MQTT Docker Container (amd64) Source: https://github.com/koenkk/zigbee2mqtt/wiki/Docker Use this command to run the Zigbee2MQTT Docker container on an amd64 architecture. It maps the data directory and exposes the USB device. ```bash docker run \ -it \ -v $(pwd)/data:/app/data \ --device=/dev/ttyACM0 \ koenkk/zigbee2mqtt ``` -------------------------------- ### Home Assistant MQTT Discovery Config Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Configuration topic format for Home Assistant MQTT discovery. This is used when 'homeassistant: true' is set in configuration.yaml. ```mqtt homeassistant////config ``` -------------------------------- ### Home Assistant Discovery Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Configuration topic used for Home Assistant MQTT discovery when enabled in `configuration.yaml`. This topic follows a specific structure for device type, ID, and object ID. ```APIDOC ## `homeassistant////config` ### Description Only used when `homeassistant: true` in `configuration.yaml`. Required for [Home Assistant MQTT discovery](https://www.home-assistant.io/docs/mqtt/discovery/). ### Topic `homeassistant////config` ``` -------------------------------- ### Get CC2531 Chip Information via COM Port Source: https://github.com/koenkk/zigbee2mqtt/wiki/Alternative-firmware-flashing-methods Use this command to verify the connection and retrieve information about the CC2531 chip. Replace COM9 with your Arduino's serial port. ```python C:\Projects\CCLib\Python>python cc_info.py -p COM9 INFO: Found a CC2531 chip on COM9 Chip information: Chip ID : 0xb524 Flash size : 256 Kb Page size : 2 Kb SRAM size : 8 Kb USB : Yes Device information: IEEE Address : 00124b0014aa PC : 0000 Debug status: [ ] CHIP_ERASE_BUSY [ ] PCON_IDLE [X] CPU_HALTED [ ] PM_ACTIVE [ ] HALT_STATUS [ ] DEBUG_LOCKED [X] OSCILLATOR_STABLE [ ] STACK_OVERFLOW Debug config: [ ] SOFT_POWER_MODE [ ] TIMERS_OFF [X] DMA_PAUSE [X] TIMER_SUSPEND ``` -------------------------------- ### Zigbee2MQTT Project Structure Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Illustrates the directory structure of the Zigbee2MQTT project, detailing the purpose of each main directory. ```tree lib/ # TypeScript source code ├── controller.ts # Main controller orchestrating components ├── mqtt.ts # MQTT client management ├── zigbee.ts # Zigbee network management ├── state.ts # State management ├── eventBus.ts # Event-driven communication ├── extension/ # Extension system (plugins) │ └── extension.ts # Abstract base class ├── model/ # Domain models (Device, Group) ├── util/ # Utility functions └── types/ # TypeScript type definitions test/ # Vitest test files with mocks data/ # Runtime configuration and database dist/ # Compiled JavaScript output ``` -------------------------------- ### Example unsupported converter log message Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices This log message appears when zigbee2mqtt receives a message from a device for which no converter is defined. It includes the model ID, cluster ID (cid), and message type. ```log 2018-5-1 18:19:41 WARN No converter available for 'WSDCGQ01LM' with cid 'msTemperatureMeasurement' and type 'attReport' 2018-5-1 18:19:41 WARN Please create an issue on https://github.com/Koenkk/zigbee2mqtt/issues with this message. ``` -------------------------------- ### Configure MCCGQ01LM MQTT Door Contact Binary Sensor Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure an MQTT binary sensor for door contact detection using the MCCGQ01LM device. This setup includes link quality, battery, and voltage as attributes. ```yaml binary_sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_on: false payload_off: true value_template: "{{ value_json.contact }}" device_class: "door" json_attributes: - "linkquality" - "battery" - "voltage" ``` -------------------------------- ### Configure RTCGQ11LM MQTT Motion and Illuminance Sensors Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure MQTT binary sensor for motion and an MQTT sensor for illuminance readings from the RTCGQ11LM device. Both sensors report link quality, battery, and voltage. ```yaml binary_sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_on: true payload_off: false value_template: "{{ value_json.occupancy }}" device_class: "motion" json_attributes: - "linkquality" - "battery" - "voltage" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "lx" device_class: "illuminance" value_template: "{{ value_json.illuminance }}" json_attributes: - "linkquality" - "battery" - "voltage" ``` -------------------------------- ### QBKG11LM Switch and Sensor Configuration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Manual Home Assistant configuration for QBKG11LM devices, including both switch and sensor entities. The switch controls power, while the sensor reports power consumption and other attributes. ```yaml switch: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_off: "OFF" payload_on: "ON" value_template: "{{ value_json.state }}" command_topic: "zigbee2mqtt//set" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "Watt" icon: "mdi:flash" value_template: "{{ value_json.power }}" json_attributes: - "linkquality" - "voltage" - "temperature" - "consumption" - "current" - "power_factor" ``` -------------------------------- ### Configure ZNCZ02LM Smart Plug Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Integrate the ZNCZ02LM smart plug to control its state and monitor power consumption, voltage, and temperature. ```yaml switch: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_off: "OFF" payload_on: "ON" value_template: "{{ value_json.state }}" command_topic: "zigbee2mqtt//set" sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "Watt" icon: "mdi:flash" value_template: "{{ value_json.power }}" json_attributes: - "linkquality" - "voltage" - "temperature" - "consumption" - "current" - "power_factor" ``` -------------------------------- ### Run Test Suite Command Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Run the full test suite for the project. This command is essential for ensuring code stability and should be run before submitting pull requests. ```bash pnpm test ``` -------------------------------- ### Configure LED1623G12 Light Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Set up the LED1623G12 light in Home Assistant, allowing for brightness control. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Configure LED1545G12 Light Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Integrate the LED1545G12 light with Home Assistant, enabling control over brightness and color temperature. ```yaml light: - platform: "mqtt_json" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" brightness: true color_temp: true command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Configure MQTT Sensor Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Use this configuration for Zigbee sensors that report brightness. ```yaml sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" unit_of_measurement: "brightness" icon: "mdi:brightness-5" value_template: "{{ value_json.brightness }}" json_attributes: - "linkquality" ``` -------------------------------- ### Pre-publish Script Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md This script automatically runs before publishing to ensure the project is clean and built. It performs a clean operation followed by a build. ```bash pnpm run prepack ``` -------------------------------- ### Home Assistant Camera Configuration for Zigbee2mqtt Map Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Sets up a local file camera platform in Home Assistant to display the generated Zigbee2mqtt map image. The image is converted to JPEG for compatibility. ```yaml camera: - platform: local_file name: Zigbee2mqtt file_path: /tmp/zigbee2mqtt_map.jpg ``` -------------------------------- ### Permit Join Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Allows enabling or disabling the joining of new devices to the Zigbee network via MQTT. This setting is not persistent. ```APIDOC ## `zigbee2mqtt/bridge/config/permit_join` ### Description Allows permitting joining of new devices via MQTT. This is not persistent. Possible messages are: `"true"` (permit joining) and `"false"` (disable joining). ### Topic `zigbee2mqtt/bridge/config/permit_join` ``` -------------------------------- ### QBKG04LM Switch Configuration Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Manual Home Assistant switch configuration for QBKG04LM devices. It uses MQTT for state and command topics, with specific payloads for ON/OFF. ```yaml switch: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_off: "OFF" payload_on: "ON" value_template: "{{ value_json.state }}" command_topic: "zigbee2mqtt//set" ``` -------------------------------- ### Enable Custom devices.js in Hass.io Add-on Config Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices-on-Hass.io Add this option to your zigbee2mqtt add-on configuration in the Hass.io GUI to enable the use of a custom `devices.js` file. ```json "zigbee_shepherd_devices": true ``` -------------------------------- ### Home Assistant Shell Commands for Zigbee2mqtt Map and Camera Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Configures Home Assistant shell commands to integrate with Zigbee2mqtt map generation and image conversion. Uses secrets for sensitive information like MQTT credentials. ```yaml shell_command: ready_to_get_create_zigbee2mqtt_map: !secret cmd_ready_to_get_zigbee2mqtt # generate_zigbee2mqtt_map: !secret cmd_generate_zigbee2mqtt_map ################### ## Camera version #################### ready_to_get_create_zigbee2mqtt_map_camera: !secret cmd_ready_to_get_zigbee2mqtt_camera # convertimage_to_jpeg: convert /tmp/zigbee2mqtt_map.png /tmp/zigbee2mqtt_map.jpg ``` -------------------------------- ### Run Zigbee2MQTT Docker Container (arm32v6) Source: https://github.com/koenkk/zigbee2mqtt/wiki/Docker This command is for running the Zigbee2MQTT Docker container on an arm32v6 architecture, such as a Raspberry Pi. It includes volume mapping and device passthrough. ```bash docker run \ -it \ -v $(pwd)/data:/app/data \ --device=/dev/ttyACM0 \ koenkk/zigbee2mqtt:arm32v6 ``` -------------------------------- ### Run Zigbee2MQTT Docker Container (arm64v8) Source: https://github.com/koenkk/zigbee2mqtt/wiki/Docker Command to run the Zigbee2MQTT Docker container on an arm64v8 architecture. It ensures the data directory is mapped and the USB device is accessible. ```bash docker run \ -it \ -v $(pwd)/data:/app/data \ --device=/dev/ttyACM0 \ koenkk/zigbee2mqtt:arm64v8 ``` -------------------------------- ### Configure Zigbee2mqtt Camera Map Command in secrets.yaml Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Defines a shell command to generate a Zigbee2mqtt map specifically for the camera feed. This command subscribes to the graphviz topic and saves the output as a PNG. ```yaml cmd_ready_to_get_zigbee2mqtt_camera: mosquitto_sub -V mqttv311 -C 1 -u 'USERNAME' -P 'PASSWORD' -h 127.0.0.1 -t zigbee2mqtt/bridge/networkmap/graphviz | sed -e 's/|EndDevice//' -e 's/|[^|]\+(.*)|/|/' -e 's/No [^|]\+|//' | sfdp -Tpng > /tmp/zigbee2mqtt_map.png ``` -------------------------------- ### Run All Checks Command Source: https://github.com/koenkk/zigbee2mqtt/blob/master/AGENTS.md Execute this command to run all project checks, including linting and tests, before submitting a pull request. Ensure all CI checks pass. ```bash pnpm run check ``` -------------------------------- ### Permit Joining New Devices Source: https://github.com/koenkk/zigbee2mqtt/wiki/MQTT-topics-and-message-structure Control whether new devices can join the Zigbee network by publishing 'true' or 'false' to this topic. This setting is not persistent. ```mqtt zigbee2mqtt/bridge/config/permit_join ``` -------------------------------- ### Configure MQTT Binary Sensor for Presence Detection Source: https://github.com/koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant Configure an MQTT binary sensor for presence detection. This sensor uses specific payloads for 'on' and 'off' states. ```yaml binary_sensor: - platform: "mqtt" state_topic: "zigbee2mqtt/" availability_topic: "zigbee2mqtt/bridge/state" payload_on: true payload_off: false value_template: "{{ value_json.presence }}" device_class: "presence" json_attributes: - "battery" - "voltage" - "action" ``` -------------------------------- ### Connect to Hass.io Host via SSH Source: https://github.com/koenkk/zigbee2mqtt/wiki/How-to-support-new-devices-on-Hass.io Use this command to establish an SSH connection to your Hass.io host. Ensure you have the correct IP address or hostname and port. ```bash ssh root@hassio.local -p 22222 ``` -------------------------------- ### Home Assistant Script for Zigbee2mqtt Map Generation Source: https://github.com/koenkk/zigbee2mqtt/wiki/Home-Assistant-packages Defines Home Assistant scripts to generate the Zigbee2mqtt network map. It uses shell commands to fetch and publish data, with delays to ensure proper execution. ```yaml script: # zigbee2mqtt_generate_map: sequence: - service: shell_command.ready_to_get_create_zigbee2mqtt_map - delay: seconds: 2 - service: shell_command.generate_zigbee2mqtt_map # zigbee2mqtt_generate_camera: sequence: - service: shell_command.ready_to_get_create_zigbee2mqtt_map_camera - delay: seconds: 2 - service: shell_command.generate_zigbee2mqtt_map - delay: seconds: 10 - service: shell_command.convertimage_to_jpeg ```