-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[nrf52, zigbee] zigbee binary_sensor, switch and time #7340
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
base: dev
Are you sure you want to change the base?
Conversation
Hey there @tomaszduda23, CODEOWNERS = ["@tomaszduda23"] And run (message by NeedsCodeownersLabel) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #7340 +/- ##
=======================================
Coverage 59.94% 59.94%
=======================================
Files 50 50
Lines 10293 10294 +1
Branches 1381 1381
=======================================
+ Hits 6170 6171 +1
Misses 3762 3762
Partials 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Nice! And what about ZHA? Will it work by default? |
It implements binaryinput/binaryoutput from https://csa-iot.org/wp-content/uploads/2022/01/07-5123-08-Zigbee-Cluster-Library-1.pdf. It might work. I've not tested it with ZHA. |
There is some implementation in ZHA https://www.home-assistant.io/integrations/binary_sensor/. Both clusters seems to be implemented in zigpy https://github.com/zigpy/zigpy/blob/f1dddb45d6e7e0cc8a6fb4a0098a9b33149cf024/zigpy/zcl/clusters/general.py#L1539 https://github.com/zigpy/zigpy/blob/f1dddb45d6e7e0cc8a6fb4a0098a9b33149cf024/zigpy/zcl/clusters/general.py#L1572. If someone has setup it would be worth to take a shot. |
I have ZHA and many Xiaomi/Aqara zigbee sensors. Have bunch of unused nrf5240 modules, just have no clue how to setup this whole nrf52 thing. Probably I have to wait until it is fully merged... |
@tomaszduda23 are you following this related "zigbee_esphome" (Zigbee component) project by @luar123 for ESPHome here? |
Oh, and i addition to that, FYI, be aware Espressif developer P-R-O-C-H-Y is now working on a new Zigbee Wrapper library with a simpler API in Arduino (for arduino-esp32) and he wrote that other developers can post additional feature request related to that in the same issue there for tracking. Maybe you could make use of the same Zigbee API? |
I've seen that. You can do more with it. It seems to be lower level implementation since it requires defining clusters in yaml. My goal was to make it easy to use. Most users don't want to understand what is the difference between cluster, attribute etc.
Looking on provided examples Espressif API looks different from Nordic. From user point of view it could be the same. c++ implementation would have to be done twice. |
FYI, while ZHA does expose much by default I believe that the ZHA integration does not expose all that zigpy supports, especially not for binary sensors, but instead generally only exposes the bare essentials for each supported platform in order to try to not overwhelmn the end user, however if something is not exposed then you can expand the sensors that it exposes by default in the main zha library which contain their Zigbee Gateway implementation, check out: and If most of it is exposed there then it is possible to finetune device quirks by writting a custom ZHA Device Handler using the unique device signature to identify specific devices: https://github.com/zigpy/zha-device-handlers PS: I think Zigbee2MQTT works very differently in that it instead does not expose anything by default so you more less always need to write a custom sevice handler which they call converters (see zigbee-herdsman-converters): https://www.zigbee2mqtt.io/advanced/support-new-devices/01_support_new_devices.html |
I've not look into ZHA integration much. I don't have HW to setup another coordinator to test how it works. I could flash nrf52840 with coordinator firmware. The setup looks time consuming though. I hope it gets merged at some point zigpy/zigpy#394.
There is auto generation which works e.g. with genOnOff. I might add auto discovery for other types Koenkk/zigbee2mqtt#23708. |
FYI, the zigpy-zboss (ZBOSS radio library for zigpy) project which enable using ZBOSS NCP firmware as Zigbee Coordinator in zha is actually quite far along now so the setup should not be as time consuming description in the old issue you linked to, instead check out this repo: The latest release should be fully usable: Though because zigpy-zboss is still experimental and not yet included by default in ZHA you do however need to add it to the zha library (ZHA’s Zigbee Gateway implementation) and then manually make Home Assistant core use that patched version instead: PS: I have keep up with that zigpy-zboss project myself and have ongoing progress summeries if interested in the longer back-story of that project here, which also contains user discussion on how to setup: |
It would be great to install experimental version by HACS. Patching core is not for average user 😄 I might take a look later on. |
If Koenkk/zigbee-herdsman-converters#7913 gets merge it would be discover without external converters. |
I agree and that and other related ideas was requested and discussed in these: |
For me the ideal zigbee implementation would be like api or mqtt. Just define sensors/lights/etc and the translation to zigbee clusters is handled automatically. That is of course a lot of work to implement and I am lacking time and esphome knowledge to do that. So my approach is more flexible but not user friendly, whereas you are targeting a few use-cases that are easy to use. I hope that my approach will lead to a full mqtt-like implementation at some point.
Although low level apis are similar because both use zboss, details are different, so I don't think a common low level code base is easy to do. But what we should consider is that there will be multiple hardware implementations for zigbee. For example we both use zigbee as a component name. |
That sounds like what @ffenix113 is trying to achieve with his ESPHome inspired non-esphome project (which is also for nRF52): |
That was my idea too at the beginning. How would you like to do so? I can see two possibilities:
Mine could be done on top of yours as long as you allow to define ZCL clusters. I was thinking about generating everything in python similar to yours but it was just easier to use things which are already defined in nrf-sdk. |
I would stick to standard ZCL clusters wherever possible and add custom clusters for not supported functions. With this also binding to other devices would work. I think it is even possible to add custom attributes to default clusters, but then you still need a converter for z2m. For z2m converters could be added upstream or esphome could generate custom files for each device.
At the moment my implementation depends on esp, I don't think there is much to share. Basically an intermediate abstraction layer would be needed. (But don't expect much development from my side, I am not working at this at the moment, just sharing ideas) |
What sounds like a good compromise would be to use standard ZCL clusters as much as possible and create a set of custom clusters for not supported functions that is standardized for ESPHome so can reuse the same converter in Zigbee2MQTT and same for ZHA Device Handler (zha-quirk) for translation without having to new converter or device handler for each new device created. Also note that ZHA recently added support for ZHA Device Handlers version 2 (ZHA-Quirks V2) architectural design which enable writing dynamic device handlers for ZHA: |
FYI; ZHA developers are working on AnalogInput and MultistateInput clusters for their "zha" Zigbee Gateway implementation:
@prairiesnpr do you happen to know if zha will dynamically support both BinaryInput and BinaryOutput clusters this way? |
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#7340
components: [zigbee, zigbee_ctx]
refresh: 1h (Added by the PR bot) |
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#7340
components: [zigbee, zigbee_ctx]
refresh: 1h (Added by the PR bot) |
To use the changes in this PR: # Clone the repository:
git clone https://github.com/esphome/esphome
cd esphome
# Checkout the PR branch:
git fetch origin pull/7340/head:nrf52_zigbee
git checkout nrf52_zigbee
# Install the development version:
script/setup
# Activate the development version:
source venv/bin/activate Now you can run (Added by the PR bot) |
To use the changes in this PR: # Clone the repository:
git clone https://github.com/esphome/esphome
cd esphome
# Checkout the PR branch:
git fetch origin pull/7340/head:nrf52_zigbee
git checkout nrf52_zigbee
# Install the development version:
script/setup
# Activate the development version:
source venv/bin/activate Now you can run (Added by the PR bot) |
To use the changes in this PR: # Clone the repository:
git clone https://github.com/esphome/esphome
cd esphome
# Checkout the PR branch:
git fetch origin pull/7340/head:nrf52_zigbee
git checkout nrf52_zigbee
# Install the development version:
script/setup
# Activate the development version:
source venv/bin/activate Now you can run (Added by the PR bot) |
To use the changes in this PR: # Clone the repository:
git clone https://github.com/esphome/esphome
cd esphome
# Checkout the PR branch:
git fetch origin pull/7340/head:nrf52_zigbee
git checkout nrf52_zigbee
# Install the development version:
script/setup
# Activate the development version:
source venv/bin/activate Now you can run (Added by the PR bot) |
To use the changes in this PR: # Clone the repository:
git clone https://github.com/esphome/esphome
cd esphome
# Checkout the PR branch:
git fetch origin pull/7340/head:nrf52_zigbee
git checkout nrf52_zigbee
# Install the development version:
script/setup
# Activate the development version:
source venv/bin/activate Now you can run (Added by the PR bot) |
@jesserockz the related PR #6075 was closed and locked by you without any comments, was that a mistake or on purpose? |
I've already opened new PR for tracking. The old one may stay closed #9736 |
@tomaszduda23 nice! Suggest you update the old PR with a link to the new PR for reference. |
It is closed. I cannot edit anymore. |
I closed it because we don't use prs to track other pr progress. Use a feature request discussion for that please. Everytime you update such a pr, it takes up the CI runners |
@tomaszduda23 could nrf52/nrf52840 with this component be able to do ESPHome firmware image update via Zigbee OTA update (Zigbee OTAU provider) via Home Assistant’s ZHA integration if that is used as the Zigbee Gateway? |
It looks interesting. |
What does this implement/fix?
Note: for adafruit bootloader check:
This requires #7049. It adds zigbee switch and binary_sensor. Tested with zigbee2mqtt 1.40.0. Up to 8 components is supported due to endpoint limit on nrf52840. Endpoints could be reused but it requires extra implementation. Entities names are auto discovered by home assistant.
zigbee_demo.mp4
Related items:
Specification:
https://csa-iot.org/wp-content/uploads/2022/01/07-5123-08-Zigbee-Cluster-Library-1.pdf
Types of changes
Related issue or feature (if applicable): fixes
esphome/feature-requests#1397
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#
Test Environment
Example entry for
config.yaml
:Alternative config: #7340 (comment)
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: