XBee serial communication

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.

1 Like

Hello i need help,
i can´t detect in ZHA another xbee router…
I have a xbee s2c coordinator connected to ZHA. It works perfect with any zigbee product. But i cant connect other xbee for controling it´s IO pins.
If I scan devices in XCTU with router, i see the coordinator. But in adding router to ZHA was impossible.
I tried commmissioning button, and configure router with params:
CE=0
ZS=2
EE=1
EO=2
NK=0
KY=5a6967426565416c6c69616e63653039

I also tried using xbee ha platform, adding a light with router address like described here: ha xbee

Nothing worked…
Thanks!

Nothing worked…

Hi!

I only noticed your post now.

You are doing it correct. Once you configured these parameters, the module should start searching for the network. Go to Configuration → Integrations → ZHA > “Add device” to allow joining, then check XCTU again, at the very bottom you will see the section for Diagnostic commands. Refresh the AI parameter a few times and tell us which values it returns.
Sometimes it helps moving physically closer to the coordinator, or changing ZS to 0 and then back to 2 to trigger joining.

Hi Denis, Thank you for sharing details of your project here in HA. I’m new to HA and been to digi xbee forum but there are no examples for end device. Your configuration made my xbee detectable to the configurator!

Anyways my goal is to make an end device with power meter and relay switch to be controlled and displayed on HA. Upon trying the configurations on xbee, this controls (15), 2 analog outputs and 1 sensor binary input showed up. This board is just pre flashed with the latest xbee firmware and no micropython yet. I wonder where did those config files came from. I tried exploring XCTU but I cant see anything GPIO config related as far as I understand. And if you can point me to more resource in creating endpoint with xbee that would be great! TIA

Hi!

Probably the best source of information for now is this: zha-device-handlers/xbee.md at 4956114628a2aee435776c5e286a8e97d4f3df53 · zigpy/zha-device-handlers · GitHub
To put it simply, the on-off switches control digital output of XBee (or show you a digital input if configured so with XCTU). You will also have PWM as a number entity and analog input as sensors.
Now you need to connect your relays to the respective lines of XBee and that’s probably it. If you need a more complicated logic, you can use template sensor or template switch.

Thanks for the fast response! And great details on link! I appreciate it.