WebThingsIO / zigbee-adapter

Zigbee adapter add-on for WebThings Gateway
Mozilla Public License 2.0
46 stars 29 forks source link

Zigbee things only work on a second click #322

Open evert opened 2 years ago

evert commented 2 years ago

At home I have a Webthings gateway (on raspberry pi). This pi has a zigbee adapter, and I have a couple of lights and switches.

When I click any 'thing' it typically does not respond. It almost feels like it takes a few minutes after interacting with it to 'wake up', after which they do work when turning on/off. This is very reliable, so when I use the gateway, I:

  1. Click the thing (nothing happens)
  2. Wait 30s - 1minute
  3. Click it again (it now turns on)

This is a bit frustrating, but it also means that my scheduled things (like turning on a light at a certain time of the day) typically doesn't work. My theory is that the events trigger the switches one, and then doesn't' try again after the 'wake up'.

I dusted off my Pi recently after not having used it for 10ish months, but I don't think this was ever an issue before.

This appears in my logs:

2021-11-08 16:21:11.223 ERROR  : zigbee-adapter: /home/pi/.webthings/addons/zigbee-adapter/lib/driver/conbee.js:338
2021-11-08 16:21:11.223 ERROR  : zigbee-adapter:                 value = value.toString(16).padStart(8, '0');
2021-11-08 16:21:11.224 ERROR  : zigbee-adapter:                               ^
2021-11-08 16:21:11.225 ERROR  : zigbee-adapter: 
2021-11-08 16:21:11.226 ERROR  : zigbee-adapter: TypeError: Cannot read property 'toString' of undefined
2021-11-08 16:21:11.227 ERROR  : zigbee-adapter:     at ConBeeDriver.dumpParameters (/home/pi/.webthings/addons/zigbee-adapter/lib/driver/conbee.js:338:31)
2021-11-08 16:21:11.227 ERROR  : zigbee-adapter:     at ConBeeDriver.run (/home/pi/.webthings/addons/zigbee-adapter/lib/driver/index.js:662:26)
2021-11-08 16:21:11.228 ERROR  : zigbee-adapter:     at ConBeeDriver.waitTimedOut (/home/pi/.webthings/addons/zigbee-adapter/lib/driver/index.js:719:22)
2021-11-08 16:21:11.229 ERROR  : zigbee-adapter:     at ontimeout (timers.js:436:11)
2021-11-08 16:21:11.230 ERROR  : zigbee-adapter:     at tryOnTimeout (timers.js:300:5)
2021-11-08 16:21:11.231 ERROR  : zigbee-adapter:     at listOnTimeout (timers.js:263:5)
2021-11-08 16:21:11.231 ERROR  : zigbee-adapter:     at Timer.processTimers (timers.js:223:10)
2021-11-08 16:21:11.246 INFO   : Plugin: zigbee-adapter died, code = 1 restarting after 30000
benfrancis commented 2 years ago

Thanks for the bug report @evert.

Some Zigbee devices do go to into sleep mode, but it's usually battery powered devices rather than mains powered devices which do that.

The error looks like there might be a bug in the Zigbee adapter which is worth investigating so I've moved the issue to the zigbee-adapter repository.

It might help if you provide the model numbers of the devices you're using as this may be difficult to reproduce.

evert commented 2 years ago

Some Zigbee devices do go to into sleep mode, but it's usually battery powered devices rather than mains powered devices which do that. The error looks like there might be a bug in the Zigbee adapter which is worth investigating so I've moved the issue to the zigbee-adapter repository.

Yeah my intuition is that this is not a sleep issue, especially since it switches to a 'broken' state relatively quickly after the plugin is restarted. Also worth noting that this used to never be a problem, and I've been a Webthings Gateway user for 2ish years.

The dongle is a Conbee II, this is my output from usb-devices:

T:  Bus=01 Lev=03 Prnt=03 Port=02 Cnt=02 Dev#=  8 Spd=12  MxCh= 0
D:  Ver= 2.01 Cls=02(commc) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=1cf1 ProdID=0030 Rev=01.00
S:  Manufacturer=dresden elektronik ingenieurtechnik GmbH
S:  Product=ConBee II
S:  SerialNumber=DE1963954
C:  #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=100mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=01 Driver=cdc_acm
I:  If#=0x1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm

If there is a way I can assist with this, let me know! It makes webthings very hard to use right now, because a lot of what I do is based on events & timers.

evert commented 2 years ago

So I've started hacking in the conbee.js file and I managed to stop it from crashing. Probably entirely in a bad way, maybe by ignoring an underlying problem.

There are 2 places in conbee.js where there's a block like

if (paramId == C.PARAM_ID.SCAN_CHANNELS) {
  value = value.toString(16).padStart(8, '0');
}

This fails because in my case value is sometimes undefined. I changed this to:

if (paramId == C.PARAM_ID.SCAN_CHANNELS && value) {
  value = value.toString(16).padStart(8, '0');
}

This stops the zigbee adapter from crashing every minute. I have no idea if this is an appropriate fix though. The 2 places where I had to do this was in asDeviceInfo and dumpParameters.

Happy to submit this as a PR too, but I don't know if there's additional adverse effects.