zigpy / zigpy-xbee

A library which communicates with XBee radios for zigpy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception in callback when Aqara Human Motion Sensor detects motion

makuser opened this issue · comments

I'm using a S2B-Pro as coordinator.

2019-01-13 22:38:23 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback <bound method SerialTransport._read_ready of SerialTransport(<uvloop.Loop running=True closed=False debug=False>, <zigpy_xbee.uart.Gateway object at 0x7f60a6308d68>, Serial<id=0x7f60a6308f28, open=True>(port='/dev/zigbee', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False))>
Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 62, in uvloop.loop.Handle._run
  File "/usr/local/lib/python3.6/site-packages/serial_asyncio/__init__.py", line 106, in _read_ready
    self._protocol.data_received(data)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/uart.py", line 43, in data_received
    self.frame_received(frame)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/uart.py", line 48, in frame_received
    self._api.frame_received(frame)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/api.py", line 207, in frame_received
    getattr(self, '_handle_%s' % (command, ))(data)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/api.py", line 230, in _handle_explicit_rx_indicator
    self._app.handle_rx(*data)
AttributeError: 'NoneType' object has no attribute 'handle_rx'
2019-01-13 22:38:23 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback <bound method SerialTransport._read_ready of SerialTransport(<uvloop.Loop running=True closed=False debug=False>, <zigpy_xbee.uart.Gateway object at 0x7f60a6308d68>, Serial<id=0x7f60a6308f28, open=True>(port='/dev/zigbee', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False))>
Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 62, in uvloop.loop.Handle._run
  File "/usr/local/lib/python3.6/site-packages/serial_asyncio/__init__.py", line 106, in _read_ready
    self._protocol.data_received(data)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/uart.py", line 43, in data_received
    self.frame_received(frame)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/uart.py", line 48, in frame_received
    self._api.frame_received(frame)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/api.py", line 207, in frame_received
    getattr(self, '_handle_%s' % (command, ))(data)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/api.py", line 230, in _handle_explicit_rx_indicator
    self._app.handle_rx(*data)
AttributeError: 'NoneType' object has no attribute 'handle_rx'
  1. are you positive /dev/zigbee is the right serial port?
  2. What version of HA are you running?
  3. what do you have in zha: section of configuration.yaml
  4. can you enable debug level logging and put full log file of a HA start in hastebin?
1. are you positive `/dev/zigbee` is the right serial port?

Absolutely.

2. What version of HA are you running?

0.85.1 (sha256:76d41b752979225e50ba507545d6a4f701522ac2a30e00cf665b47f1ea1af4d8)

3. what do you have in `zha:` section of `configuration.yaml`
zha:
  database_path: /config/zigbee.db
  radio_type: xbee
  usb_path: /dev/zigbee
#  usb_path: rfc2217://10.22.0.53:2000
#  baudrate: 57600
  • concerning rfc2217 usb_path: too bad pyserial-asyncio has not been updated to work with rfc2217 addresses. Waiting for pyserial/pyserial#395 to be resolved.
  • concerning baud: I changed the baudrate in XCTU from 9600 to 57600 to have it use the default value. And yes, that's been verified to work.
4. can you enable debug level logging and put full log file of a HA start in hastebin?

Sure. https://pastebin.com/ADXJRtC4

I think /config/zigbee.db got messed up. I'm suspecting it happens when a device sends an attribute update prior Zigpy finishes device discovery. To me this was happening with Xiaomi devices.

2019-01-14 00:48:42 DEBUG (MainThread) [zigpy.appdb] Loading application state from /config/zigbee.db
2019-01-14 00:48:42 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry /dev/zigbee for zha
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/config_entries.py", line 252, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/app/homeassistant/components/zha/__init__.py", line 155, in async_setup_entry
    application_controller = ControllerApplication(radio, database)
  File "/usr/local/lib/python3.6/site-packages/zigpy_xbee/zigbee/application.py", line 15, in __init__
    super().__init__(database_file=database_file)
  File "/usr/local/lib/python3.6/site-packages/zigpy/application.py", line 25, in __init__
    self._dblistener.load()
  File "/usr/local/lib/python3.6/site-packages/zigpy/appdb.py", line 214, in load
    dev = self._application.get_device(ieee)
  File "/usr/local/lib/python3.6/site-packages/zigpy/application.py", line 116, in get_device
    return self.devices[ieee]
KeyError: 00:15:8d:00:02:b9:58:1e
2019-01-14 00:48:42 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=zha>

To clean up you need to use sqlite and clean any references to ieee='00:15:8d:00:02:b9:58:1e' in all tables. (or if it was your only single device, just delete zigbee.db)
in sqlite /config/zigbee.db run the following

  • delete from attributes where ieee='00:15:8d:00:02:b9:58:1e';
  • delete from output_clusters where ieee='00:15:8d:00:02:b9:58:1e';
  • delete from clusters where ieee='00:15:8d:00:02:b9:58:1e';
  • delete from output_clusters where ieee='00:15:8d:00:02:b9:58:1e';
  • delete from endpoints where ieee='00:15:8d:00:02:b9:58:1e';
  • delete from devices where ieee='00:15:8d:00:02:b9:58:1e';

PS: and make you you install github master tree version of zigpy-xbee, as the one published to PyPi had a bug which may reset coordinator on every hass restart.

To clean up you need to use sqlite and clean any references to ieee='00:15:8d:00:02:b9:58:1e' in all tables. (or if it was your only single device, just delete zigbee.db)

I did that and then I also got the latest commit on master branch and restarted hass. See the result below.

PS: and make you you install github master tree version of zigpy-xbee, as the one published to PyPi had a bug which may reset coordinator on every hass restart.

#22 (comment)

@makuser Could you try https://github.com/Adminiuga/zigpy-xbee/tree/fixes/s2b-at-cmd-fix branch?
But before trying, with XCTU please make sure you have the following parameters/values:

EE = 1
EO = 2
ZS = 2

otherwise the new branch will form a new network. For me, zigpy_xbee==0.1.0 did not form the network correctly, because association status was 0 and NWK was also 0x0000 because S2B module had coordinator API firmare installed. This new PR additionally checks for correct Zigbee Profile and Encryption enabled & Encription Options causing new network formation if any of the above are not configured correctly.

@Adminiuga
Seems that changes on s2b-at-cmd-fix branch, are working for me with S2B module.
Can we expect, this fix to go in future releases, or it's heavily experimental?
Here is my zha config:

zha:
  radio_type: xbee
  usb_path: socket://xbee:2323
  baudrate: 115200
  database_path: /config/zigbee.db

I can control my TRADFRI bulb E27 CWS opal, but when it's turned off from main switch, still is displayed as 'on' in HA ui.
TRADFRI remote control is shown in integrations, but it's binary sensor is alwas 'off', whatever I do on it.
I'm quite new with 'zha' at HA side, so probably I miss somthing.

@jonudewux thank you for the feedback. I'll create PR and push the changes upstream. You may have to install zigpy-xbee from github, until we get a new version of it published to PyPi.

@Adminiuga

What about remote controller and motion sensor, is it expected behaviour, is a issue, can you comment?

Xiaomi devices are tricky to get discovered completely, because they stop polling their parent device for new data, unless you keep pressing the button. But, pressing the button sends an attribute report which causes #21 (comment) upon restart and is being tracked in zigpy/zigpy#123
Please provide exact model for remote and motion sensor and whether those are discovered completely or not. You may have to make a few attempts. If you restart HA with an incomplete discovery, then you may have to clean up the DB.

#21 (comment) problem is fixed in zigpy/zigpy#137 and is likely the root cause. Closing this issue due to inactivity.