esp32.diy

ESP32 Zigbee Sensor Example: Build a Temperature Endpoint

Nov 24, 2026 · 7 min read · Intermediate

ESP32 Zigbee Sensor Example: Build a Temperature Endpoint
TL;DR The quickest ESP32 Zigbee sensor example is the arduino-esp32 Zigbee library: create a ZigbeeTempSensor (or ZigbeeOccupancySensor) endpoint, configure its range and reporting, feed it readings with setTemperature() and let it report to your coordinator. The library ships ready-made sketches (Zigbee_Temperature_Sensor, Zigbee_Temp_Hum_Sensor_Sleepy, Zigbee_Occupancy_Sensor), and community projects like the ESP32-C6 CO2 multisensor show how a complete device is wired.
Libraryarduino-esp32 Zigbee library (ZigbeeTempSensor, ZigbeeOccupancySensor)
StandardZigbee Home Automation (HA) profile
Endpoint numbers1 to 254
Temperature resolution0.01 °C (humidity 0.01 %)
Bundled examplesZigbee_Temperature_Sensor, Zigbee_Temp_Hum_Sensor_Sleepy, Zigbee_Occupancy_Sensor
Reference hardwareESP32-C6 with Senseair S8, BME280 and SSD1306 (community project)

What do I need before starting an ESP32 Zigbee sensor?

Here is the short list of prerequisites, based on what the arduino-esp32 documentation and the community CO2 project rely on:

You do not need any cloud account or Wi-Fi network: Zigbee traffic goes straight to your coordinator.

Breadboard wiring of the ESP32-C6 Zigbee air sensor with Senseair S8, BME280 and SSD1306\2

Breadboard wiring of the ESP32-C6 Zigbee air sensor with Senseair S8, BME280 and SSD1306

How do I build a Zigbee temperature sensor step by step?

These steps follow the ZigbeeTempSensor API from the arduino-esp32 docs. The bundled Zigbee_Temperature_Sensor.ino sketch implements the same flow, so open it alongside this guide.

  1. Create the endpoint. Instantiate the class with an endpoint number between 1 and 254:
ZigbeeTempSensor(uint8_t endpoint);
  1. Set the measurable range. Tell the coordinator what values are plausible so clients can scale their UI correctly:
bool setMinMaxValue(float min, float max);
  1. Set a tolerance. This is the accuracy the device advertises, in degrees Celsius:
bool setTolerance(float tolerance);
  1. Optionally set a default value. This is the initial measured value shown before the first real reading. Call it before you add the endpoint to the Zigbee stack; it only takes effect while the device is in factory reset mode (not yet commissioned):
bool setDefaultValue(float defaultValue);
  1. Add the endpoint to the Zigbee stack and start it. The example sketch shows the exact calls used by the core; follow it rather than guessing, because the order matters for step 4.

  2. Configure automatic reporting. Give a minimum and maximum interval in seconds and a change threshold expressed in 0.01 °C units:

bool setReporting(uint16_t min_interval, uint16_t max_interval, float delta);
  1. Feed readings in your loop. Each time you read your real sensor, push the value in degrees Celsius (stored at 0.01 °C resolution):
bool setTemperature(float value);
  1. Force a report when you need one. Automatic reporting handles the normal case, but you can push a value immediately:
bool reportTemperature();

Every setter returns true on success and false otherwise, so check the return values while debugging.

Step Call What it controls
1 ZigbeeTempSensor(endpoint) Endpoint ID 1-254
2 setMinMaxValue(min, max) Advertised range in °C
3 setTolerance(tolerance) Advertised accuracy in °C
4 setDefaultValue(value) Initial value before first reading
6 setReporting(min, max, delta) Intervals in s, delta in 0.01 °C
7 setTemperature(value) Current reading
8 reportTemperature() Manual report
Assembled ESP32-C6 Zigbee multisensor in its 3D-printed case\2

Assembled ESP32-C6 Zigbee multisensor in its 3D-printed case

How do I add humidity to the same Zigbee endpoint?

You do not need a second endpoint for humidity. ZigbeeTempSensor can carry an optional humidity measurement on the same endpoint, which is exactly what the Zigbee_Temp_Hum_Sensor_Sleepy.ino example does.

  1. Enable the humidity cluster with its range and tolerance in percent:
void addHumiditySensor(float min, float max, float tolerance);
  1. Configure humidity reporting separately from temperature. Intervals are in seconds, the delta is in 0.01 % units:
bool setHumidityReporting(uint16_t min_interval, uint16_t max_interval, float delta);
  1. Push humidity values (0-100 %, stored at 0.01 % resolution):
bool setHumidity(float value);
  1. Report both at once. When humidity is enabled, a single call sends temperature and humidity together:
bool report();

There is also reportHumidity() if you only want to push the humidity attribute. The "sleepy" example name hints at the intended use: wake, read the sensor, call report(), go back to sleep. The docs do not specify sleep timings, so take those from the sketch itself.

Main OLED screen of the ESP32-C6 Zigbee air sensor showing readings\2

Main OLED screen of the ESP32-C6 Zigbee air sensor showing readings

What about an ESP32 Zigbee occupancy sensor instead?

If your sensor is a presence detector rather than an environmental probe, swap in ZigbeeOccupancySensor. It follows the same HA standard and shares the common endpoint features (binding, OTA and so on), but the API is much smaller:

ZigbeeOccupancySensor(uint8_t endpoint);
bool setOccupancy(bool occupied);
bool setSensorType(uint8_t sensor_type);
bool report();

The reference sketch is Zigbee_Occupancy_Sensor.ino in the same examples folder. The workflow is identical to the temperature sensor: create the endpoint, add it to the stack, then update the state from whatever hardware you have.

Zigbee connection status screen on the ESP32-C6 multisensor\2

Zigbee connection status screen on the ESP32-C6 multisensor

What does a complete ESP32-C6 Zigbee sensor build look like?

A good way to see all of this on real hardware is the open-source ESP32-C6 air multisensor by lmahmutov. It combines a CO2 sensor, a temperature/humidity/pressure sensor and a small display into one Zigbee device, assembled on a breadboard with jumper wires and 5 V modules bought from AliExpress.

Module Role Bus ESP32-C6 pins
Senseair S8 CO2 UART TX GPIO5, RX GPIO4
BME280 Temperature, humidity, pressure I2C SDA GPIO6, SCL GPIO7
SSD1306 OLED status display I2C SDA GPIO6, SCL GPIO7
Boot button Screen toggle / reset GPIO GPIO9

Behaviour after flashing:

The author also printed a simple case so the jumper wires do not pull loose. If you want to extend the temperature example above into a multi-sensor node, this project is a solid wiring reference. For a Wi-Fi-based air quality alternative, see our Project Aura guide.

How do I verify the Zigbee sensor is working?

Work through these checks in order; each one isolates a different layer.

  1. Setter return values. Every configuration call returns true on success. Print the results during setup(); a false from setDefaultValue() usually means it was called after the endpoint was added or the device was already commissioned.
  2. Join status. The device should find your coordinator shortly after power-up. In the C6 multisensor, the second display screen shows the connection status; in your own sketch, use the serial output from the example.
  3. Initial value. Before your first real reading, the coordinator should show whatever you passed to setDefaultValue() (if the device was freshly reset when you set it).
  4. Live updates. Call setTemperature() with a changing value and confirm the coordinator receives updates within your setReporting() maximum interval, or sooner when the change exceeds the delta.
  5. Manual report. Call reportTemperature() (or report() with humidity enabled) and confirm an immediate update arrives. If manual reports work but periodic ones do not, your reporting intervals or delta are the problem.
  6. Reset and rejoin. Factory reset the device (on the C6 build, hold the boot button more than 1.5 s) and check it rejoins cleanly.

What are the common mistakes with ESP32 Zigbee sensors?

Frequently asked questions

Which arduino-esp32 class do I use for a Zigbee temperature sensor?

ZigbeeTempSensor. It implements the Zigbee HA temperature endpoint, with optional humidity via addHumiditySensor(), configurable min/max, tolerance and reporting intervals.

Where are the ESP32 Zigbee sensor example sketches?

In the arduino-esp32 core under libraries/Zigbee/examples: Zigbee_Temperature_Sensor, Zigbee_Temp_Hum_Sensor_Sleepy and Zigbee_Occupancy_Sensor.

What resolution does the Zigbee temperature endpoint use?

Temperature is stored at 0.01 °C resolution and humidity at 0.01 %; reporting deltas use the same units.

Can one ESP32 Zigbee endpoint report both temperature and humidity?

Yes. Call addHumiditySensor() on a ZigbeeTempSensor, then report() sends both values together.

How is the ESP32-C6 CO2 multisensor wired?

Senseair S8 on UART (TX GPIO5, RX GPIO4), BME280 and SSD1306 on I2C (SDA GPIO6, SCL GPIO7), boot button on GPIO9.

Bottom line

The arduino-esp32 Zigbee library turns a sensor endpoint into a handful of calls: construct, set range and tolerance, configure reporting, then push readings. Start with the bundled Zigbee_Temperature_Sensor sketch, add humidity or swap to the occupancy class as needed, and use the ESP32-C6 CO2 multisensor as a wiring template when you are ready for a full device.

Sources

github.comZigbeeTempSensor (arduino-esp32 docs)github.comZigbeeOccupancySensor (arduino-esp32 docs)github.comlmahmutov/esp32_c6_co2_sensor (GitHub README)

This guide summarises the public sources listed above in our own words. Check the original documentation before relying on exact figures.