kabbi / zigbee2mqtt-adapter

zigbee2mqtt adapter for WebThings gateway
Mozilla Public License 2.0
21 stars 13 forks source link

Issue connecting the window sensor: Cannot read property 'modelId' of undefined #6

Closed flatsiedatsie closed 3 years ago

flatsiedatsie commented 5 years ago

I have managed to install the add-on manually, I think. The Zigbee2mqtt software is running in a terminal window, and when I press the button on the Aqara window sensor for 3 seconds I can see some messages scroll by. It seems Zigbee2MQTT is working.

The add-on also show some activity at the same time: it crashes.

2019-07-31 11:29:42.767 INFO   : Opened a new things socket
2019-07-31 11:29:48.170 ERROR  : zigbee2mqtt: /home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/zigbee2mqtt-adapter.js:83
2019-07-31 11:29:48.171 ERROR  : zigbee2mqtt:       const description = Devices[msg.device.modelId];
2019-07-31 11:29:48.172 ERROR  : zigbee2mqtt:                                              ^
2019-07-31 11:29:48.173 ERROR  : zigbee2mqtt: 
2019-07-31 11:29:48.174 ERROR  : zigbee2mqtt: TypeError: Cannot read property 'modelId' of undefined
2019-07-31 11:29:48.175 ERROR  : zigbee2mqtt:     at ZigbeeMqttAdapter.handleIncomingMessage (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/zigbee2mqtt-adapter.js:83:46)
2019-07-31 11:29:48.176 ERROR  : zigbee2mqtt:     at emitThree (events.js:136:13)
2019-07-31 11:29:48.176 ERROR  : zigbee2mqtt:     at MqttClient.emit (events.js:217:7)
2019-07-31 11:29:48.177 ERROR  : zigbee2mqtt:     at MqttClient._handlePublish (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:987:12)
2019-07-31 11:29:48.179 ERROR  : zigbee2mqtt:     at MqttClient._handlePacket (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:336:12)
2019-07-31 11:29:48.180 ERROR  : zigbee2mqtt:     at work (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:292:12)
2019-07-31 11:29:48.181 ERROR  : zigbee2mqtt:     at Writable.writable._write (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:302:5)
2019-07-31 11:29:48.182 ERROR  : zigbee2mqtt:     at doWrite (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:428:64)
2019-07-31 11:29:48.182 ERROR  : zigbee2mqtt:     at writeOrBuffer (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:417:5)
2019-07-31 11:29:48.183 ERROR  : zigbee2mqtt:     at Writable.write (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:334:11)
flatsiedatsie commented 5 years ago

I checked with mosquitt_sub what the incoming message looked like.

Client mosqsub|23184-gateway received PUBLISH (d0, q0, r0, m0, 'zigbee2mqtt/bridge/config/devices', ... (335 bytes))
[{"ieeeAddr":"0x00124b0xxxxx","type":"Coordinator"},{"ieeeAddr":"0x00158d000xxxxx","type":"EndDevice","model":"MCCGQ11LM","friendly_name":"0x0015xxxxx","nwkAddr":5xxxxx,"manufId":4xxx,"manufName":"LUMI","powerSource":"Battery","modelId":"lumi.sensor_magnet.aq2","hwVersion":2,"swBuildId":"3xxx-xxxx","dateCode":"20161128"}]

Strangely, modelId is in there.

flatsiedatsie commented 5 years ago

I think I've cracked it: this version of the magnetic contact sensor was not in the supported devices list.

Perhaps there could be a fuzzy matching heuristic where only the first two parts of the modelId have to match?

flatsiedatsie commented 5 years ago

I've created a pull request to add this device.

It might be nice to create more expressive error messages when this is the issue, so the user knows what to do.

kabbi commented 5 years ago

Yeah, I think we should add a proper error message for unsupported devices. Will definitely look into this

flatsiedatsie commented 5 years ago

How do you feel about the fuzzy matching? Could that work? Or will that only lead to issues? I don't know if the convention that Xiaomi/other companies use is in any way predictable. E.g. that the string after the second dot is just a version upgrade without a fundamentally change to how things work. Then again, this case already hinted that version 2 of the magnetic contact sensor works differently.