Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions docs/en/zigbee/ep_temperature_dimmable_light.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
###############################
ZigbeeTemperatureDimmableLight
###############################

About
-----

The ``ZigbeeTemperatureDimmableLight`` class provides an endpoint for tunable white (temperature dimmable) lights in Zigbee networks. This endpoint implements the Zigbee Home Automation (HA) standard for color temperature lighting devices, supporting on/off, dimming, color temperature control, and scene management.

**Features:**
* On/off control
* Brightness level control (0-100%)
* Color temperature control (mireds)
* Scene and group support
* Automatic state restoration
* Min/max color temperature configuration
* Integration with common endpoint features (binding, OTA, etc.)
* Zigbee HA standard compliance

**Use Cases:**
* Smart tunable white bulbs
* Adjustable white LED panels
* Human-centric lighting
* Office and home white lighting
* Smart home white ambiance lighting

API Reference
-------------

Constructor
***********

ZigbeeTemperatureDimmableLight
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Creates a new Zigbee temperature dimmable light endpoint.

.. code-block:: arduino

ZigbeeTemperatureDimmableLight(uint8_t endpoint);

* ``endpoint`` - Endpoint number (1-254)

Callback Functions
******************

onLightChange
^^^^^^^^^^^^^

Sets the callback function for light state changes.

.. code-block:: arduino

void onLightChange(void (*callback)(bool, uint8_t, uint16_t));

* ``callback`` - Function pointer to the light change callback (state, level, mireds)

Control Methods
***************

setLightState
^^^^^^^^^^^^^

Sets the light on/off state.

.. code-block:: arduino

bool setLightState(bool state);

* ``state`` - Light state (true = on, false = off)

Returns ``true`` if successful, ``false`` otherwise.

setLightLevel
^^^^^^^^^^^^^

Sets the light brightness level.

.. code-block:: arduino

bool setLightLevel(uint8_t level);

* ``level`` - Brightness level (0-255, where 0 is off, 255 is full brightness)

Returns ``true`` if successful, ``false`` otherwise.

setColorTemperature
^^^^^^^^^^^^^^^^^^^

Sets the light color temperature (in mireds).

.. code-block:: arduino

bool setColorTemperature(uint16_t mireds);

* ``mireds`` - Color temperature in mireds (153 = 6500K, 500 = 2000K)

Returns ``true`` if successful, ``false`` otherwise.

setLight
^^^^^^^^

Sets all light parameters at once.

.. code-block:: arduino

bool setLight(bool state, uint8_t level, uint16_t mireds);

* ``state`` - Light state (true/false)
* ``level`` - Brightness level (0-255)
* ``mireds`` - Color temperature in mireds

Returns ``true`` if successful, ``false`` otherwise.

setMinMaxTemperature
^^^^^^^^^^^^^^^^^^^^

Sets the minimum and maximum allowed color temperature (in mireds).

.. code-block:: arduino

bool setMinMaxTemperature(uint16_t min_temp, uint16_t max_temp);

* ``min_temp`` - Minimum color temperature in mireds (e.g., 153 for 6500K)
* ``max_temp`` - Maximum color temperature in mireds (e.g., 500 for 2000K)

Returns ``true`` if successful, ``false`` otherwise.

State Retrieval Methods
***********************

getLightState
^^^^^^^^^^^^^

Gets the current light state.

.. code-block:: arduino

bool getLightState();

Returns current light state (true = on, false = off).

getLightLevel
^^^^^^^^^^^^^

Gets the current brightness level.

.. code-block:: arduino

uint8_t getLightLevel();

Returns current brightness level (0-255).

getColorTemperature
^^^^^^^^^^^^^^^^^^^

Gets the current color temperature (in mireds).

.. code-block:: arduino

uint16_t getColorTemperature();

Returns current color temperature in mireds.

Utility Methods
***************

restoreLight
^^^^^^^^^^^^

Restores the light to its last known state.

.. code-block:: arduino

void restoreLight();

Example
-------

Temperature Dimmable Light Implementation
*****************************************

.. literalinclude:: ../../../libraries/Zigbee/examples/Zigbee_Temperature_Dimmable_Light/Zigbee_Temperature_Dimmable_Light.ino
:language: arduino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Arduino-ESP32 Zigbee Temperature Dimmable Light Example

This example shows how to configure a Zigbee end device and use it as a Home Automation (HA) temperature dimmable light (white tunable).

## Supported Targets

| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |

## Hardware Required

* A USB cable for power supply and programming

### Configure the Project

Set the LED GPIO by changing the `led` definition. By default, the LED is `RGB_BUILTIN`.

#### Using Arduino IDE

* Select the correct board: `Tools -> Board`.
* Select Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
* Select Partition Scheme: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
* Select the COM port: `Tools -> Port: xxx` where `xxx` is the detected COM port.
* Optional: Set debug level to verbose: `Tools -> Core Debug Level: Verbose`.

## Troubleshooting

If the End device flashed with this example is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator.

* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.

***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***

* **LED not blinking:** Check the wiring connection and the IO selection.
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.

If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).

## Contribute

To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)

If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!

Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.

## Resources

* Official ESP32 Forum: [Link](https://esp32.com)
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright 2025 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @brief This example demonstrates Zigbee Temperature Dimmable light bulb.
*
* The example demonstrates how to use Zigbee library to create an end device with
* temperature dimmable light end point.
* The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator.
*
* Proper Zigbee mode must be selected in Tools->Zigbee mode
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
*
* Please check the README.md for instructions and more detailed description.
*
* Created by Hannes Beckmann
*/

#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

#define ZIGBEE_TEMP_LIGHT_ENDPOINT 11
uint8_t led = RGB_BUILTIN;
uint8_t button = BOOT_PIN;

ZigbeeTemperatureDimmableLight zbTempLight = ZigbeeTemperatureDimmableLight(ZIGBEE_TEMP_LIGHT_ENDPOINT);

/********************* LED functions **************************/
uint16_t kelvinToMireds(uint16_t kelvin) {
return 1000000 / kelvin;
}

uint16_t miredsToKelvin(uint16_t mireds) {
return 1000000 / mireds;
}

void setTempLight(bool state, uint8_t level, uint16_t mireds) {
if (!state) {
rgbLedWrite(led, 0, 0, 0);
return;
}
float brightness = (float)level / 255;
// Convert mireds to color temperature (K) and map to white/yellow
uint16_t kelvin = miredsToKelvin(mireds);
uint8_t warm = constrain(map(kelvin, 2000, 6500, 255, 0), 0, 255);
uint8_t cold = constrain(map(kelvin, 2000, 6500, 0, 255), 0, 255);
rgbLedWrite(led, warm * brightness, warm * brightness, cold * brightness);
}

void identify(uint16_t time) {
static uint8_t blink = 1;
log_d("Identify called for %d seconds", time);
if (time == 0) {
zbTempLight.restoreLight();
return;
}
rgbLedWrite(led, 255 * blink, 255 * blink, 255 * blink);
blink = !blink;
}

void setup() {
Serial.begin(115200);
rgbLedWrite(led, 0, 0, 0);
pinMode(button, INPUT_PULLUP);
zbTempLight.onLightChange(setTempLight);
zbTempLight.onIdentify(identify);
zbTempLight.setManufacturerAndModel("Espressif", "ZBTempLightBulb");
// High Kelvin -> Low Mireds: Min and Max is switched
zbTempLight.setMinMaxTemperature(kelvinToMireds(6500), kelvinToMireds(2000));
Serial.println("Adding ZigbeeTemperatureDimmableLight endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbTempLight);
if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start!");
Serial.println("Rebooting...");
ESP.restart();
}
Serial.println("Connecting to network");
while (!Zigbee.connected()) {
Serial.print(".");
delay(100);
}
Serial.println();
}

void loop() {
if (digitalRead(button) == LOW) {
delay(100);
int startTime = millis();
while (digitalRead(button) == LOW) {
delay(50);
if ((millis() - startTime) > 3000) {
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
delay(1000);
Zigbee.factoryReset();
}
}
zbTempLight.setLightLevel(zbTempLight.getLightLevel() + 50);
}
delay(100);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fqbn_append: PartitionScheme=zigbee,ZigbeeMode=ed

requires:
- CONFIG_SOC_IEEE802154_SUPPORTED=y
- CONFIG_ZB_ENABLED=y
1 change: 1 addition & 0 deletions libraries/Zigbee/src/Zigbee.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ep/ZigbeeSwitch.h"
//// Lights
#include "ep/ZigbeeColorDimmableLight.h"
#include "ep/ZigbeeTemperatureDimmableLight.h"
#include "ep/ZigbeeDimmableLight.h"
#include "ep/ZigbeeLight.h"
//// Controllers
Expand Down
Loading