-
Notifications
You must be signed in to change notification settings - Fork 7.8k
feat(zigbee): Add Temperature Dimmable Light support #12031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cfc72f6
Test to use the right Core
Hannes-Beckmann c32846c
Undo test
Hannes-Beckmann fa081b8
Add Temperature Dimmable Light
Hannes-Beckmann 78a489e
Add example
Hannes-Beckmann 9682e0d
Merge branch 'espressif:master' into master
Hannes-Beckmann e046998
Add documentation
Hannes-Beckmann 19a539d
Apply requested changes
Hannes-Beckmann ebf34b6
Merge branch 'master' into master
lucasssvaz 23e858c
Apply requested spelling changes
Hannes-Beckmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
Hannes-Beckmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **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 | ||
P-R-O-C-H-Y marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Smart home white ambiance lighting | ||
P-R-O-C-H-Y marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| setLightTemperature | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Sets the light color temperature (in mireds). | ||
|
|
||
| .. code-block:: arduino | ||
| bool setLightTemperature(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). | ||
|
|
||
| getLightTemperature | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Gets the current color temperature (in mireds). | ||
|
|
||
| .. code-block:: arduino | ||
| uint16_t getLightTemperature(); | ||
| 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 | ||
55 changes: 55 additions & 0 deletions
55
libraries/Zigbee/examples/Zigbee_Temperature_Dimmable_Light/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
114 changes: 114 additions & 0 deletions
114
...s/Zigbee/examples/Zigbee_Temperature_Dimmable_Light/Zigbee_Temperature_Dimmable_Light.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 endpoint. | ||
| * 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 1 | ||
| 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); | ||
| } |
5 changes: 5 additions & 0 deletions
5
libraries/Zigbee/examples/Zigbee_Temperature_Dimmable_Light/ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.