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

a synopsis or template on how to use the zigpy-znp library #108

Closed
pitchoun38 opened this issue Dec 8, 2021 · 5 comments
Closed

a synopsis or template on how to use the zigpy-znp library #108

pitchoun38 opened this issue Dec 8, 2021 · 5 comments

Comments

@pitchoun38
Copy link

The zigpy-znp library looks very nice and I wonder if this could be use as a standalone library imported in a python3 code, without the all zigpy stack.

I got some hints from the interesting zigpy-cli project , and so far I'm able to open the communication with the Zigbee usb key. However, I'm struggling on how to send zigbee raw command and how to receive them.

For receiving messages, I guess that I need to create a listener, but not sure on which API it should rely on.

For sending messages, that should I use the request(), broadcast() or mrequest() depending of unicast, briadcast or multi-cast ?
is those API standard for each zigpy- ?

@puddly
Copy link
Collaborator

puddly commented Dec 8, 2021

Central documentation is unfortunately lacking at the moment so here are some links:

Sending messages is usually done through zigpy itself, since it takes care of constructing the ZCL/ZDO header and eventually calling ControllerApplication.request:

await device.endpoints[1].on_off.toggle()

@pitchoun38
Copy link
Author

pitchoun38 commented Dec 8, 2021

This looks very interesting and especially that one #709 thanks.

what is not clear for me is related to zipy- versus zigby stack. In other terms, can I develop a python application relying only on the zigpy- ?

What do you mean by "Received messages should be passed to handle_message." in #709 ? Do you mean we have to use add_listener() ? In that case the all zigpy stack mecanism came, correct ?

@puddly
Copy link
Collaborator

puddly commented Dec 8, 2021

In other terms, can I develop a python application relying only on the zigpy- ?

Yes. Zigpy on its own just handles ZCL and ZDO, it doesn't talk to any radios and expects a ControllerApplication subclass to implement this. You can use any library's ControllerApplication in the same way (bellows.zigbee.application.ControllerApplication, zigpy_deconz.zigbee.application.ControllerApplication, etc.).

zigpy-znp is dependent on zigpy and internally uses its structures, like zigpy.device.Device, so it's not possible to use standalone unless you want to directly talk to the Texas Instruments radio with zigpy_znp.api.ZNP and handle everything yourself. Each radio library has a different internal interface for communicating with its Zigbee chip, which is why ControllerApplication exists.

What do you mean by "Received messages should be passed to handle_message."

That linked document is explaining how to write a radio library to talk to a new USB coordinator, like zigpy-znp. It describes the internals. Zigpy implements handle_message but you can subclass ControllerApplication and replace all of this.

In that case the all zigpy stack mecanism came, correct ?

What portion of zigpy are you trying to avoid? If you configure it to use its SQLite database, it will store device NWK and IEEE addresses and when performing initialization, persist the node descriptor, endpoint descriptors, and model/manufacturer attribute values. That's about it. Binding, setting up attribute reporting, and actual device control is up to your application.

If you can describe what you're trying to do, I can maybe come up with a better example application that shows how to use zigpy.

As an example of a small, standalone command line tool that uses ControllerApplication, take a look at https://github.com/zigpy/zigpy-znp/blob/dev/zigpy_znp/tools/energy_scan.py

@Hedda
Copy link
Contributor

Hedda commented Dec 20, 2021

@pitchoun38 Is questions related to Domoticz-Zigate implementation of zigpy-znp and zigate-znp radio libraries discussed here:

zigpy/zigpy#865

At least it sounds as pipiche38 what to achieve the same thing in his Zigate plugin for Domoticz because that already have its own ZDO and ZCL layers which are working so believe he for now only want to partly use zigpy radio libraries for hardware abstraction.

You might also be interested in the somewhat related discussions here:

zigpy/zigpy#842

zigpy/zigpy#848

zigpy/zigpy#557

As well as be aware of zigpy-cli here:

https://github.com/zigpy/zigpy-cli

https://github.com/zigpy/zigpy-cli/pulls

https://github.com/zigpy/zigpy-cli/issues

@pitchoun38
Copy link
Author

Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants