Home Assistant Community

XBee serial communication

Tags: #<Tag:0x00007fcf539f6738>


I have a ZigBee network for sensors controlled by an XBee S2C module with ZHA component.
I also have another XBee S2C device that controls a relay. In order to open or close the relay I must send arbitrary bytes to it from the XBee module over UART, i.e. 0x65 to open the relay and 0x6F to close it.
According to the XBee specs (https://www.digi.com/resources/documentation/digidocs/pdfs/90002002.pdf) I must issue an API command (0x10 Transmit Request frame) from the coordinator device (which is controlled by HA).

My problem is that I don’t know how to do it from HA, and even don’t know where start looking.

I guess it is not supported out-of-the-box and I probably need to write a custom module providing the service and probably customize zigpy or zha-quirks or whatever, but I need your advice on where to start, because I am not really familiar with all these stuff yet.


How is the relay connected to the xbee and is the second xbee currently joined to the network?


The relay is connected to the xbee with UART ( http://www.tinyosshop.com/index.php?route=product/product&product_id=595 , http://www.tinyosshop.com/datasheet/TOSR0X-T%20User%20Manual.pdf ).
Yes, it has joined the network already.


Ok, I’m not certain that it’s possible to send arbitrary bytes through the xbee UART in API mode. It may be, but it’s not something I have researched. If it is, you will likely need to build a quirk and probably add the required functionality to zigpy_xbee.

Another option would be to use the DIO pins on the xbee directly, I’m doing that now and am in the process of PRing to zhaquriks https://github.com/dmulcahey/zha-device-handlers/pull/73 This would require you to change relays, I’ve driven 3.3v SSRs directly from the DIO pins without issue.

The other option would be to add a microcontroller and have the device join as a ZHA device. You could then have the microcontroller output the required bytes. This is a project where I am using that method. https://github.com/prairiesnpr/QuadGarageDoorController It’s actually controlling 4 relays, but instead of switching a digital output, you could transmit via the UART.


Thank you!
I can see you are using remote_at_request. I believe I can use tx or tx_explicit to send UART data, without modification of zigpy_xbee.
Besides the quirks, do I need to change anything in HA itself to add a switch or service or sensor based on that quirk?


No, HA will create the appropriate entities based on the endpoints. That quirk looks like this when joined.

just edit the replacement endpoint list to match your relay.


Well, I’ve tried that and it works, I can send any data on my coordinator (API mode) and the end device (xbee transparent mode) just prints it to UART. Here is a quick and dirty code that tests the idea, when I flip a switch on or off, it prints ‘d’ or ‘n’: https://github.com/Shulyaka/zha-device-handlers/tree/xbee_dio2

Now, I am thinking on how to do it in a more generic way to be useful for others. Obviously, I don’t want to hardcode TOSR0X commands into xbee zhaquirk because xbee could be connected to a wide range of devices. I think of it as a device that has a service, and any module could call the service with arbitrary data. Any switches or sensors communicating to xbee could be built on top of that service.
This is where I got stuck. I don’t know how to write a zhaquirk that provides a service. Which device type should I use? Are there any other devices out there that require arbitrary data to be sent by HA?