doudz / homeassistant-zigate

zigate component for Home Assistant
MIT License
48 stars 13 forks source link

zigate.attribute_updated broken #123

Closed biau closed 4 years ago

biau commented 4 years ago

Hi,

Since I've updated hass and zigate to latest version I have an issue with nodered, it looks like the events node loose the connection with zigate.attribute_updated event. It works for some time and then stop with no reason. The only message relevant in nodered is : Received event for unknown subscription 3. Unsubscribing. (with no timestamp)

I can see that nodered is still connected to hass because I still receive events from other events: image

It looks like the zigate send something wrong. I'll try to find in debug logs.

found it I think:

020-07-07 10:13:41 DEBUG (ZiGate-Listen) [zigate] Raw packet received, b'\x01\x81\x02\x12\x02\x107D&\x82\xa9\x02\x11\x02\x10\x02\x10\xff\x02\x11\x02\x10B\x02\x10*\x02\x11!\xc7\x02\x1b\x02\x13(\x14\x02\x14!\xa8C\x02\x15!`\x02\x10\x02\x16$\x02\x13\x02\x10\x02\x10\x02\x10\x02\x10\x02\x1a!,\xaa\x97!\x02\x10\x02\x10\x98!\xff\x12\x99!\x1f\x11\x9a!\x02\x14\x02\x10T\x03' 2020-07-07 10:13:41 DEBUG (ZiGate-Event Loop) [zigate] Dispatch ZIGATE_PACKET_RECEIVED 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Received response 0x8102: b'2682a9010000ff010042002a0121c70b0328140421a84305216000062403000000000a212caa972100009821ff1299211f119a210400' 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] RESPONSE 0x8102 - Individual Attribute Report : sequence:38, addr:82a9, endpoint:1, cluster:0, attribute:65281, status:0, data_type:66, size:42, data:0121c70b0328140421a84305216000062403000000000a212caa972100009821ff1299211f119a210400, lqi:84 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Dispatch ZIGATE_ATTRIBUTE_UPDATED 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Handle special xiaomi attribute {'endpoint': 1, 'cluster': 0, 'addr': '82a9', 'attribute': 65281, 'data': '0121c70b0328140421a84305216000062403000000000a212caa972100009821ff1299211f119a210400', 'name': 'xiaomi', 'type': <class 'dict'>, 'value': {1: 3015, 3: 20, 4: 17320, 5: 96, 6: b'\x03\x00\x00\x00\x00', 10: 43564, 151: 0, 152: 4863, 153: 4383, 154: 4}} 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Acquire Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Release Lock on device LUMI lumi.sensor_cube.aqgl01 (82a9) 00158d00028794e5 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Dispatch ZIGATE_ATTRIBUTE_UPDATED 2020-07-07 10:13:41 DEBUG (ZiGate-Decode data) [zigate] Dispatch ZIGATE_RESPONSE_RECEIVED 2020-07-07 10:13:41 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event zigate.attribute_updated[L]: endpoint=1, cluster=0, addr=82a9, attribute=65281, data=0121c70b0328140421a84305216000062403000000000a212caa972100009821ff1299211f119a210400, name=xiaomi, type=dict, value=1=3015, 3=20, 4=17320, 5=96, 6=b'\x03\x00\x00\x00\x00', 10=43564, 151=0, 152=4863, 153=4383, 154=4, ieee=00158d00028794e5, device_type=lumi.sensor_cube.aqgl01, entity_id=zigate.00158d00028794e5> 2020-07-07 10:13:41 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140411556462160] Unable to serialize to JSON. Bad data found at $.event.data.value.6=b'\x03\x00\x00\x00\x00'(<class 'bytes'>

pawelka commented 4 years ago

I also face the same problem and started looking for a reason.

csacre commented 4 years ago

I have the same issue (leading to AppDaemon 4 to disconnect from Hassio).

2020-07-08 03:24:43 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event zigate.attribute_updated[L]: endpoint=1, cluster=0, addr=1a26, attribute=65281, data=0121db0b0421a81305210700062402000000006429be086521db180a210000, name=xiaomi, type=dict, value=1=3035, 4=5032, 5=7, 6=b'\x02\x00\x00\x00\x00', 100=2238, 101=6363, 10=0, ieee=00158d0003a279c2, device_type=lumi.sensor_ht, entity_id=zigate.00158d0003a279c2> 2020-07-08 03:24:43 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1697304112] Unable to serialize to JSON. Bad data found at $.event.data.value.6=b'\x02\x00\x00\x00\x00'(<class 'bytes'>

2020-07-08 03:27:05 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event zigate.attribute_updated[L]: endpoint=1, cluster=0, addr=8dc2, attribute=65281, data=0121bd0b0421a81305210f00062402000000006429e3086521be190a210000, name=xiaomi, type=dict, value=1=3005, 4=5032, 5=15, 6=b'\x02\x00\x00\x00\x00', 100=2275, 101=6590, 10=0, ieee=00158d000358edfa, device_type=lumi.sensor_ht, entity_id=zigate.00158d000358edfa> 2020-07-08 03:27:05 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1698401456] Unable to serialize to JSON. Bad data found at $.event.data.value.6=b'\x02\x00\x00\x00\x00'(<class 'bytes'>

2020-07-08 03:34:30 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event zigate.attribute_updated[L]: endpoint=1, cluster=0, addr=196b, attribute=65281, data=0121a90b0421a81305210d0006240200000000642959086521c8170a2135b5, name=xiaomi, type=dict, value=1=2985, 4=5032, 5=13, 6=b'\x02\x00\x00\x00\x00', 100=2137, 101=6088, 10=46389, ieee=00158d00034f8c03, device_type=lumi.sensor_ht, entity_id=zigate.00158d00034f8c03> 2020-07-08 03:34:30 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1697495760] Unable to serialize to JSON. Bad data found at $.event.data.value.6=b'\x02\x00\x00\x00\x00'(<class 'bytes'>

2020-07-08 03:50:08 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event zigate.attribute_updated[L]: endpoint=1, cluster=0, addr=a616, attribute=65281, data=0121e50b0328150421a84305210c00062401000000000a2100006410000b210000, name=xiaomi, type=dict, value=1=3045, 3=21, 4=17320, 5=12, 6=b'\x01\x00\x00\x00\x00', 10=0, 100=False, 11=0, ieee=00158d0002b8cc52, device_type=lumi.sensor_motion.aq2, entity_id=zigate.00158d0002b8cc52> 2020-07-08 03:50:08 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1716570192] Unable to serialize to JSON. Bad data found at $.event.data.value.6=b'\x01\x00\x00\x00\x00'(<class 'bytes'>

csacre commented 4 years ago

To fix this temporarily, I have changed my copy of init.py I am not sure of the consequence but for a few days now it seems to work correctly.

 def attribute_updated(**kwargs):
    device = kwargs['device']
    ieee = device.ieee
    attribute = kwargs['attribute']
    _LOGGER.debug('Update attribute for device {} {}'.format(device,
                                                             attribute))
    entity = hass.data[DATA_ZIGATE_DEVICES].get(ieee)
    event_data = attribute.copy()
    if type(event_data.get('type')) == type:
        event_data['type'] = event_data['type'].__name__
    event_data['ieee'] = device.ieee
    event_data['addr'] = device.addr
    event_data['device_type'] = device.get_property_value('type')
    if entity:
        event_data['entity_id'] = entity.entity_id
    #CS temp fix
    if str(event_data['attribute']) != "65281":
        hass.bus.fire('zigate.attribute_updated', event_data)
    else:
        _LOGGER.warning('ZIGATE CS SKIP ATTRIBUTE 65281')
doudz commented 4 years ago

should be fixed https://github.com/doudz/homeassistant-zigate/commit/e3ab494d1f90bef3492be5f08eca4fba33ffa6d8

csacre commented 4 years ago

It works! Thank you!