zigpy / zha

Zigbee Home Automation
Apache License 2.0
26 stars 23 forks source link

Example minimum viable ZHA gateway file #183

Open 97Cweb opened 2 months ago

97Cweb commented 2 months ago

Good morning I am trying to make my own zigbee network for a project I am working on. Due to this I need to have a gateway/router system. I have spent the better part of a day getting various zigbee libraries to load, only to end up here, at the one they all point to. I am hoping that I can make my project with this as the gateway, where I can send messages to a zigbee object through this.

THe issue I am facing is that there is no documentation and that the code, being so complex, is very difficult to parse. So far, I have only managed the following, which does not work, as I dont have the config parameter, which I don't know how to populate

from zha.application.gateway import Gateway
zbgateway = Gateway()

Any help would be greatly appreciated Thank you

dmulcahey commented 2 months ago

Documentation is on my list to work on soon. For now you can reference the HA component that leverages the library to see how things work together.

This shows how to set up the gateway and initialize the devices https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/__init__.py#L126

This shows the structure of the config object needed to create the gateway. https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/helpers.py#L1178

The ZHA integration in HA is a lot less complex than the code in the lib is. Hopefully this helps a bit. I'll try to set up a small self contained example outside of HA soon for you.

97Cweb commented 2 months ago

Thank you for this starting point! Between this and the robot (chatgpt) I was able to get a basic start going. I am waiting for my dev boards to come in, so I cannot go much farther right now, but here is a copy of what I made for your viewing and possible use as an example. Also, do you have an entry point for how to send commands over zigbee, or an intro to it? I have read conflicting info for it, one stating it is just serial send, another stating devices get made, that contain actions that then can have states, pretty much making a class object and interacting with that. Hopefully you can shed some light on this so I know where to proceed from here, as my project has me making custom devices and communicating through this. Thank you again!

On Wed, Aug 28, 2024 at 1:26 PM David F. Mulcahey @.***> wrote:

Documentation is on my list to work on soon. For now you can reference the HA component that leverages the library to see how things work together.

This shows how to set up the gateway and initialize the devices

https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/__init__.py#L126

This shows the structure of the config object needed to create the gateway.

https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/helpers.py#L1178

The ZHA integration in HA is a lot less complex than the code in the lib is. Hopefully this helps a bit. I'll try to set up a small self contained example outside of HA soon for you.

— Reply to this email directly, view it on GitHub https://github.com/zigpy/zha/issues/183#issuecomment-2315898150, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQO72O2OBDQYRAC6CQULZTYB3LAVCNFSM6AAAAABNILLCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJVHA4TQMJVGA . You are receiving this because you authored the thread.Message ID: @.***>

-- Collin Barker

97Cweb commented 2 months ago

Forgot the files, here they are

On Sat, Aug 31, 2024 at 1:54 PM Collin Barker @.***> wrote:

Thank you for this starting point! Between this and the robot (chatgpt) I was able to get a basic start going. I am waiting for my dev boards to come in, so I cannot go much farther right now, but here is a copy of what I made for your viewing and possible use as an example. Also, do you have an entry point for how to send commands over zigbee, or an intro to it? I have read conflicting info for it, one stating it is just serial send, another stating devices get made, that contain actions that then can have states, pretty much making a class object and interacting with that. Hopefully you can shed some light on this so I know where to proceed from here, as my project has me making custom devices and communicating through this. Thank you again!

On Wed, Aug 28, 2024 at 1:26 PM David F. Mulcahey < @.***> wrote:

Documentation is on my list to work on soon. For now you can reference the HA component that leverages the library to see how things work together.

This shows how to set up the gateway and initialize the devices

https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/__init__.py#L126

This shows the structure of the config object needed to create the gateway.

https://github.com/home-assistant/core/blob/af8131e68f95ebb33fdb9f0dbc826143fe323cab/homeassistant/components/zha/helpers.py#L1178

The ZHA integration in HA is a lot less complex than the code in the lib is. Hopefully this helps a bit. I'll try to set up a small self contained example outside of HA soon for you.

— Reply to this email directly, view it on GitHub https://github.com/zigpy/zha/issues/183#issuecomment-2315898150, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQO72O2OBDQYRAC6CQULZTYB3LAVCNFSM6AAAAABNILLCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJVHA4TQMJVGA . You are receiving this because you authored the thread.Message ID: @.***>

-- Collin Barker

-- Collin Barker

TheJulianJES commented 2 months ago

You cannot attach files on GitHub via email by the way. You need to do that in the web UI.

97Cweb commented 2 months ago

gatewaytest.zip sorry about that, here it is

dmulcahey commented 2 months ago

you can also peek at this: https://github.com/zigpy/zha-websocket-server/blob/dev/zhaws/server/__main__.py and this: https://github.com/zigpy/zha-websocket-server/blob/dev/zhaws/server/websocket/server.py#L32

this is an older attempt before we has the ZHA lib. This will be updated at some point to leverage the ZHA lib.

97Cweb commented 2 months ago

Hello again I got a sonoff plug on the gateway now, but I have no clue how to access it through the gateway. Can you provide an example for getting the device, endpoints, etc and how to send a message? Ideally there would be one for both a end device that consumes messages (like the plug) and for one that creates messages (like a switch) Thank you for your help

On Sun, Sep 1, 2024 at 5:08 PM David F. Mulcahey @.***> wrote:

you can also peek at this: https://github.com/zigpy/zha-websocket-server/blob/dev/zhaws/server/__main__.py and this: https://github.com/zigpy/zha-websocket-server/blob/dev/zhaws/server/websocket/server.py#L32

this is an older attempt before we has the ZHA lib. This will be updated at some point to leverage the ZHA lib.

— Reply to this email directly, view it on GitHub https://github.com/zigpy/zha/issues/183#issuecomment-2323497676, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQOYJFVJO3RTYS7YTFLTZUN66PAVCNFSM6AAAAABNILLCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRTGQ4TONRXGY . You are receiving this because you authored the thread.Message ID: @.***>

-- Collin Barker

dmulcahey commented 2 months ago

I guess help me understand what you are trying to accomplish? This project handles a bunch of what you are asking about…. If you want to see how you would interact with the objects provided by the lib you can peek at the ZHA integration in HA: https://github.com/home-assistant/core/tree/dev/homeassistant/components/zha

If you could explain what you are attempting to do I may be able to provide better assistance.

documentation is nearly non existent at the moment. We’ll get to it at some point as time allows 😬

97Cweb commented 2 months ago

What I am trying to do is get a gateway object to sit and collect devices which I allow in. My end goal is to make a train control system for N scale trains, so there will be a remote control throttle, and multiple trains, each with a zigbee chip in them. I want to send commands from the remote to the devices via the gateway, and would like to know how to do this, preferably by having the gateway act as a interface to the zigbee network so I can see the packets come in from the remote, and then create packets for the train, allowing for modifications to be done.

The way I am thinking is that the remote would send directions and speed along with train as sensor readings, the gateway would get these, do some processing on them and pass them as values to the train receiver.

All 3 components will be custom but will work on Zigbee. I also have a wall plug in there to turn on and off the entire layout without needing to unplug it. I want to know how to do this. If I was in wifi, I would be saving the ip address of each thing in the remote and forwarding it, but I would like the gateway to be more than just a black box relay.

A more programmatic example:

remote sends

{ train:1 direction:Forward power: 50% }

Gateway receives, sends out to the train the following

{ train: ieee_addr dir:True //False is backwards power:4096 //pwm out of 8192 }

This way the remote does not need to know which ieee_addr the train is, the gateway stores it.

Gateway also supports adding, removing multiples of these entities, and none of the devices care about each other, they all relay through this custom gateway.

Closest thing I can think of is the post command for http, where it takes in a json equivalent, does magic and then redirects you to a page of content based on the json input.

Hopefully this helps. Thank you for your patience, and I hope I can give this as an example of a gateway interface in time

On Wed, Sep 11, 2024 at 12:25 PM David F. Mulcahey @.***> wrote:

I guess help me understand what you are trying to accomplish? This project handles a bunch of what you are asking about…. If you want to see how you would interact with the objects provided by the lib you can peek at the ZHA integration in HA: https://github.com/home-assistant/core/tree/dev/homeassistant/components/zha

If you could explain what you are attempting to do I may be able to provide better assistance.

documentation is nearly non existent at the moment. We’ll get to it at some point as time allows 😬

— Reply to this email directly, view it on GitHub https://github.com/zigpy/zha/issues/183#issuecomment-2344120203, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQO2LSE4YSOCM6P4ERWLZWBVGNAVCNFSM6AAAAABNILLCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBUGEZDAMRQGM . You are receiving this because you authored the thread.Message ID: @.***>

-- Collin Barker

prairiesnpr commented 2 months ago

I don't think this is the appropriate library for the application you speak of. This is focused on Zigbee Home Automation, so devices like switches, lights, thermostats, etc. You honestly probably want something like the Digi Xbee platform, assuming you are set on Zigbee, where it will take care of the Zigbee side of things, and you can send serial packets back and forth. Adding all the complexity of the ZCL is going to be frustrating for such a simple application.

97Cweb commented 2 months ago

Ok, thank you for your help. Hopefully I can reuse something of my hardware. Have a good day

On Wed, Sep 11, 2024 at 1:55 PM prairiesnpr @.***> wrote:

I don't think this is the appropriate library for the application you speak of. This is focused on Zigbee Home Automation, so devices like switches, lights, thermostats, etc. You honestly probably want something like the Digi Xbee platform, assuming you are set on Zigbee, where it will take care of the Zigbee side of things, and you can send serial packets back and forth. Adding all the complexity of the ZCL is going to be frustrating for such a simple application.

— Reply to this email directly, view it on GitHub https://github.com/zigpy/zha/issues/183#issuecomment-2344329275, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQO4UFRQF3KOZ6HF5F4DZWB72DAVCNFSM6AAAAABNILLCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBUGMZDSMRXGU . You are receiving this because you authored the thread.Message ID: @.***>

-- Collin Barker

prairiesnpr commented 2 months ago

The other option would be to just use Home Assistant, we don't know what hardware you have, but if you can build an end device on it, then you would only have to worry about the train side.