zigpy / bellows

A Python 3 project to implement EZSP for EmberZNet devices
GNU General Public License v3.0
182 stars 86 forks source link

How to run Zigbee co-ordinator application based on ZM35X in Linux RPI4 platform #431

Open RoyAnupam opened 3 years ago

RoyAnupam commented 3 years ago

Hi, I am trying to build a Zigbee Co-Ordinator application in my RPI4 running Linux platform. I am planning to buy a ZM35XX Zigbee USB dongle for this purpose. [https://www.allicdata.com/products/zm3588s-usb/2914948.html]

But in my understanding, I would also need a Host software stack running on my RPI, in order to talk to the Zigbee USB module. I figured out that, there is EmberZNet Stack from SILabs which can be used for my purpose, but I don't have access to it currently. Then, I happened to bump into zigpy/bellows python based stack. Is it possible to run this bellows stack on RPI4 and run Zigbee Co-ordinator functionality in my ZM35XX USB module? Kindly share some insights.

Thank You very much in advance~

BR,

MattWestb commented 3 years ago

Zigpy / bellows runs on PI if you is having python 3.9 installed or in one docker container like HA is doing.

The question is if your USB dongle is running Silabs EZSP zigbee stack coordinator firmware (EZSP NCP) (one must for Bellows) or if its having the proprietary MeshConnect firmware.

Also with EZSP NCP firmware you can using it in all open systems that is supporting SIlcabs Zigbee chips like ZHA, Tasmota and Z2M.

We have getting firmware for EM357 and EM3581 but not for the EM3588 chip devices and its needs much knowledge plus licence for the zigbee stack (Silabs EZSP 100 $ some devs is having it) and IAR compiler that is costing over 3500 $ and its tricky compiling then support for the chip is dropped.

I think its better putting the money on one coordinator that is not flagged end off life for doing more serous things but i cant recommending Sonoff coordinators then they is having so much hardware problems (not calibrated radios from the factory that is one must and so on).

One alternative is one coordinator that is network connected and is using serial to net for communication. Its little more expensive but is working great (in ZHA).

USB dongles and PI-HAT with EFR32 chips is not so expensive and is working OK.

Adminiuga commented 3 years ago

Yes, you could, but you would need to add some code on top of bellows. Bellows per se is a low level library for EZSP protocol. This code exist as part of ZHA integration in Home Assistant Core. Take a look at zigpy/zigpy-cli as well

RoyAnupam commented 3 years ago

@MattWestb

The question is if your USB dongle is running Silabs EZSP zigbee stack coordinator firmware (EZSP NCP) (one must for Bellows)or if its having the proprietary MeshConnect firmware.

Okay, It means, the dongle must be pre-flashed with EZSP NCP firmware for bellows to be able to use it? I noticed link to update firmware in dongles in project Wiki page https://github.com/walthowd/husbzb-firmware So, it means, we have access to the EZSP NCP firmware's for the compatible radios, but, I was wondering whether any additional hardware is required to flash the firmware into the radio? Any idea?

Also with EZSP NCP firmware you can using it in all open systems that is supporting SIlcabs Zigbee chips like ZHA, Tasmota and Z2M.

Okay, got it. Actually, my intention was to use bellows as a standalone library instead of using HomeAssistant OS with ZHA integration.

USB dongles and PI-HAT with EFR32 chips is not so expensive and is working OK.

Okay I see. Does it work out of the box with bellows? Could you kindly share some Wiki info for above hardware?

Thank You very much

RoyAnupam commented 3 years ago

@Adminiuga

Yes, you could, but you would need to add some code on top of bellows. Bellows per se is a low level library for EZSP protocol. This code exist as part of ZHA integration in Home Assistant Core.

Thank you for your reply. Okay I got it. Actually, my intention was to use bellows as a standalone library instead of using HomeAssistant OS with ZHA integration. So If I understand correctly, I would need to develop some use case scenarios on top of bellows library (like Create Network, Permit Join, Add Device, Browse Endpoints, Control operations etc.) ? Please share your opinion. Thanks

BR,

Adminiuga commented 3 years ago

Yes, it is possible to be standalone, but you do have to add this layer on top and essentially implement what zha integration does. For example start the radio library, initialize radio, open network for joining, wait till a device joins and for example the if the device has an on_off cluster then present the user with a light bulb. And if the user clicks on the bulb, then send the toggle command to on_off cluster

MattWestb commented 3 years ago

In the Zigpy wiki you can also finding all adapters / firmware we have funding working with Bellows in the same page but under Recommended firmware versions for EZSP coordinators. EByte have proprietary firmware and need SWD probe for being flashed one time (new bootloader) all other is having one working bootlooader (if not written somthing else in the wiki) and can being updated with one terminal with X-Mode.

Small USB and PI-HAT i think only Elelabs have making good working ones. One link: https://elelabs.com/shop/ (can also being found on other market pleases like Amazon).

And updated firmware is made of the community and also updating program for users (linked in the wiki).

With PI-HAT its needed doing some extra setting in the PIs OS for getting hardware UART working OK but its easy made.

Edit: PI4 its important getting USB devices away from the USB-Zigbee dongle then the USB3 is making strong interference with Zigbee radio so normal one good extension cable is needed for getting the Zigbee dongle working OK.

RoyAnupam commented 3 years ago

Yes, it is possible to be standalone, but you do have to add this layer on top and essentially implement what zha integration does. For example start the radio library, initialize radio, open network for joining, wait till a device joins and for example the if the device has an on_off cluster then present the user with a light bulb. And if the user clicks on the bulb, then send the toggle command to on_off cluster

Thank you for sharing your suggestions! Do the https://github.com/zigpy/bellows github repo contain any command-line utility tool to do basic Zigbee Co-ordinator operations based on bellows library? I want to take reference for developing my own application

RoyAnupam commented 3 years ago

In the Zigpy wiki you can also finding all adapters / firmware we have funding working with Bellows in the same page but under Recommended firmware versions for EZSP coordinators. EByte have proprietary firmware and need SWD probe for being flashed one time (new bootloader) all other is having one working bootlooader (if not written somthing else in the wiki) and can being updated with one terminal with X-Mode.

Small USB and PI-HAT i think only Elelabs have making good working ones. One link: https://elelabs.com/shop/ (can also being found on other market pleases like Amazon).

Okay great. Thank you for sharing your suggestions. Can I use following Zigbee USB dongle with Bellows library? https://elelabs.com/products/elelabs-usb-adapter.html

And updated firmware is made of the community and also updating program for users (linked in the wiki).

With PI-HAT its needed doing some extra setting in the PIs OS for getting hardware UART working OK but its easy made.

Edit: PI4 its important getting USB devices away from the USB-Zigbee dongle then the USB3 is making strong interference with Zigbee radio so normal one good extension cable is needed for getting the Zigbee dongle working OK.

MattWestb commented 3 years ago

Some devs is / have using it and Elelabs have making one update utility for updating the firmware Elelabs EZSP Firmware Update Utility and also released updated firmware in the same git.

And the community have cooking more updated firmware for the device that is also working OK Compatible with Elelabs-ELU013 and ELR023.

I have seen one clone of this device on Amazon but i dont remember the name they was using.

RoyAnupam commented 3 years ago

Some devs is / have using it and Elelabs have making one update utility for updating the firmware Elelabs EZSP Firmware Update Utility and also released updated firmware in the same git.

And the community have cooking more updated firmware for the device that is also working OK Compatible with Elelabs-ELU013 and ELR023.

I have seen one clone of this device on Amazon but i dont remember the name they was using.

Okay sure. I got it. Thanks. Do the https://github.com/zigpy/bellows github repo contain any command-line utility tool to do basic Zigbee Co-ordinator operations based on bellows library? I want to take reference for developing my own application

MattWestb commented 3 years ago

https://github.com/zigpy/bellows/tree/dev/bellows/cli is the CLI part and you can getting online help like belows info --help.

I think most NCP ops is defined (but not all) in the application.py.

RoyAnupam commented 3 years ago

https://github.com/zigpy/bellows/tree/dev/bellows/cli is the CLI part and you can getting online help like belows info --help.

I think most NCP ops is defined (but not all) in the application.py.

Thank you very much!

Hedda commented 3 years ago

Before you do anything you really need to upgrade the firmware or by a newer adapter as EM35xx/EM35x ships will very old FW:

Read the discussion is this other issue about updating firmware on such old adapters -> https://github.com/zigpy/bellows/issues/348

Take a look at zigpy/zigpy-cli as well

As mentioned, also check out the new zigpy-cli at https://github.com/zigpy/zigpy-cli as maybe could extend that to fit your needs.

Actually, my intention was to use bellows as a standalone library instead of using HomeAssistant OS with ZHA integration.

A tip could be to also see the code from Jeedom Official Zigbee Plugin based on zigpy (access requires purchasing their plugin):

https://github.com/zigpy/zigpy/discussions/725

I am planning to buy a ZM35XX Zigbee USB dongle for this purpose.

Again, also as already mentioned, another tip is to not use a Zigbee coordinator with SoC that is end-of-life so buy newer hardware.

Silabs list ZM35XX as "Not Recommended for New Designs (NRND)" so try to find a newer dongle with EFR32MG12 or EFR32MG21.

I have seen one clone of this device on Amazon but i dont remember the name they was using.

POPP ZB-Stick and POPP ZB-Shield are OEM versions of Elelabs ELU013 and ELR023 sold in Europe (they are exact same hardware):

https://www.popp.eu/products/

https://elelabs.com/shop/

Alternative Silabs Zigbee coordinator hardware is Tube's Zigbee Gateways (Silicon Labs EFR32 variant) though stock is low:

https://github.com/tube0013/tube_gateways

https://www.tubeszb.com/shop/2

RoyAnupam commented 3 years ago

Take a look at zigpy/zigpy-cli as well

As mentioned, also check out the new zigpy-cli at https://github.com/zigpy/zigpy-cli as maybe could extend that to fit your needs.

Actually, my intention was to use bellows as a standalone library instead of using HomeAssistant OS with ZHA integration.

A tip could be to also see the code from Jeedom Official Zigbee Plugin based on zigpy (access requires purchasing their plugin):

zigpy/zigpy#725

I am planning to buy a ZM35XX Zigbee USB dongle for this purpose.

Again, also as already mentioned, another tip is to not use a Zigbee coordinator with SoC that is end-of-life so buy newer hardware.

Silabs list ZM35XX as "Not Recommended for New Designs (NRND)" so try to find a newer dongle with EFR32MG12 or EFR32MG21.

I have seen one clone of this device on Amazon but i dont remember the name they was using.

POPP ZB-Stick and POPP ZB-Shield are OEM versions of Elelabs ELU013 and ELR023 sold in Europe (they are exact same hardware):

https://www.popp.eu/products/

https://elelabs.com/shop/

Alternative Silabs Zigbee coordinator hardware is Tube's Zigbee Gateways (Silicon Labs EFR32 variant) though stock is low:

https://github.com/tube0013/tube_gateways

https://www.tubeszb.com/shop/2

Thank You very much for your kind reply & suggestions! I will check these in detail~

RoyAnupam commented 3 years ago

Hi, I have a basic question about Zigbee onboarding in Home Assistant setup. Actually, I never used HA, but, just being curios to know how it works! Does Zigbee 3.0 device onboarding mandate QR code for transferring the install code from Thing device to Trust Center device? I am not sure, if this is right forum to ask this question. But, if you have some insight about this, it will be highly appreciated.

MattWestb commented 3 years ago

ZHA is normally using the well known HA key for joining devices (Zigbee 1.x and 3) but its possible adding install code with services in HA for joining devices with ( have not trying it but some deva and user have using it). There is no GUI for scanning QR-codes but you can do it and pasting the code in the service and it shall working.

Hedda commented 3 years ago

There is no GUI for scanning QR-codes but you can do it and pasting the code in the service and it shall working.

Exactly, underlying support is there but there is no GUI or app for scanning QR codes to get install codes into Home Assistant, see:

https://community.home-assistant.io/t/request-qr-code-tags-scanning-for-joining-new-zigbee-3-0-device-to-home-assistant-zha-integration-component-via-ui-and-companion-apps/231185

https://github.com/home-assistant/core/pull/40652

RoyAnupam commented 3 years ago

Thank You @Hedda & @MattWestb for quick response... I understood that, even if ZHA has underlying support for QR code based install code addition, but, due to lack of GUI or camera app in HA, install code needs to be transferred from other companion device like Android /iPhone etc. Therefore, it means, without help of other companion app, it is basically impossible to onboard a newer Zigbee3 Devices with QR code support? Correct me if I a wrong.

But, I am wondering, how will any camera-less/scanner app less device onboard such newer Zigbee3.0 newer devices at all? If they always require companion devices like phones, it will be cumbersome and not easy for user. Do you know any other way to pass on the QR code from the Device to Trust Center by any other means? Is it possible? Please share your thoughts!

puddly commented 3 years ago

But, I am wondering, how will any camera-less/scanner app less device onboard such newer Zigbee3.0 newer devices at all?

A QR code is just one way encode the device's IEEE address and the install code. You could also ask the user to manually type in the hex-encoded IEEE address and install code, but I don't think many people will look forward to typing in 52 hexadecimal characters (plus some sort of checksum!) and then being asked to re-type everything when they inevitably make a transcription error.

That being said, you don't necessarily need to use the install code at all. It's used only to eliminate the brief window of opportunity for an attacker to sniff your global network key by encrypting it while it's being distributed to the joining device. Zigbee 3.0 devices will still join without using an install code.

MattWestb commented 3 years ago

Also possible using one QR app on one mobile / tablet and scanning the the code and copy it to the clip boar or sharing it with Bluetooth and also having HA in the mobile / tablet you can past the clipboard in HA service for adding install codes.

Edit: Ops the join_with_code was in custom component that not loading in the newer HA so i think its not working adding install codes in ZHA :-((

Hedda commented 2 years ago

FYI, the Z-Wave JS integration UI will soon implement a QR scanner in Home Assistant's frontend code that will be used for Z-Wave SmartStart provisioning (which is similar to Zigbee 3.0 device inclusion via QR code), and sounds as if that QR scanner component will be implemented as a separate part that could potentially be a reusable element that the ZHA UI could use for QR code scanning? More information is posted here -> https://github.com/zigpy/zigpy/discussions/857

Pmctst commented 1 year ago

@RoyAnupam

Hi I am starting with a development I think similar to what you tried to achieve. Did you finally created an application on top of Bellows library? Could you give me some tips about how to interact for creating a coordinator or a end device and managing messages.

I think I have understood how EZSP protocol works but I have not a clear view of how to develop an application on top of that. Should it be using callbacks?

Hedda commented 1 year ago

@Pmctst may be a little too late but check out the related question/request and answers/discussion here -> https://github.com/zigpy/zigpy/issues/1087

PS: First update firmware, so read the discussion is this other issue about updating firmware on such really old adapters -> https://github.com/zigpy/bellows/issues/348