This may be of interest as another approach to manage relays.
My relays are controlled via i2c, but I presume you could make some changes to communicate via serial port from micropython on xbee3. I used Grove 4 / 8 channel SPDT relay via i2c
I wanted to use standard zigbee onoff endpoints to control relay. The latest version of xbee3 firmware (100A) now supports pass through of zdo to micropython. I use micropython to change the ZDO responses for Active_EP_req and Simple_Desc_rsp at the time that the xbee3 joins the HASS network. It sends a simple descriptor for each endpoint, indicating a simple OnOff (cluster id 0x06). Once set up, it:
- responds to on and off commands at the relevant endpoints by activating my relays over i2c
- responds to attribute requests to send current on/off status to HASS.
- it publishes reporting messages to act as a heartbeat and refresh current on/off statusās to HASS
I use the micropython which is supported on xbee3 to do this. I guess it could also be done with arduino or similar.
I have published the code I used for this at (https://github.com/petertrain/xbee3-i2c-relay).
I have copied and ported a fair amount of code for handling the zigbee communications from zibpy. I ran into two issues:
- I ran out of memory on the xbee3
- some of the standard python libraries used by zigpy arenāt supported on micropython (notably lib/enum).
As a result, I have butchered the zigpy code a fair amount to get it working. At times, I hardcoded encoded values instead of providing meaningful types. I might go back and try to clean some of that up.
The nice thing about this solution is that you donāt require use of quirks or any configuration in HASS to get it working. I just join the xbee3 with appropriate micropython module to the network and HASS is immediately configured to control the relevant relays.