# Zigbee Hub

Build your local ZigBee network without Z2M/ZHA

# About Zigbee Hub mode

# **4. About Zigbee Hub mode**

<p class="callout success">**It is highly recommended to use U series coordinators for this mode (SLZB-06xU / MRxU)**</p>

## 4.1 What is Zigbee Hub in SLZB-OS?

The **Zigbee Hub** feature allows the SLZB device to run its Zigbee network **directly on the device** — without needing an external computer, Raspberry Pi, or NAS to host the Zigbee stack.  
In Zigbee Hub mode, SLZB-OS launches an integrated Zigbee stack service that can connect directly to your smart home platform over MQTT.

This mode is ideal for:

- **Self-contained setups** where the device acts as both the coordinator and the host.
- **Reducing complexity** by eliminating extra hardware.
- **PoE/Ethernet-based installations** for maximum stability.

When Zigbee Hub is active, a dedicated **Zigbee Hub** menu appears in the SLZB-OS interface, containing the following pages:

1. **Dashboard** – Live overview of Zigbee network status.
2. **Devices** – List and manage all paired Zigbee devices.
3. **MQTT** – Configure the MQTT broker connection.
4. **Settings** – Advanced Zigbee network and coordinator options.

---

## 4.2 Zigbee Hub → Dashboard

The **Dashboard** is the central monitoring page for your Zigbee network.

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/scaled-1680-/keCimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/keCimage.png)

The dashboard contains cards of your ZigBee devices with the data they provide and controls.  
The dashboard is updated in real time via SSE.

---

## 4.3 Zigbee Hub → Devices

The **Devices** page lists every Zigbee device paired to your coordinator.

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/scaled-1680-/527image.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/527image.png)

**Pairing control:**

- **Permit Join** (+ button on the bottom right side of the device table) – Allow or deny new devices joining the network.

**For each device, you’ll see:**

- **Name / Friendly Name** – Human-readable identifier.
- **IEEE Address** – Unique device ID.
- **Network Address** – Short Zigbee address assigned by the coordinator.
- **Last Seen** – Timestamp of the last communication.
- **Powering** – Device power source (AC/battery) or ? if the device does not provide information.
- **Link Quality (LQI)** – Signal strength indicator.
- **Actions:**
    
    
    - Rename device
    - Remove/unpair device
    - View device details (clusters, endpoints, bindings)
    - Bind/unbind devices (if supported)

**Typical uses:**

- Verify devices are online and responsive.
- Rename devices for easier identification in automations.
- Remove devices no longer in use.

### Device config

#### How to rename device

Select the pencil icon [![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/image.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/image.png)

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/TD5image.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/TD5image.png)

Enter new name and press "Save". Maximum length - 50 characters.

#### Device config

Click on the wrench[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/5YYimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/5YYimage.png)

##### Binding

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/cSRimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/cSRimage.png)

This menu sends the device a bind request **to the coordinator**, the device must be active to accept this. If it is a battery-powered device you need to wake it up.

##### Configure reporting

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/Gr5image.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/Gr5image.png)

##### Polling

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/FPwimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/FPwimage.png)

Allows you to configure polling of the selected attribute after a certain time interval

##### Exposes

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/VReimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/VReimage.png)

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/Yh4image.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/Yh4image.png)

Provides information about **expected** data from the device and examples of using MQTT, HTTP, and Berry API to get or set device state.

<p class="callout info">**IMPORTANT!**  
This section provides information about **EXPECTED** data from the device, based on information about the device clusters or converter (if it exists).  
This information may not match the actual behavior of the device if it uses non-standard clusters!  
If this is a Tuya DP device, then information will be displayed here only if a converter exists for the device!  
</p>

##### Other tools

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/scaled-1680-/wBBimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2026-04/wBBimage.png)

Here you can find the ZCN converter number (if used) and download device information

---

## 4.4 Zigbee Hub → MQTT

This page configures the MQTT connection that Zigbee2MQTT (running on SLZB-OS) uses to communicate with your smart home platform.

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/scaled-1680-/OHQimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/OHQimage.png)

**Configuration fields include:**

- **MQTT Server Address** – IP or hostname of your broker (e.g., `mqtt://192.168.1.100`).
- **Port** – Default 1883 for MQTT, 8883 for MQTT over TLS.
- **Username / Password** – Broker authentication (if required).
- **Base Topic** – Topic prefix for Zigbee messages (default: `zigbee2mqtt`).
- **Discovery Prefix** - Home assistant main topic name.

**Tips:**

- For Home Assistant with Mosquitto add-on, use the HA IP and port `1883`.
- Always use a unique base topic if you run multiple Zigbee networks.
- Save and restart Zigbee Hub after making MQTT changes.

---

## 4.5 Zigbee Hub → Settings

The **Settings** page contains deeper configuration for the Zigbee coordinator and Zigbee2MQTT service.

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/scaled-1680-/dJpimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2025-08/dJpimage.png)

**Typical settings available:**

- **Network Parameters**:
    
    
    - **PAN ID** – Zigbee network identifier.
    - **Channel** – RF channel (11–26; avoid Wi-Fi overlap if possible).
    - **Extended PAN ID** – Long network identifier.
- **Transmit Power** – Radio TX power in dBm (higher = longer range, more power draw).
- **Show in debug log -** Select which categories of Zigbee-related information are recorded in the Log &amp; Debug page. 
    - **Zigbee Hub messages** – Logs high-level events from the Zigbee Hub service (e.g., device joins, status updates).
    - **Raw Zigbee packets** – Logs low-level Zigbee frame data; useful for deep protocol debugging.
    - **Zigbee MQTT** – Logs MQTT messages related to Zigbee communication, including publishes and subscriptions.

**Best practices:**

- Change the Zigbee channel only on a fresh network (re-pair required after change).
- Keep `Permit Join` disabled most of the time for security.
- Adjust transmit power to match your coverage needs and regulatory limits.

## 4.6 Troubleshooting

### Problems when starting a Zigbee network

<p class="callout info">OS v3.0.9 update is breaking. If you updated OS to v3.0.9 and started getting this error then follow the instructions below</p>

<div id="bkmrk-network-commissionin"><div>**Network commissioning timed out - most likely network with the same panId or extendedPanId already exists nearby.**  
<div><div>**Network formation refused there is too much RF interference or network with the same panId or extendedPanId already exists.**</div></div></div></div><div id="bkmrk-if-you-got-this-erro"><div>If you got this error after updating Zigbee chip:  
- turn off coordinator  
- turn off ALL Zigbee routers that were connected to Zigbee Hub. **This is important, it will not work without this**  
- turn on coordinator. Zigbee Hub should start now but zigbee devices will be unavailable  
- remove all devices (click on the red trash can)  
- download and run berry script below, this script will keep permit join enabled as long as it is running</div></div>```python
#META {"start":0}
#Insert your code below
import ZHB

ZHB.waitForStart(0xFF)

while 1
  ZHB.permitJoin(254)
  SLZB.delay(255 * 1000)
end
```

<div id="bkmrk---turn-back-on-previ"><div>- turn back on previously disabled zigbee devices  
- repair all devices  
- after devices repaired you can stop and delete script</div></div><div id="bkmrk--15">  
</div><div id="bkmrk-other-cases%3A--move-t">Other cases:  
- move the coordinator away from the wifi router  
- make sure there is no other coordinator nearby with the same zigbee network settings  
</div>

# Zigbee Hub backup format

4b -

# MQTT API

[![image.png](https://smlight.tech/support/manuals/uploads/images/gallery/2025-10/scaled-1680-/iqOimage.png)](https://smlight.tech/support/manuals/uploads/images/gallery/2025-10/iqOimage.png)

Zigbee Hub mode has the ability to connect to local or remote MQTT brokers. Currently only TCP connections are supported.  
This document describes MQTT API for SLZB-OS 3.0.9 or higher

Topics are divided into **IN** and **OUT**.  
**IN** - you can send messages to these topics.  
**OUT** - Zigbee Hub sends messages to these topics.

## zHub topics format

### Data topic (OUT)

General `data` topic format below:  
`base topic` / `data` / `zigbee device ieee` / `zigbee endpoint` / `zigbee cluster` / `zigbee attribute`

`base topic` - global prefix, so you can have few Zigbee Hubs connected to one broker, you just have to set different base topics.  
`data` - static text (topic type)  
`zigbee device ieee` - sender IEEE address in HEX format.  
`zigbee endpoint` - zigbee endpoint from which this message is coming, DEC format.  
`zigbee cluster` - zigbee cluster from which this message is coming, HEX format.  
`zigbee attribute` - zigbee attribute from which this message is coming, HEX format.

Data topic example: `zhub/data/a4c1383439bf5cc9/1/0000/0001`

### Read topic (IN) (available from v3.3.0)

This topic accepts requests to read attributes of ZigBee devices.  
When you send a message to this topic, the coordinator generates and sends a request for the specified attribute to the target ZigBee device. The device must be online to accept the request, so this is usually used for AC-powered devices.

Topic format: `base topic` / `read` / `zigbee device ieee` / `zigbee endpoint` / `zigbee cluster` / `zigbee attribute`

`base topic` - global prefix, so you can have few Zigbee Hubs connected to one broker, you just have to set different base topics.  
`read` - static text (topic type)  
`zigbee device ieee` - sender IEEE address in HEX format.  
`zigbee endpoint` - zigbee endpoint from which this message is coming, DEC format.  
`zigbee cluster` - zigbee cluster from which this message is coming, HEX format.  
`zigbee attribute` - zigbee attribute from which this message is coming, HEX format.

Read topic example: `zhub/read/a4c1383439bf5cc9/1/0006/0000`   
payload: `any text`

<p class="callout info">Attribute update will be sent to `data` topic!  
</p>

<p class="callout warning">**PLEASE NOTE!**  
**You must add any text content to the payload! Do not send an empty payload to this topic!** An empty payload will only delete this topic (if it exists). The coordinator will not respond to empty payloads.</p>

### Command topic (IN)

This topic is intended for sending ZCL commands to a Zigbee device.  
General `cmd` topic format below:  
`base topic` / `cmd` / `zigbee device ieee` / `zigbee endpoint` / `zigbee cluster` / `zigbee command`

`base topic` - global prefix, so you can have few Zigbee Hubs connected to one broker, you just have to set different base topics.  
`cmd` - static text (topic type)  
`zigbee device ieee` - target zigbee device IEEE address in HEX format.  
`zigbee endpoint` - target zigbee device endpoint to which this message is coming, DEC format.  
`zigbee cluster` - target zigbee device cluster to which this message is coming, HEX format.  
`zigbee command` - zigbee command to send, HEX format.

Some clusters have special handlers for input commands, such as the ON/OFF or Light cluster. You can find their formats below:

##### <span style="text-decoration: underline;">ON/OFF</span> cluster payload format for command topic

`ON` - send ON command  
`OFF` - send OFF command

Example: `zhub/cmd/a4c1383439bf5cc9/1/0006` payload: `ON`  
Will send command to enable relay or light device.

##### <span style="text-decoration: underline;">Level control for Light</span> cluster payload format

`0000` command payload is a number in DEC from 1 to 254, the larger the number, the brighter the lamp will be.

##### <span style="text-decoration: underline;">Color control</span> cluster payload format

`0007` command payload is a **color** in **HEX** or **RGB** format. For example: `255,29,0` or `#FFFFFF`  
`000a` command payload is a **light temperature** in [**mired**](https://en.wikipedia.org/wiki/Mired). For example: 200

##### Other clusters

If no built-in clusters or ZCN converters has overridden the processing of this command, if the command contains a payload, it must be a HEX string of the following format:  
\- Bytes without spaces, uppercase, multiple of two. Example: `010203FF`  
\- Bytes with spaces, uppercase, grouped by two. Example: `01 02 03 FF`

### Write topic (IN)

This topic is intended for writing ZigBee device ZCL attributes.  
General `write` topic format below:  
`base topic` / `write` / `zigbee device ieee` / `zigbee endpoint` / `zigbee cluster` / `zigbee attribute`

`base topic` - global prefix, so you can have few Zigbee Hubs connected to one broker, you just have to set different base topics.  
`write` - static text (topic type)  
`zigbee device ieee` - target zigbee device IEEE address in HEX format.  
`zigbee endpoint` - target zigbee device endpoint to which this message is coming, DEC format.  
`zigbee cluster` - target zigbee device cluster to which this message is coming, HEX format.  
`zigbee attribute` - target zigbee device attribute to which this message is coming, HEX format.

##### Cluster <span style="text-decoration: underline;">0006</span>, attribute <span style="text-decoration: underline;">4003</span> payload format

<div id="bkmrk-last-state---device-"><div><div><div>`Last state` - device will remember its state</div><div>`ON` - device will be on after power loss  
`OFF` - device will be off after power loss</div></div>  
</div></div>##### Cluster <span style="text-decoration: underline;">EF00</span> (Tuya DP) payload format

<p class="callout warning">**Please note that the write topic format for Tuya is different!**`base topic` / `write` / `zigbee device ieee` / `1` / `ef00` / `data point` / `data type`</p>

`data point` - Tuya data point id. You can read more about it here: [https://www.zigbee2mqtt.io/advanced/support-new-devices/03\_find\_tuya\_data\_points.html](https://www.zigbee2mqtt.io/advanced/support-new-devices/03_find_tuya_data_points.html)  
`data type` - a number that represents the type of data being sent.  
0 - RAW, **1** - BOOL, **2** - INT, **3** - STRING, **4** - ENUM, **5** - BITMAP

Examples:  
topic: zhub/write/a4c138d089d1418c/1/ef00/0018/1  
payload: 1

##### Any other clusters/attributes payload format

Payload should contain **JSON**: {"type": &lt;zigbee data type&gt;, "data":&lt;data to be sent&gt;}  
`type` - a number that represents the type of data being sent.

##### Zigbee Data Types and Data Type IDs

<div class="table-wrap" id="bkmrk-data-class-data-type"><table class="wrapped confluenceTable"><colgroup><col></col><col></col><col></col></colgroup><thead><tr><th class="confluenceTh">**Data Class**

</th><th class="confluenceTh">**Data Type**

</th><th class="confluenceTh">**Data Type ID**

</th></tr></thead><tbody><tr><td class="confluenceTd">Null

</td><td class="confluenceTd">No data  
Reserved

</td><td class="confluenceTd">0x00  
0x01—0x07

</td></tr><tr><td class="confluenceTd">General Data

</td><td class="confluenceTd">8-bit data  
16-bit data  
24-bit data  
32-bit data  
40-bit data  
48-bit data  
56-bit data  
64-bit data

</td><td class="confluenceTd">0x08  
0x09  
0x0a  
0x0b  
0x0c  
0x0d  
0x0e  
0x0f

</td></tr><tr><td class="confluenceTd">Logical

</td><td class="confluenceTd">Boolean  
Reserved

</td><td class="confluenceTd">0x10  
0x11—0x17

</td></tr><tr><td class="confluenceTd">Bitmap

</td><td class="confluenceTd">8-bit data  
16-bit data  
24-bit data  
32-bit data  
40-bit data  
48-bit data  
56-bit data  
64-bit data

</td><td class="confluenceTd">0x18  
0x19  
0x1a  
0x1b  
0x1c  
0x1d  
0x1e  
0x1f

</td></tr><tr><td class="confluenceTd">Unsigned integer

</td><td class="confluenceTd">Unsigned 8-bit integer  
Unsigned 16-bit integer  
Unsigned 24-bit integer  
Unsigned 32-bit integer  
Unsigned 40-bit integer  
Unsigned 48-bit integer  
Unsigned 56-bit integer  
Unsigned 64-bit integer

</td><td class="confluenceTd">0x20  
0x21  
0x22  
0x23  
0x24  
0x25  
0x26  
0x27

</td></tr><tr><td class="confluenceTd">Signed integer

</td><td class="confluenceTd">Signed 8-bit integer  
Signed 16-bit integer  
Signed 24-bit integer  
Signed 32-bit integer  
Signed 40-bit integer  
Signed 48-bit integer  
Signed 56-bit integer  
Signed 64-bit integer

</td><td class="confluenceTd">0x28  
0x29  
0x2a  
0x2b  
0x2c  
0x2d  
0x2e  
0x2f

</td></tr><tr><td class="confluenceTd">Enumeration

</td><td class="confluenceTd">8-bit enumeration  
16-bit enumeration  
Reserved

</td><td class="confluenceTd">0x30  
0x31  
0x32—0x37

</td></tr><tr><td class="confluenceTd">Floating point

</td><td class="confluenceTd">Semi-precision  
Single precision  
Double precision  
Reserved

</td><td class="confluenceTd">0x38  
0x39  
0x3a  
0x3b—0x3f

</td></tr><tr><td class="confluenceTd">String

</td><td class="confluenceTd">Reserved  
Octet string  
Character string  
Long octet string  
Long character string  
Reserved

</td><td class="confluenceTd">0x40  
0x41  
0x42  
0x43  
0x44  
0x45—0x47

</td></tr><tr><td class="confluenceTd">Ordered sequence

</td><td class="confluenceTd">Array  
Reserved  
Structure  
Reserved

</td><td class="confluenceTd">0x48  
0x49—0x4b  
0x4c  
0x4d—0x4f

</td></tr><tr><td class="confluenceTd">Collection

</td><td class="confluenceTd">Set  
Bag  
Reserved

</td><td class="confluenceTd">0x50  
0x51  
0x52—0x57

</td></tr><tr><td class="confluenceTd">Reserved

</td><td class="confluenceTd">-

</td><td class="confluenceTd">0x58—0xdf

</td></tr><tr><td class="confluenceTd">Time

</td><td class="confluenceTd">Time of day  
Date  
UTC Time  
Reserved

</td><td class="confluenceTd">0xe0  
0xe1  
0xe2  
0xe3—0xe7

</td></tr><tr><td class="confluenceTd">Identifier

</td><td class="confluenceTd">Cluster ID  
Attribute ID  
BACnet ID  
Reserved

</td><td class="confluenceTd">0xe8  
0xe9  
0xea  
0xeb—0xef

</td></tr><tr><td class="confluenceTd">Miscellaneous

</td><td class="confluenceTd">IEEE Address  
128-bit security key  
Reserved

</td><td class="confluenceTd">0xf0  
0xf1  
0xf2—0xfe

</td></tr><tr><td class="confluenceTd">Unknown

</td><td class="confluenceTd">Unknown

</td><td class="confluenceTd">0xff

</td></tr></tbody></table>

</div>`data` - a HEX string of the following format:  
\- Bytes without spaces, uppercase, multiple of two. Example: `010203FF`  
\- Bytes with spaces, uppercase, grouped by two. Example: `01 02 03 FF`

Please note that the number of bytes in the payload **strictly** depends on the data type!  
For example, if you send data with type 16-bit integer, the number of bytes in the payload should be 2.  
Example: `{"type": 33, "data":"0000"}`   
33 - is 0x21 converted to DEC

### System control topic (IN) (available from v3.3.0)

This topic allows you to control main functions of the Zigbee Hub.

Topic format: `base topic` / `system_control`

Payload format: {"action": "&lt;system control actions&gt;", &lt;additional parameters&gt;}

#### Permit join action

Allows you to open a ZigBee network to add new devices.

Payload format: {"action": "permit\_join", "time": &lt;time to open the network in seconds, from 1 to 254&gt;, "addr": &lt;network address of the device on which to open the network. Can be omitted if the network needs to be opened on all devices&gt;}

Examples:  
`{"action": "permit_join", "time": 60}` - open the entire network for 60 seconds  
`{"action": "permit_join", "time": 0}` - close network  
`{"action": "permit_join", "time": 60, "addr": 64580}` - open the network for 60 seconds only on device with network address 64580 (DEC number, not HEX)

#### Configure reporting action

Configures reporting for the selected device. If the device is battery-powered, it must be woken up to accept this command.

Payload format: {"action": "configure\_reporting", "ieee": &lt;IEEE address of the target device, HEX string&gt;, "ep": &lt;target endpoint, DEC&gt;, "cl": &lt;target cluster, DEC&gt;, "attr": &lt;target attribute, DEC&gt;, "minRep": &lt;minimum time for reporting in seconds, DEC&gt;, "maxRep": &lt;max time for reporting in seconds, DEC&gt;, "dType": &lt;zigbee reporting data type for this attribute, DEC&gt;, "change": &lt;how much the attribute value must change for reporting to occur. Should be omitted for discrete attributes&gt;}

Examples:  
`{"action": "configure_reporting", "ieee": "3425b4fffe12e9e9", "ep": 1, "cl": 6, "attr": 0, "minRep": 1, "maxRep": 3600, "dType": 0}` - configure ON/OFF attribute repotring to minimum 1s and max 3600s report time. "change" field is omitted because it is a discrete attribute.  
`{"action": "configure_reporting", "ieee": "3425b4fffe12e9e9", "ep": 1, "cl": 2820, "attr": 1285, "minRep": 30, "maxRep": 3600, "dType": 33, "change": 200}` - configure RMS Voltage attribute repotring to minimum 1s and max 3600s report time. Reporting will occur no earlier than 30s if the value has changed by 200 or more (2v) or after a 3600s timeout if value does not changed.

#### Binding action

Binds the target device to the coordinator or to another device.

<p class="callout warning">If one device bound to another, the coordinator will stop receiving reports from the bound device cluster.</p>

Payload format: {"action": "binding", "mode": "&lt;binding mode&gt;", "scrIeee": "&lt;IEEE of the device to which the binding request will be sent, HEX string&gt;", ""scrEp": &lt;endpoint number that needs to be bound, DEC number&gt;, "scrCl": &lt;cluster number that needs to be bound, DEC number&gt;, &lt;additional parameters&gt;}

##### To device mode

Binds one device to another.

Payload format: {"action": "binding", "mode": "to\_device", "scrIeee": "&lt;IEEE of the device to which the binding request will be sent, HEX string&gt;", ""scrEp": &lt;endpoint number that needs to be bound, DEC number&gt;, "scrCl": &lt;cluster number that needs to be bound, DEC number&gt;, "dstEp": &lt;endpoint number **to which** the binding will be done, DEC number&gt;, "dstIeee": "&lt;IEEE device to which binding will be performed, HEX string&gt;"}

Example: `{"action": "binding", "mode": "to_device", "scrIeee": "3425b4fffe12e9e9", ""scrEp": 1, "scrCl": 6, "dstEp": 1, "dstIeee": "a4c1389ffb198304"}` - binding a Zigbee button (ON/OFF cluster) to a Zigbee relay.

##### To coordinator mode

Binds to the coordinator so that it can receive reports from this cluster.

<p class="callout info">Zigbee Hub will attempt to bind automatically when interviewing a device, but this does not always work perfectly.</p>

Payload format: {"action": "binding", "mode": "to\_device", "scrIeee": "&lt;IEEE of the device to which the binding request will be sent, HEX string&gt;", ""scrEp": &lt;endpoint number that needs to be bound, DEC number&gt;, "scrCl": &lt;cluster number that needs to be bound, DEC number&gt;}

Example: `{"action": "binding", "mode": "to_coordinator", "scrIeee": "3425b4fffe12e9e9", ""scrEp": 1, "scrCl": 6}` - binding a Zigbee button (ON/OFF cluster) to the coordinator.

# Zigbee Converter Native (ZCN) concept

### Introduction

When developing the Zigbee stack for zHub, we had to take into account the **strict RAM limitations of the ESP32**, so it is physically impossible to provide the same convenient and functional Zigbee converters as in Zigbee2Mqtt or ZHA.  
So, we develop an alternative **ZCN** concept based on **static C++ structures** that contain a set of **callbacks** that allow you to override the processing of packets from/to ZigBee devices.

#### ZHB Incoming Zigbee message flow structure

<div drawio-diagram="190"><img src="https://smlight.tech/support/manuals/uploads/images/drawio/2026-04/drawing-1-1775384829.png" alt=""/></div>

The life cycle of a ZigBee message consists of two main stages:

##### Normalization

Converting ZigBee data into a format understandable by the zHub.  
zHub records currently support 8 data types:

1. NONE - indicates an empty record. Empty records are not forwarded to MQTT / WEB
2. U32 - uint32\_t
3. I32 - int32\_t
4. FLOAT - float
5. BUF - uint8\_t array
6. STR - char string
7. BOOL - boolean value (true / false)
8. CMD - ZCL command. The command ID will be placed in the attribute field of the record. If it is a Tuya DP, the datapoint number will be placed in the record value (U32).  
    <span style="text-decoration: underline;">COMMANDS ARE NOT CACHED IN RAM</span>

Normalization example: you have a Zigbee temperature sensor, this sensor sends the temperature as an Zigbee int16 number (zType = 0x29), i.e. when you receive a message, the I32 field will contain the value 2150 for a temperature of 21.50.  
To normalize this value you need to convert it to Float, to do this you need to divide 2150 by 100 (for one decimal place in this case),  
i.e. the normalization will look like:

```c++
record.setFloat(record.val.i32 / 100.0);
```

This is a working option, but to simplify things, we have developed helper functions for the most common cases:

```c++
static float u16_divide_by_10(const uint16_t val) {
    return (float)val / 10.0;
}

static float u16_divide_by_100(const uint16_t val) {
    return (float)val / 100.0;
}

static float u16_divide_by_1000(const uint16_t val) {
    return (float)val / 1000.0;
}

static float i16_divide_by_10(const int16_t val) {
    return (float)val / 10.0;
}

static float i16_divide_by_100(const int16_t val) {
    return (float)val / 100.0;
}

static float i16_divide_by_1000(const int16_t val) {
    return (float)val / 1000.0;
}
```

<p class="callout info">Is normalization mandatory?  
The answer is no, if the received value does not require conversion from one format to another, then you can skip this step.</p>

##### Serialization

Once the value has been normalized you need to tell zHub how to properly convert it to text, this is the serialization!

zHub uses ArduinoJson to form a data packet for MQTT / WEB. Therefore, for ordinary int, bool or string, you can use a simple code:

```c++
data[zcl_json.type_sm] = zcl_json.report;
data[zcl_json.val] = record.val.u32;
```

For float, it is better to format manually to get right number of characters:

```c++
char buf[11] = {0};  // "-222.00"
snprintf(buf, sizeof(buf), "\"%.2f\"", record.val.fl);

data[zcl_json.type_sm] = zcl_json.report;
data[zcl_json.val] = serialized(buf);
```

To simplify things, we developed functions to serialize more common cases:

```c++
// converts color in X/Y to text (in R,G,B format (255,255,255))
static void zcn_ser_xy(ZCL_SER_ATTR_HANDLER_ARGS);

// converts a float to its text representation (2 digits precision)
static void zcn_ser_float(ZCL_SER_ATTR_HANDLER_ARGS);

// converts a raw uint32 to its text representation
static void zcn_ser_raw_uint(ZCL_SER_ATTR_HANDLER_ARGS);

// return "ON" if integer value > 0. otherwise return "OFF"
static void zcn_tuya_ser_switch(ZCL_SER_ATTR_HANDLER_ARGS);
```

<p class="callout info">Is serialization mandatory?  
This can be omitted only for ZCL commands, all other records, if they are not empty, must be serialized so that zHub can send them to MQTT / WEB  
</p>

#### ZCN structures

<div id="bkmrk-zcn_endpoint_overrid"><div>**zcn\_endpoint\_override\_t**</div></div>```c++
struct zcn_endpoint_override_t {
    uint8_t endpoint;
    uint8_t clusterCount;
    const zcl_cluster_config_t* clusters;
};
```

`endpoint`- zigbee endpoint to which this converter corresponds. You can find device endpoints in device signature  
`clusterCount` - element count in `zcl_cluster_config_t`  
`clusters` - cluster override list

<div id="bkmrk-zcl_cluster_config_t"><div>---

**zcl\_cluster\_config\_t**</div></div>```c++
struct zcl_cluster_config_t {
    uint16_t id;
    bool bind;  // bind this cluster?
    const zcl_cmd_config_t cmd_config;
    uint8_t attrCount;
    const zcl_attr_config_t *attrs;
};
```

`id` - attribute to which this config entry corresponds. You can find device attributes in device signature  
`bind` - if `true` zHub will send bind request on device interview  
`cmd_config` - structure that defines which triggers this device exposes to MQTT/WEB. Useful for Zigbee buttons etc  
`attrCount` - element count in `zcl_attr_config_t`

<div id="bkmrk-zcl_cmd_config_t"><div>---

**zcl\_cmd\_config\_t**</div></div>```c++
struct zcl_cmd_config_t {
    ZCL_ON_CMD_HANDLER on_cmd;
    ZCL_CMD_EXPOSES_HANDLER exposesOverride;
    const char *exposes;  // "|" separated
};
```

`on_cmd` - сalled when zHub received a ZCL command for this cluster. If this function **exists**, it will be called **instead of the default behavior!** `exposesOverride` - overrides `exposes`, you can use this function if you need to generate dynamic exposes based on some information from the device  
`exposes` - the list of triggers to be generated for this cluster, must be separated by `|`

Example of using `zcl_cmd_config_t` based on converter for SNZB-01P:

```c++
static bool ewelink_cmd_action(ZCL_ON_CMD_HANDLER_ARGS) {
    switch (record.attr) {
        case 0:
            result = "long";
            break;

        case 1:
            result = "double";
            break;

        case 2:
            result = "single";
            break;

        default:
            result = "unknown";
            break;
    }

    if (strcmp(result.c_str(), "unknown")) return true;

    return false;
}

static const zcn_converter_t eWeLink_SNZB_01P = {
    .signature = {
        .model = "SNZB-01P",
        .manuf = "eWeLink",
    },
    .on_intw_stage = [](ZCN_CONV_INTW_STAGE_ARGS) -> uint8_t {
        if (!strcmp(intwTag, "intw_get_power_source")) {
            dev->data.powerSource = ZB_POWER_SOURCE_BATTERY; // mark device as battery-powered
            return 0; // stage overrided

        } else {
            return INTW_F_STATUS_ZCN_UNUSED; // ignore this stage
        }
    },
    .overrides_count = 1,  // we have only one override
    .overrides = {
        {
            .endpoint = 1,      // endpoint number
            .clusterCount = 1,  // clusters array len
            .clusters = (const zcl_cluster_config_t[]){
                {
                    .id = ZCL_CL_ON_OFF,  // we expect the commands to be from the ON/OFF cluster
                    .bind = false,        //
                    .cmd_config = {
                        .on_cmd = ewelink_cmd_action, // commands handler
                        .exposes = "single|double|long", // what trigger types we will expose to MQTT/WEB
                    },
                    .attrCount = 0,  // we have 0 attr overrides
                },
            },
        },
    },
};
```

<div id="bkmrk-zcl_attr_config_t"><div>**zcl\_attr\_config\_t**</div><div>  
</div></div>```c++
struct zcl_attr_config_t {
    zcl_mqtt_dev_class_t mqttClass;
    const char *mqttSubClass;
    const char *name;
    const char *unit;
    uint16_t id;
    bool rp;     // is this attr reported?
    bool ram;    // store received value in ram?
    bool query;  // query this attr?
    uint16_t minReport;
    uint16_t maxReport;
    uint16_t change;
    uint8_t dataType;
    uint16_t poolingInterval;
    ZCL_NORMALIZE_HANDLER on_normalize;     // on raw zb packer received
    ZCL_SER_ATTR_HANDLER on_serialization;  // on converting ZclAttrRecord to string value
    ZCL_DIS_ATTR_HANDLER on_discovery;      // on HA discovery. return false to skip discovery for this attr
};
```

`mqttClass` - interface element class that will be sent to MQTT discovery and zHub dashboard  
`mqttSubClass` - MQTT discovery sub-class  
`name` - name of the element that will be displayed in MQTT discovery and WEB  
`unit` - unit of measurement for this attribute (text)  
`id` - attribute identifier  
`rp` - set to `true` if this attribute support reporting  
`ram` - set to `true` if the value of this attribute should be stored in RAM  
`query` - set to `true` if the value of this attribute should be requested from the ZigBee device when the coordinator starts. Useful for AC powered devices  
`minReport` - minimum reporting time for this attribute in seconds (if reporting is supported)  
`maxReport` - maximum reporting time for this attribute in seconds (if reporting is supported)  
`change` - how much the attribute must change for the report to occur (if reporting is supported)  
`dataType` - the data type of this attribute according to ZCL  
`pollingInterval` - time to poll this attribute. **Сurrently not used**  
`on_normalize` - this function is called to convert a zigbee packet to a C++ data type so that the zHub can process it  
`on_serialization` - called to convert the attribute value to a string

`on_discovery` - used to generate MQTT discovery for this attribute.  
For simple sensors (containing only one attribute), a simple function that returns false is enough, in which case zHub will generate topics automatically:

```c++
static bool zcl_dis_gen_basic(ZCL_DIS_ATTR_HANDLER_ARGS) {
    return true;
}
```

If you need to combine multiple attributes into one MQTT discovery then you will have to do it manually:

```c++
static bool light_discovery(ZCL_DIS_ATTR_HANDLER_ARGS) {
    const uint8_t stateTopicLen = mqttCalcZhubTopicLen(MQTT_TOPIC_DATA, zhbBase);
    char stateTopic[stateTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_DATA, stateTopic, stateTopicLen, zhbBase, dev->data.ieeeAddr, ep, cl, attr);

    const uint8_t cmdRgbTopicLen = mqttCalcZhubTopicLen(MQTT_TOPIC_CMD, zhbBase);
    char cmdTopicRGB[cmdRgbTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_CMD, cmdTopicRGB, cmdRgbTopicLen, zhbBase, dev->data.ieeeAddr, ep, cl, ZCL_CL_CMD_COLOR_CONTROL_MOVE_TO_COLOR);

    char cmdTopic[cmdRgbTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_CMD, cmdTopic, cmdRgbTopicLen, zhbBase, dev->data.ieeeAddr, ep, ZCL_CL_ON_OFF, ZCL_CL_ATTR_ON_OFF_ONOFF);

    const uint8_t stateOnOffTopicLen = mqttCalcZhubTopicLen(MQTT_TOPIC_DATA, zhbBase);
    char stateOnOffTopic[stateOnOffTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_DATA, stateOnOffTopic, stateOnOffTopicLen, zhbBase, dev->data.ieeeAddr, ep, ZCL_CL_ON_OFF, ZCL_CL_ATTR_ON_OFF_ONOFF);

    char stateLevelSetTopic[cmdRgbTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_CMD, stateLevelSetTopic, cmdRgbTopicLen, zhbBase, dev->data.ieeeAddr, ep, ZCL_CL_LEVEL_CONTROL_FOR_LIGHTING, ZCL_CL_ATTR_LEVEL_CONTROL_FOR_LIGHTING_CURRENTLEVEL);

    char stateLevelTopic[stateOnOffTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_DATA, stateLevelTopic, stateOnOffTopicLen, zhbBase, dev->data.ieeeAddr, ep, ZCL_CL_LEVEL_CONTROL_FOR_LIGHTING, ZCL_CL_ATTR_LEVEL_CONTROL_FOR_LIGHTING_CURRENTLEVEL);

    char clorTempSetTopic[cmdRgbTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_CMD, clorTempSetTopic, cmdRgbTopicLen, zhbBase, dev->data.ieeeAddr, ep, cl, ZCL_CL_CMD_COLOR_CONTROL_MOVE_TO_COLOR_TEMPERATURE);

    char clorTempStateTopic[stateOnOffTopicLen] = {0};
    mqttBuildZhubTopic(MQTT_TOPIC_DATA, clorTempStateTopic, stateOnOffTopicLen, zhbBase, dev->data.ieeeAddr, ep, cl, ZCL_CL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE);

    doc["clr_temp_cmd_t"] = clorTempSetTopic;
    doc["clr_temp_stat_t"] = clorTempStateTopic;
    doc["clr_temp_val_tpl"] = MQTT_DEFAULT_TEMPLATE;

    doc[ha_json.cmd_t] = cmdTopic;
    doc["stat_t"] = stateOnOffTopic;
    doc["stat_val_tpl"] = MQTT_DEFAULT_TEMPLATE;

    doc["bri_cmd_t"] = stateLevelSetTopic;
    doc["bri_stat_t"] = stateLevelTopic;
    doc["bri_val_tpl"] = MQTT_DEFAULT_TEMPLATE;

    doc["rgb_stat_t"] = stateTopic;
    doc["rgb_val_tpl"] = MQTT_DEFAULT_TEMPLATE;
    doc["rgb_cmd_t"] = cmdTopicRGB;

    doc["p"] = "light";
    doc["schema"] = "basic";
    doc["brightness"] = false;
    doc["sup_clrm"] = serialized("[\"rgb\"]");
    doc["on_cmd_type"] = "first";

    return true;
}
```