espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.73k stars 7.43k forks source link

Implement Zigbee in Arduino #10135

Open P-R-O-C-H-Y opened 3 months ago

P-R-O-C-H-Y commented 3 months ago

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:

PR: https://github.com/espressif/arduino-esp32/pull/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

elgerg commented 3 months ago

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 commented 3 months ago

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

elgerg commented 3 months ago

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

P-R-O-C-H-Y commented 3 months ago

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 commented 3 months ago

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

elgerg commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

elgerg commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

Excellent. Thanks :)

P-R-O-C-H-Y commented 3 months ago

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

elgerg commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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

elgerg commented 2 months ago

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?

How is this? https://github.com/zigpy/zigpy/discussions/1162 Thanks

elgerg commented 2 months ago

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

This looks awesome!

Do you know when it'll end up in the next release? Thanks 🙏

Hedda commented 2 months ago

@P-R-O-C-H-Y Tip; here is a other Arduino library for creating Zigbee Home Automation devices (with links to some examples):

P-R-O-C-H-Y commented 2 months ago

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

This looks awesome!

Do you know when it'll end up in the next release?

Thanks 🙏

I am doing the best that the first version can be released soon.

P-R-O-C-H-Y commented 2 months ago

Dev Update 26/09/2024 - PR ready to be reviewed.

P-R-O-C-H-Y commented 1 month ago

The Zigbee library got merged! Now it's available in bothmaster and release/v3.1 branches. So in next release 3.0.6 and 3.1.0-rc2 it will be included.

lboue commented 1 month ago

Great job!

Abdull commented 1 month ago

awesome to hear!

I'm inexperienced what is required to implement software for Zigbee devices.

Having a look at directory https://github.com/espressif/arduino-esp32/tree/master/libraries/Zigbee/src/ep , do I deduce correctly that each "category" of Zigbee device type would require its own implementation files?

Maybe you can give hints how others could join?

P-R-O-C-H-Y commented 1 month ago

awesome to hear!

I'm inexperienced what is required to implement software for Zigbee devices.

Having a look at directory https://github.com/espressif/arduino-esp32/tree/master/libraries/Zigbee/src/ep , do I deduce correctly that each "category" of Zigbee device type would require its own implementation files?

Maybe you can give hints how others could join?

Hello @Abdull, take a look at the basics of the Zigbee protocol. You can find many sources and videos on the internet ;) As you noticed, Zigbee device can have 1 or more endpoints, which specify its type (light, sensor, switch, etc.). Each type need to have its own implementation as you found in the library (the link you posted). I am open on any suggestion what EPs to add in next updates and also I would be really happy to see a PR with any new EP support. As a reference you can take a look at the EPs I have added. For more details check the esp32-zigbee-sdk repository and sources there. But to be honest, it's not that simple to understand all the clusters, handlers etc. If anyone plan to add new EP type, I will be glad to help with any questions or development.

elgerg commented 1 month ago

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

If you're taking requests these are the sort of things I would like to see:

Human presence detector (PIR etc) Luminosity/Light sensor Time Client (get the current time from the coordinator) Battery monitoring Sleepy device

Thanks!

MeisterQ commented 1 month ago

Id also like to put a feature request:

P-R-O-C-H-Y commented 1 month ago

Id also like to put a feature request:

  • TRV support with stuff like external Temp sensor, window open, temperature setpoint, etc (like everything the Shelly TRV supports but only on zigbee)

Hi @MeisterQ, the TRV is just a thermostat. We have support for this type of endpoint. Also we have a temperature sensor endpoint supported as well. Just regular sensor for example for windows, doors, etc. is not yes supported. So if you plan to build your own TRV you can already start prototyping with the stuff we already have :)

Hedda commented 1 month ago

If you're taking requests these are the sort of things I would like to see:

Human presence detector (PIR etc) Luminosity/Light sensor Time Client (get the current time from the coordinator) Battery monitoring Sleepy device

Thanks!

FYI, there are more Zigbee examples in the esp32-zigbee-sdk repository which could probably be converted to this new API. See:

That includes examples for "deep sleep" and "light sleep" (standby) modes for Zigbee End Device:

As for Battery monitoring, I read note Arduino recently released an open-source Arduino Power Management library for Arduino Pro that could maybe be ported? It includes battery management and charger manager + sleep and standby mode

More on that here

Time Client looks to be missing, and I agree that Zigbee Time Client is needed to make a stand-alone smart thermostat or HVAC.

MeisterQ commented 1 month ago

Id also like to put a feature request:

  • TRV support with stuff like external Temp sensor, window open, temperature setpoint, etc (like everything the Shelly TRV supports but only on zigbee)

Hi @MeisterQ, the TRV is just a thermostat. We have support for this type of endpoint. Also we have a temperature sensor endpoint supported as well. Just regular sensor for example for windows, doors, etc. is not yes supported. So if you plan to build your own TRV you can already start prototyping with the stuff we already have :)

Thank you. That could be a start. None of the TRVs existing meet my requirements

gdivry commented 1 month ago

Thanks a lot for this incredible work Can I use the esp32c6 as a Zigbee coordinator with the lib ?

dpharris commented 1 month ago

Could README.md files be possibly added to the arduino-esp32/libraries /Zigbee/ directory, to the example directory, and/or the individual examples?

These would be very helpful to people new to this. They could also include actual or links to pictures and videos.

Thanks David

On Sun, Oct 13, 2024 at 9:09 AM gdivry @.***> wrote:

Thanks a lot for this incredible work Can I use the esp32c6 as a Zigbee coordinator with the lib ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

Message ID: @.***>

Hedda commented 1 month ago

Can I use the esp32c6 as a Zigbee coordinator with the lib ?

As I understand this is currently only to use ESP32-C6/ESP32-H2 as a ”Zigbee End Device” (ZED) or ”Zigbee Router” device (ZR) stand-alone nodes (i.e. standalone devices that can be added to an existing Zigbee network and then controlled via it), not as Zigbee Coordinator or Zigbee Gateway.

If you want a all-in-one Zigbee Gateway using ESP32 then can I suggest that you look into adding support for esp-zigbee-sdk support to Tasmota's sub-project called Zigbee2Tasmota (Z2T) which is currently only compatible with Silicon Labs and Texas Instruments as Zigbee Coordinator but it might give you ideas:

and

For refernce also check out the zigpy-espzb radio libraary for zigpy and their zha project which can now indirectly use a ESP32-H2 Zigbee Coordinator via zigpy-espzb via an hardware abstraction layer for the Zigbee radios CLI serial interface:

And

Hedda commented 1 month ago

Can I use the esp32c6 as a Zigbee coordinator with the lib ?

As I understand this is currently only to use ESP32-C6/ESP32-H2 as a ”Zigbee End Device” (ZED) or ”Zigbee Router” device (ZR) stand-alone nodes (i.e. standalone devices that can be added to an existing Zigbee network and then controlled via it), not as Zigbee Coordinator or Zigbee Gateway.

If you want a all-in-one Zigbee Gateway using ESP32 then can I suggest that you look into adding support for esp-zigbee-sdk support to Tasmota's sub-project called Zigbee2Tasmota (Z2T) which is currently only compatible with Silicon Labs and Texas Instruments as Zigbee Coordinator but it might give you ideas:

and

@s-hadinger to go off on a tangent with question above; what exact functions are still missing for this new Zigbee API for Arduino to potentially be useful for a Zigbee Gateway project like Zigbee2Tasmota (Z2T)?

s-hadinger commented 1 month ago

@s-hadinger to go off on a tangent with question above; what exact functions are still missing for this new Zigbee API for Arduino to potentially be useful for a Zigbee Gateway project like Zigbee2Tasmota (Z2T)?

I don't know, I have not checked. But there are no plans to port Z2T to H2/C6 due to the predominance of CC2652P and low number of devices using H2/C6. Also for the future, I expect Thread to progressively take over Zigbee. So I think we are well served with Zigbee as of today with both EFR32/CC2652P compatibility

P-R-O-C-H-Y commented 3 weeks ago

Another update for the Zigbee library -> PR #10551

P-R-O-C-H-Y commented 3 weeks ago

I have also did a power consumption test for the sleepy device. Sharing the picture of consumption when sleep was set to 30s, after wakeup, the connection was done, measured data and reported. Then back to sleep.

Screenshot 2024-10-25 at 14 44 24

You can see the average consumption was around 6mA. The more time the device will sleep the better power efficiency you can get.

tlanfer commented 1 week ago

This is great work, and i managed to get it to work immediately using a waveshare ESP32-C6 devkit board. I'm curious about the possiblities with sleep. One of the major reasons i'm using zigbee devices is when they need to run on low power. I have a bunch TRVs that run on battery at last a long time (months), yet respond to commands almost immediately (less than 5 seconds delay). My specific usecase is having a battery powered LED light that i only need to activate every now and then, but should not drain the battery when not in use. Zigbee would be perfect for this.

With deep sleep i'm getting a full reboot, and if i want reasonably quick response times i can only sleep for relatively short times. So i would assume i need some form of light sleep for that? Just wake up enough to check for commands and go back to sleep?

ggtimtom commented 1 week ago

I have an ESP32-H2 but only with 2MB of Flash. Will this also work?

ggtimtom commented 1 week ago

I want to build two sensors: A rain meter using a hallsensor an a magnet

A digital water meter: In my installed watermeter a little metalsheet is rotating. As a sensor i will use an geartoothsensor.

AndunHH commented 1 week ago

Thanks for the great work done here. As this whole feature is not jet finished, I'm hesitating to create a new issue. If this here is not the right spot, please give me a hint, where I should put it.

I succesfully used the example for the Switch and the on/off light with the given "light" example on a second seeed xiao esp32-c6 and with an ikea power outlet.

I tried to expand the example, because I don't want to bind a power outlet manually after every reset. I already found a similar ticket for the espressif SDK., that tells me, that this is already possible.

I changed the example to not wait in the setup() for a bound device. But then: nothing happens, because _is_bound = false in the follow up routings. If I bind the first light again, the whole switch starts working and also the formerly bound power outlet is switching as expected. (= the newly bound light and the power outlet are switching together)

Therefore, I assume, that during initialization the state of _is_bound is not correctly read from the memory, right? I'm was looking at https://github.com/espressif/arduino-esp32/blob/e99f1fdc6d12e07324be6e956318496e6a0bfac3/libraries/Zigbee/src/ZigbeeEP.cpp#L13 but at this point my knowdlege comes to an end. ...

Thanks for any hints how to solve this, or if this already known and planned. Or where I should open a individual ticket.

Hedda commented 6 days ago

@P-R-O-C-H-Y have you thought about maybe splitting Zigbee API for Arduino to make one part hardware-agnostic?

That is, breakout the Zigbee API from arduino-esp32 into its own separate library makes that hardware independent so that it could be reused by other projects with other Zigbee radio libraries, especially if they too have based their Zigbee stack on ZBOSS, such as example Nordic Semiconductor. With the point being that such a library would attract more Arduino developers that are interested in this Zigbee API but might want to instead make an implementation for a non-ESP32 based radio.

P-R-O-C-H-Y commented 4 days ago

This is great work, and i managed to get it to work immediately using a waveshare ESP32-C6 devkit board. I'm curious about the possiblities with sleep. One of the major reasons i'm using zigbee devices is when they need to run on low power. I have a bunch TRVs that run on battery at last a long time (months), yet respond to commands almost immediately (less than 5 seconds delay). My specific usecase is having a battery powered LED light that i only need to activate every now and then, but should not drain the battery when not in use. Zigbee would be perfect for this.

With deep sleep i'm getting a full reboot, and if i want reasonably quick response times i can only sleep for relatively short times. So i would assume i need some form of light sleep for that? Just wake up enough to check for commands and go back to sleep?

Hi @tlanfer, thanks for your feedback. The light sleep is not possible, as it needs the Power Management enabled and use the FreeRTOS tickless mode. We don't want to enable this settings for whole Arduino core, as it may bring unexpected behavior. If you really need the light sleep, you can use the ESP-IDF and the ESP-ZIGBEE-SDK directly. There is an example on how to use the light sleep :)

P-R-O-C-H-Y commented 4 days ago

Thanks for the great work done here. As this whole feature is not jet finished, I'm hesitating to create a new issue. If this here is not the right spot, please give me a hint, where I should put it.

I succesfully used the example for the Switch and the on/off light with the given "light" example on a second seeed xiao esp32-c6 and with an ikea power outlet.

I tried to expand the example, because I don't want to bind a power outlet manually after every reset. I already found a similar ticket for the espressif SDK., that tells me, that this is already possible.

I changed the example to not wait in the setup() for a bound device. But then: nothing happens, because _is_bound = false in the follow up routings. If I bind the first light again, the whole switch starts working and also the formerly bound power outlet is switching as expected. (= the newly bound light and the power outlet are switching together)

Therefore, I assume, that during initialization the state of _is_bound is not correctly read from the memory, right? I'm was looking at

https://github.com/espressif/arduino-esp32/blob/e99f1fdc6d12e07324be6e956318496e6a0bfac3/libraries/Zigbee/src/ZigbeeEP.cpp#L13

but at this point my knowdlege comes to an end. ... Thanks for any hints how to solve this, or if this already known and planned. Or where I should open a individual ticket.

Hi @AndunHH, thank you for your feedback. I will take a look on this issue with the _is_bound if I can see anything wrong there. The TODO comment is there for me, as I might transfer all those variables to not be a static if possible. If you have more info about that issue you have also with an example and steps how to reproduce it, please open a new issue and describe everything there. It will help a lot to have it separated, so we can discuss it there :)

P-R-O-C-H-Y commented 4 days ago

@P-R-O-C-H-Y have you thought about maybe splitting Zigbee API for Arduino to make one part hardware-agnostic?

That is, breakout the Zigbee API from arduino-esp32 into its own separate library makes that hardware independent so that it could be reused by other projects with other Zigbee radio libraries, especially if they too have based their Zigbee stack on ZBOSS, such as example Nordic Semiconductor. With the point being that such a library would attract more Arduino developers that are interested in this Zigbee API but might want to instead make an implementation for a non-ESP32 based radio.

Hi @Hedda, I was not thinking about that as I use the ESP-ZIGBEE-SDK underneath, which uses the ZBOSS. The main idea of Arduino APIs is to offer a similar approach to other Arduino interfaces. If users want to use ESP-IDF Zigbee APIs, that is still possible, they can just ignore the Arduino Zigbee APIs. This is valid for most of our Arduino APIs, actually, users can always use the ESP-IDF underneath. We don't have a goal of portability of our libraries, only to keep portability of user applications. But for sure other manufacturers can follow the same APIs, but the Implementation will depend on them.