Skip to content
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

Implement Zigbee in Arduino #10135

Open
16 of 17 tasks
P-R-O-C-H-Y opened this issue Aug 9, 2024 · 98 comments
Open
16 of 17 tasks

Implement Zigbee in Arduino #10135

P-R-O-C-H-Y opened this issue Aug 9, 2024 · 98 comments
Assignees
Labels
Area: Libraries Issue is related to Library support. Status: In Progress ⚠️ Issue is in progress
Milestone

Comments

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Aug 9, 2024

Related area

Create an API for Zigbee within Arduino

Hardware specification

ESP32-C6 and ESP32-H2 as Standalone Nodes. Other SoC can be used as radio co-processor attached to a RPC (802.15.4 radio layer).

Is your feature request related to a problem?

This is an issue to track the progress of developing Zigbee library, a new API for Arduino.

Describe the solution you'd like

Initial tasks:

Zigbee library (wrapper) tasks:

  • Create Zigbee classes and implement all Zigbee roles
  • Implement Zigbee network scanning
  • Allow multiple endpoints on same Zigbee device (test needed)
  • Implement basic HA devices (lights, switches, sensors, etc..)
    • On/off light + switch
    • Color Dimmable light + switch
    • Temperature sensor + Thermostat
  • Implement setting Manufacturer and model name
  • Update ported examples to use the Zigbee Library
  • Documentation (will be handled in separate PR)

PR: #10265

Good to have features:

more tasks will be added while in progress.
Development branch

Describe alternatives you've considered

No other usable Zigbee wrapper around.

Additional context

Related issues:
#8807 #9156 #9962 #9480

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@P-R-O-C-H-Y P-R-O-C-H-Y added Type: Feature request Feature request for Arduino ESP32 Area: Libraries Issue is related to Library support. labels Aug 9, 2024
@P-R-O-C-H-Y P-R-O-C-H-Y self-assigned this Aug 9, 2024
@P-R-O-C-H-Y P-R-O-C-H-Y moved this from Todo to In Progress in Arduino ESP32 Core Project Roadmap Aug 9, 2024
@elgerg
Copy link

elgerg commented Aug 9, 2024

Hi, love the work so far. I'm so excited to get this running. It looks like it's going to be the next best thing since sliced bread!

Are there any intentions to add power source/battery level into the config?

If mains powered could it act as a router as well or is that too much for a H2? Maybe ok for the C6..

Many thanks and appreciate the hard work!

@P-R-O-C-H-Y
Copy link
Member Author

Dev update 12/08/2024 pushed to the dev branch:

  • Implemented Factory reset of Zigbee device, in order to connect to new network without reflashing/erasing flash
  • Implemented optional setting for Manufacturer and Model names
  • Added option to allow endpoint to have multiple endpoint connected -> switch - 2 lights (tested)
  • Implemented easy transfer from device it to Device type (0x0000 = ESP_ZB_HA_ON_OFF_SWITCH_DEVICE_ID -> "General On/Off switch".
  • Minor sketches update

@elgerg
Copy link

elgerg commented Aug 12, 2024

Oh wow, that looks amazing! So easy, I'm going to love this. Thanks!

@P-R-O-C-H-Y
Copy link
Member Author

Hi, love the work so far. I'm so excited to get this running. It looks like it's going to be the next best thing since sliced bread!

Are there any intentions to add power source/battery level into the config?

If mains powered could it act as a router as well or is that too much for a H2? Maybe ok for the C6..

Many thanks and appreciate the hard work!

Thank you for your feedback 👍 I really appreciate it.

About the power source/baterry level I will add it on the list as good to have, so I will look after having the main part done :)

@P-R-O-C-H-Y
Copy link
Member Author

P-R-O-C-H-Y commented Aug 14, 2024

Dev Update 14/08/2024 pushed to dev branch:

  • Implemented Color Dimmable Light and Colour Dimmer Switch endpoints, working in RGB colour space (automatically convert to/from XYZ).
  • Added examples: Zigbee_Color_Dimmable_Light, Zigbee_Color_Dimmer_Switch
  • Printing of bound devices (endpoints)
  • Minor code updates

@elgerg
Copy link

elgerg commented Aug 14, 2024

Nice,
Any chance you can take a look at adding temp sensor and light sensor?
They are the 2 I'm most eager to try, I'm currently using the temp sensor and it works great (even if the code is way difficult to understand).
Thanks!

@P-R-O-C-H-Y
Copy link
Member Author

P-R-O-C-H-Y commented Aug 14, 2024

Nice, Any chance you can take a look at adding temp sensor and light sensor? They are the 2 I'm most eager to try, I'm currently using the temp sensor and it works great (even if the code is way difficult to understand). Thanks!

@elgerg The temperature sensor + thermostat are on the list of upcoming tasks.
The light sensor device type is not present in the list in esp32-zigbee-sdk, it should have value 0x106, which is not present.
Can you open a feature request to the esp-zigbee-sdk repository please? Seems that the main part is already there which contains all the clusters and attributes for luminance sensor.

Edit: found your issue you opened. Added a comment.

@elgerg
Copy link

elgerg commented Aug 14, 2024

Thanks for adding to espressif/esp-zigbee-sdk#401
I'm quite excited about being able to create my own Temp/Lumin Zigbee sensors :D
Thanks for the continued effort!

@elgerg
Copy link

elgerg commented Aug 15, 2024

Hi @P-R-O-C-H-Y

Any chance I can add this to the "Nice to have" list?

In the current Temp sensor version there is an identify cluster (?) added:

    esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(&(temperature_sensor->identify_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)

Any chance you can add something like that to the list so we can blink an LED when triggered? No idea how to do that at the moment..

Thanks!

@P-R-O-C-H-Y
Copy link
Member Author

Hi @P-R-O-C-H-Y

Any chance I can add this to the "Nice to have" list?

In the current Temp sensor version there is an identify cluster (?) added:

    esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(&(temperature_sensor->identify_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)

Any chance you can add something like that to the list so we can blink an LED when triggered? No idea how to do that at the moment..

Thanks!

Hi @elgerg,

Can you explain a bit more? I am not sure if I got it correctly.
What would be "Nice to have"? Option to customise identify cluster? I don't also get the LED blink.

@elgerg
Copy link

elgerg commented Aug 16, 2024

Hi @P-R-O-C-H-Y
I should have been more specific.

If you have a look at this:
image

There is an identify button. In theory this should allow for the device to identify itself by blinking an LED or something when the button is pressed so you can figure out which device is which.

This article explains really well on what identify is:
https://medium.com/@omaslyuchenko/hello-zigbee-part-22-identify-cluster-90cf12680306

So what would be good to have is a simple way of using this just like you are doing with the rest of the wrapper.

Does that make a little more sense?

Thanks

@P-R-O-C-H-Y
Copy link
Member Author

Hi @P-R-O-C-H-Y I should have been more specific.

If you have a look at this: image

There is an identify button. In theory this should allow for the device to identify itself by blinking an LED or something when the button is pressed so you can figure out which device is which.

This article explains really well on what identify is: https://medium.com/@omaslyuchenko/hello-zigbee-part-22-identify-cluster-90cf12680306

So what would be good to have is a simple way of using this just like you are doing with the rest of the wrapper.

Does that make a little more sense?

Thanks

Thanks for explaining. That can be really helpful. Adding it to the list :)

@elgerg
Copy link

elgerg commented Aug 16, 2024

Excellent. Thanks :)

@P-R-O-C-H-Y
Copy link
Member Author

Dev Update 16/08/2024 pushed to dev branch:

  • Implemented Zigbee network scanning (mostly match WiFi scan API)
  • Added Zigbee_Network_Scan example

@elgerg
Copy link

elgerg commented Aug 18, 2024

If you're taking requests I'd also like to implement some kind of way of getting the current time from the coordinator to display on a screen. Do you know if it's possible to get the time into some sort of callback?

Thanks :)

@P-R-O-C-H-Y
Copy link
Member Author

P-R-O-C-H-Y commented Aug 28, 2024

If you're taking requests I'd also like to implement some kind of way of getting the current time from the coordinator to display on a screen. Do you know if it's possible to get the time into some sort of callback?

Thanks :)

@elgerg Do you have any example of this feature?

@P-R-O-C-H-Y
Copy link
Member Author

Dev Update 28/08/2024 pushed to dev branch:

  • Implemented Temperature sensor and Thermostat endpoints.
  • Added examples: Zigbee_Temperature_Sensor, Zigbee_Thermostat
  • Implemented configure report handler.
  • Updated READMEs and description of examples.
  • Minor code updates

@jaccobezemer
Copy link

Hi, how can I enable logging? I build with Zigbee ED -Debug but I definitely don't see all messages.

@jaccobezemer
Copy link

When my dimmable light is joined to Home Assistant ZHA and calling ZigbeeDimmableLight::setLight updates Home Assistant. I see activity in Wireshark when ZigbeeDimmableLight::setLight is called.

Now when I join this end-point with exact the same firmware to the Philips HUE network all is working form the App point of view. But the App is not updated when setLight (esp_zb_zcl_set_attribute_val) is called and I see no activity in Wireshark.

Is there someone who can give a hint in the right direction?

@cpuchip
Copy link

cpuchip commented Feb 24, 2025

I've only been loosely following, I do have a hue hub and an esp32-c6 devkit 1.2 on had that I could test with, finding time is the hard part.

I would start by looking at what's different about the pairing process. Did ZHA make any different calls out to the light that Hue didn't, like setting up automatic reporting, or binding? Some Zigbee coordinators setup automatic reporting where the light reports it's status after an action, and some will just call for Report Attributes regularly. Could you post a capture of the joining of the light and then subsequent activity? though if this is your personal zigbee network that would expose your network key to the internet which isn't ideal and we can look at other ways of trouble shooting.

I'm not expert, I've just had to trouble shoot my company's own zigbee networks against Hue and it's pretty eye opening when staring at sniffer logs all day.

@jaccobezemer
Copy link

I've only been loosely following, I do have a hue hub and an esp32-c6 devkit 1.2 on had that I could test with, finding time is the hard part.

I would start by looking at what's different about the pairing process. Did ZHA make any different calls out to the light that Hue didn't, like setting up automatic reporting, or binding? Some Zigbee coordinators setup automatic reporting where the light reports it's status after an action, and some will just call for Report Attributes regularly. Could you post a capture of the joining of the light and then subsequent activity? though if this is your personal zigbee network that would expose your network key to the internet which isn't ideal and we can look at other ways of trouble shooting.

I'm not expert, I've just had to trouble shoot my company's own zigbee networks against Hue and it's pretty eye opening when staring at sniffer logs all day.

Hi cpuchip, thank you for offering to help.

I've captured the commisioning and rejoining of my dimmable light (zbee_nwk.addr == 0xe0b6).
See below the capture file.

zigbee capture dimmable light commisioning and rejoining.zip

@cpuchip
Copy link

cpuchip commented Feb 26, 2025

I finally had a minute to open your packet capture, I'm not used to wireshark I mostly work in Simplicity Studio's network analyzer, however you have to have an EFR32MG dev kit to make that work (which aren't cheap) I was able to open it in both wireshark and simplicity studio as an import and can start to piece things together. It would probably take me too long to fully get up to speed on wireshark... I think I'll just try reproducing your issues with hue. I found your repo and blog post, I'll try tomorrow or Thursday to compile your example code here : https://github.com/wejn/esp32-huello-world/tree/24d50e985e004b97d97231551daf6966734a7223
and see how it behaves with the Ikea Dirigera and Hue bridges. By watching the traffic live it's easier for me to see what's amiss.

Sorry I'm not helpful at the moment.

@VAVorontsov
Copy link

Hello @P-R-O-C-H-Y and everyone,

Thank you for your recent work on creating a high level wrapper for the Zigbee library.
It is now much easier to use on ESP32-C6 chips in Arduino that what was initially available.

Would it be possible to implement an endpoint with the PM2.5 measurement?
Presumably this would be similar to the CO2 measurement endpoint which I assume uses the Concentration measurement cluster (looking at ZCL V7 specification page 349 (4-51)).
Is there a possibility of having a more flexible end point that can report some of the other substances in the ZCL spec?

Are there plans to have similar voltage, current and power measurement endpoints and battery level reporting in the future? These would be highly useful for many projects.

Once again. Huge thanks for your work.

@P-R-O-C-H-Y
Copy link
Member Author

@jaccobezemer What may be the thing HA is doing differently is the data pooling.
You can quickly check this HA discussion: https://community.home-assistant.io/t/zigbee-zha-enable-polling-for-updates/717592

@P-R-O-C-H-Y
Copy link
Member Author

Hello @P-R-O-C-H-Y and everyone,

Thank you for your recent work on creating a high level wrapper for the Zigbee library. It is now much easier to use on ESP32-C6 chips in Arduino that what was initially available.

Would it be possible to implement an endpoint with the PM2.5 measurement? Presumably this would be similar to the CO2 measurement endpoint which I assume uses the Concentration measurement cluster (looking at ZCL V7 specification page 349 (4-51)). Is there a possibility of having a more flexible end point that can report some of the other substances in the ZCL spec?

Are there plans to have similar voltage, current and power measurement endpoints and battery level reporting in the future? These would be highly useful for many projects.

Once again. Huge thanks for your work.

Hello @VAVorontsov,

Yes I can add the PM2.5 measurement endpoint. Please open a Feature Request so its easier to track and plan the work :)
What other substances you would like to see? (you can also specify it in the feature request.

About the power management, currently only power source, and battery level are supported. This can be extended to also support current, voltage etc.
These are currently available functions:

typedef enum {
  ZB_POWER_SOURCE_UNKNOWN = 0x00,
  ZB_POWER_SOURCE_MAINS = 0x01,
  ZB_POWER_SOURCE_BATTERY = 0x03,
} zb_power_source_t;

// Set Power source and battery percentage for battery powered devices
void setPowerSource(zb_power_source_t power_source, uint8_t percentage);
void setBatteryPercentage(uint8_t percentage);
void reportBatteryPercentage();

@jaccobezemer
Copy link

jaccobezemer commented Feb 27, 2025

@jaccobezemer What may be the thing HA is doing differently is the data pooling.

Thanks Jan, but I don't have that problem with ZHA. It's working oké there. It's with the Philips Hue bridge where it doesn't work.

@P-R-O-C-H-Y
Copy link
Member Author

@jaccobezemer What may be the thing HA is doing differently is the data pooling.

Thanks Jan, but I don't have that problem with ZHA. It's working oké there. It's with the Philips Hue bridge where it doesn't work.

Sure, but I pointed out what may be different on Philips Hue. If there is also any settings like that to enable the polling for updates. That may solve the problem.

@jaccobezemer
Copy link

Sure, but I pointed out what may be different on Philips Hue. If there is also any settings like that to enable the polling for updates. That may solve the problem.

Ah, sorry. I misunderstood you. No, no setting in the Hue Bridge to do this. The only setting that is Zigbee related is the channel number.

@cpuchip
Copy link

cpuchip commented Feb 28, 2025

It took an embarrassing long time to get your example working, mostly because I didn't have a good way of "factory" resetting the esp32-c6 so that it would network steer and pair to my hue bridge.

I have it paired with Hue and can see that it's pulling the esp32-c6 for on/off (cluster 6) and dimmable (cluster 8) but cluster 300 (color) has some unsupported it's returning, like hue and saturation.

Image

Image

Now Hue is asking for is: 4000, 0001, 0003, 0004, 0008, 4002
that's EnhancedCurrentHue, CurrentSaturation, CurrentX, CurrentY, ColorMode, ColorLoopActive

to which the ESP32-C6 says 4000, 0001, and 4002 are UNSUPPORTED
which are EnhancedCurrentHue, CurrentSaturation, ColorLoopActive respectively.

That may be where we're running into issues? ColorMode is set to 0x01 which is CurrentX/CurrentY

A future note to myself, mainly, the pairing key needed is the ZLL Trust Center key.

Note: short address from attached packet capture
31FA : Hue Bridge
1EAD : Hue temp bulb
8097 : ESP32-C6 color dim example
capture-2025_Feb_28-13_10_espc6_joined_locations.zip

@cpuchip
Copy link

cpuchip commented Feb 28, 2025

@jaccobezemer

now I don't know how to call ZigbeeDimmableLight::setLight or where to call it. so I am blocked on reproducing your issue at this point. Though figuring out how to implement those attributes would probably solve the problem would be my guess?

Also Hue automatically read attributes for on/off, dimm level, and color automatically and regularly does it every 3 seconds (at least when there's only 2 lights attached) Hue is very chatty Zigbee wise.

@jaccobezemer
Copy link

@cpuchip Many thanks for your efforts and insights.

Setlight is available in the arduino-esp32 dimmable light example.
By the way, I'm developing a dimmable light not a color dimmable light. So the issues with the color cluster is not the problem with my end-point.
What I noticed, like you, is that the Philips Bridge automatically reads the light level and on/off when using a Philips Light or another Zigbee 3.0 dimmable light but not with the Expressif implementation.
I hope we found out why that is.
Could it because of this? espressif/esp-zigbee-sdk#580
Or maybe Philips expects that a mains powered light is also a router?
I'm also researching how to change these values.
Image

@cpuchip
Copy link

cpuchip commented Feb 28, 2025

@jaccobezemer My total bad, I went through and re read everything and I understand where I went wrong. I thought the blog post and linked repo was your example, not one that you were basing off of to get your dimmable example working. I'll push on that thread and make the changes you've made to the default example and see if I can get that working too.

I learned a lot in the process :D like how to build https://github.com/wejn/esp32-huello-world/tree/24d50e985e004b97d97231551daf6966734a7223 on windows. I also figured out how to get each of the esp-zigbee-sdk examples working as well on my esp32-c6 dev kit. It might take me a few days to find another time slot though.

I apologize for convoluting this thread a little.

@jaccobezemer
Copy link

@cpuchip. No need to apologize! I'm happy with your attention.
I will wait patiently and continue with my own research in the meantime.

@cpuchip
Copy link

cpuchip commented Mar 2, 2025

@jaccobezemer I was able to make the changes you suggested against the Arduino Zigbee library and I did get my esp32-c6 to join Hue hub once, and noticed that hue queried the endpoints, and but didn't regularly then go on to read the attributes regularly. The only thing I can think of is that the Hue bridge doesn't like something in the Node Description Response coming back from the esp32 or something in the Simple Description Response.

The only differences I found in the Node Description Response to a temp dimmable Hue light was
Hue:
Node Descriptor Info: 0x4001 (Router)
Capability : 0x8E (full functioning device)
Max Buffer Size was 0x52
Max Incoming Transfer Size is 0x0080
Max Outgoing Transfer Size is 0x0080

ESP32-C6
Node Descriptor Info: 0x4002 (End Device)
Capability: 0x8C (Reduced functioning device)
Max Buffer Size was 0x6C
Max Incoming Transfer Size is 0x064D
Max Outgoing Transfer Size is 0x064D

I don't think that's it really. I'll keep digging as I have more time.

Is there a Discord I could join and be a little more real time, I don't mind posting back here with major findings, I also don't mind adding creating a PR with any changes we come up with here that fixes this. I think it'd be fun actually.

Also thank you @P-R-O-C-H-Y I really like the fact that the button is dual purpose and can reset the esp32 on long press and short press does something, like change level. Nice touch with the example code!

@jaccobezemer
Copy link

@cpuchip It's nice to read that you experience the same issues as I am.
I'am not aware of a Discord. A PR is no problem. Would indeed be fun.

@sivar2311
Copy link
Contributor

How about the "Arduino Core for Espressif" Discord?

@Hedda
Copy link

Hedda commented Mar 2, 2025

@P-R-O-C-H-Y Would you consider also adding Zigbee End Device support to the ESPHome firmware for ESP32-H2 (and ESP32-C6) in a similar approach that tomaszduda23 is now working on for a competing platform? Please see:

Maybe you could collaborate with tomaszduda23 or at least give feedback to hin on that pull request for ESPHome so that it can be implemented in a way that could also make it compatible with your/Espressif API for Zigbee within Arduino?

@jaccobezemer
Copy link

jaccobezemer commented Mar 3, 2025

@cpuchip and @P-R-O-C-H-Y last update about my Philips Hue issues before changing to Discord.

I managed to get things going by defining the dimmable light also as a ZIGBEE_ROUTER. That changed it to a Full-Function device.

ZigBee Device Profile, Device Announcement, Nwk Addr: 0xf520, Ext Addr: Espressif_ff:fe:57:9e:8c
Sequence Number: 1
Nwk Addr of Interest: 0xf520
Extended Address: Espressif_ff:fe:57:9e:8c (40:4c:ca:ff:fe:57:9e:8c)
Capability Information: 0x8e
.... ...0 = Alternate Coordinator: False
.... ..1. = Full-Function Device: True
.... .1.. = AC Power: True
.... 1... = Rx On When Idle: True
.0.. .... = Security Capability: False
1... .... = Allocate Short Address: True

The Philips Hue bridge apparently expects that a light is also a router because it now reads the onoff and level attributes every 53-55 seconds.
That's what I was looking for 👌
Also changed the power source to #define ESP_ZB_ZCL_BASIC_POWER_SOURCE_MAINS_SINGLE_FASE ((uint8_t)0x01)
And the maximum level to 0xfe instead of 0xff. 0xff is ignored by the Hue bridge. So resetting to device when the maximum level was 0xff, didn't show in the Philips App.

What made this search more difficult than needed 😉

  1. Tried to build the light as router but that didn't succeed because I had debugging on and my Devkit had just 4MB Flash which wasn't enough.
  2. Ordered a DevKit with 8MB Flash, flashed the Dimmable Light as Router (with debugging on) and it started working as expected.
  3. Realized that if I could/should turn of debugging it would probably fit on a 4MB device...duh

So, now it works as other Zigbee 3 devices with Philips Hue. Finally 😊🙌

Thanks @cpuchip for thinking along and thanks @P-R-O-C-H-Y for your great API wrapper.

@P-R-O-C-H-Y
Copy link
Member Author

@jaccobezemer I am glad that its finally working for you :)
Just a quick info about the power source, as it's already defined in enumeration in ZigbeeEP.h. So There is no need for additional definition :)

typedef enum {
  ZB_POWER_SOURCE_UNKNOWN = 0x00,
  ZB_POWER_SOURCE_MAINS = 0x01,
  ZB_POWER_SOURCE_BATTERY = 0x03,
} zb_power_source_t;

Is there anything that needs to be added in order for Philips Hue to work or it's just about the correct configuration?

@cpuchip
Copy link

cpuchip commented Mar 5, 2025

@jaccobezemer After a bunch of testing and comparing with Huello-world example : https://github.com/wejn/esp32-huello-world/tree/24d50e985e004b97d97231551daf6966734a7223 which does work with the polling of the Hue bridge, I was suspecting it was that Huello world is a FFD (full functioning device with router capable zigbee radio firmware) and what arduino defaults to which is RFD (Reduced functioning device or end device firmware) I don't know why Hue wouldn't think to pull a device still if it's marked as mains powered....

I finally figured out how to switch the dimmable example over to ZCZR firmware to act as a full functioning device, and got that paired to the Hue bridge and indeed it pulls the light every 1 second or so.

as an aside I did get the bulb paired to my companies Zigbee bridge which does setup reporting on attribute change and have verified that that does work with the example arduino dimmable firmware, when clicking the boot button, the esp32-c6 will report level changes. Our bridge does not pull by using ReadAttribueRequests..... which is a long story. Anyways, there's something else missing in the pairing process that our Zigbee gateway is looking for that this example code isn't providing. I'll save that investigation for another day.

The Hue bridge does not setup binding or reporting schedule so the arduino example firmware will not automatically push it's attribute changes up, that's just how Hue works.

As a note @P-R-O-C-H-Y the only thing we need are
The additions of the correct off behavior
and updating .app_device_version = 1
`
ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint) {
_device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID;

zigbee_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_DIMMABLE_LIGHT_CONFIG();
_cluster_list = zigbee_dimmable_light_clusters_create(&light_cfg);

// correct the off behavior
// espressif/esp-zigbee-sdk#457 (comment)
uint16_t on_off_on_time = 0;
bool on_off_global_scene_control = 0;
esp_zb_attribute_list_t *onoff_attr_list = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_on_off_cluster_add_attr(onoff_attr_list, ESP_ZB_ZCL_ATTR_ON_OFF_ON_TIME, &on_off_on_time);
esp_zb_on_off_cluster_add_attr(onoff_attr_list, ESP_ZB_ZCL_ATTR_ON_OFF_GLOBAL_SCENE_CONTROL,&on_off_global_scene_control);
// .

_ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID, .app_device_version = 1};

// set default values
_current_state = false;
_current_level = 255;
}
`

And the ability to set the ZLL truct center key in ZigbeeCore.cpp
// allow joining the Philips Hue network(s) esp_zb_enable_joining_to_distributed(true); uint8_t secret_zll_trust_center_key[] = { // The Philips HUE Trust Center Key 0x81, ..., 0xB8 }; esp_zb_secur_TC_standard_distributed_key_set(secret_zll_trust_center_key);

I would also suggest changes to the Zigbee_Dimmable_light.ino and the color one too

`
#if !defined(ZIGBEE_MODE_ED) && !defined(ZIGBEE_MODE_ZCZR)
#error "Zigbee device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

#ifdef ZIGBEE_MODE_ZCZR
zigbee_role_t role = ZIGBEE_ROUTER; // or can be ZIGBEE_COORDINATOR
#else
zigbee_role_t role = ZIGBEE_END_DEVICE;
#endif
`

update role
// When all EPs are registered, start Zigbee in End Device mode if (!Zigbee.begin(role)) {

I can make an PR for that tomorrow, unless you just want to do it yourself which is fine, the only part I'm unsure on is a proper way to add an API for esp_zb_secur_TC_standard_distributed_key_set before stack startup.

@jaccobezemer
Copy link

@cpuchip We've figured it out. See my post of yesterday where I came up with the same conclusion😊

As for the app_device_version, there is already a methode for that:
zbDimmableLight.setVersion(1); // sets the app_device_version to 1, needed for Philips HUE
And there is one for setting the powersource: zbDimmableLight.setPowerSource(ZB_POWER_SOURCE_MAINS);

What we mis so far @P-R-O-C-H-Y, is what @cpuchip mentioned in the previous post.
To sum it up:
We need a configurable option to set
esp_zb_enable_joining_to_distributed(true);
esp_zb_secur_TC_standard_distributed_key_set(secret_zll_trust_center_key);

Also we need a way to change an attribute value to change these attributes:
esp_zb_on_off_cluster_add_attr(onoff_attr_list, ESP_ZB_ZCL_ATTR_ON_OFF_ON_TIME, &on_off_on_time); esp_zb_on_off_cluster_add_attr(onoff_attr_list, ESP_ZB_ZCL_ATTR_ON_OFF_GLOBAL_SCENE_CONTROL,&on_off_global_scene_control);

@cpuchip If you want to make a PR, please do. I'm happy to work on that with you.

@cpuchip
Copy link

cpuchip commented Mar 11, 2025

I'm still working on this, I have a branch on my fork of this repo: https://github.com/cpuchip/arduino-esp32/tree/feature/zigbee-tc-support

Sorry it's taking me longer to get to this then I thought, but I'm making progress.

@Parsaabasi Parsaabasi modified the milestones: 3.2.0, 3.3.0 Mar 12, 2025
@tomfrenzel
Copy link

@P-R-O-C-H-Y I wanted to try out the OTA functionality but it was not clear to me how i should create the OTA binary.
The image_builder_tool seems like it only works for esp-idf. But i want to create the OTA binary from my .ino file.

Is it even possible to do that?

@Ruedi177
Copy link

Ruedi177 commented Mar 21, 2025

@P-R-O-C-H-Y Thank you so much for adding Zigbee support to the Arduine IDE!
I have successfully connected my ESP32C6 to the Home Assistant using the Example script "Zigbee_Pressure_Flow_Sensor". I would like to adapt this script to report Power measurement to HA and the Pressure Sensor Value would work fine for this. The only problem I have is that I don't know how to change the unit of measurement from hPa to Watts. Would you be able to help me with this?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Status: In Progress ⚠️ Issue is in progress
Projects
Status: In Progress
Development

No branches or pull requests