kabbi / zigbee2mqtt-adapter

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

Messsage format incorrect? #16

Open jfrohn opened 4 years ago

jfrohn commented 4 years ago

I recently set up a completely new ZigBee stick follwing the quide on zigbee2mqtt. When I try to add a new device I always get the following error:

2020-01-18 10:14:12.032 ERROR : zigbee2mqtt: /home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/zigbee2mqtt-adapter.js:83 2020-01-18 10:14:12.033 ERROR : zigbee2mqtt: const description = Devices[msg.device.modelId]; 2020-01-18 10:14:12.034 ERROR : zigbee2mqtt: ^ 2020-01-18 10:14:12.034 ERROR : zigbee2mqtt: 2020-01-18 10:14:12.036 ERROR : zigbee2mqtt: TypeError: Cannot read property 'modelId' of undefined 2020-01-18 10:14:12.037 ERROR : zigbee2mqtt: at ZigbeeMqttAdapter.handleIncomingMessage (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/zigbee2mqtt-adapter.js:83:46) 2020-01-18 10:14:12.037 ERROR : zigbee2mqtt: at emitThree (events.js:136:13) 2020-01-18 10:14:12.038 ERROR : zigbee2mqtt: at MqttClient.emit (events.js:217:7) 2020-01-18 10:14:12.039 ERROR : zigbee2mqtt: at MqttClient._handlePublish (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:987:12) 2020-01-18 10:14:12.039 ERROR : zigbee2mqtt: at MqttClient._handlePacket (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:336:12) 2020-01-18 10:14:12.040 ERROR : zigbee2mqtt: at work (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:292:12) 2020-01-18 10:14:12.041 ERROR : zigbee2mqtt: at Writable.writable._write (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/mqtt/lib/client.js:302:5) 2020-01-18 10:14:12.042 ERROR : zigbee2mqtt: at doWrite (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:428:64) 2020-01-18 10:14:12.043 ERROR : zigbee2mqtt: at writeOrBuffer (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:417:5) 2020-01-18 10:14:12.043 ERROR : zigbee2mqtt: at Writable.write (/home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/node_modules/readable-stream/lib/_stream_writable.js:334:11) 2020-01-18 10:14:12.046 INFO : Plugin: zigbee2mqtt-adapter died, code = 1 restarting after 0 2020-01-18 10:14:12.647 INFO : zigbee2mqtt: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-01-18 10:14:13.334 INFO : zigbee2mqtt: Loading add-on zigbee2mqtt-adapter from /home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter 2020-01-18 10:14:26.539 ERROR : zigbee2mqtt: /home/pi/.mozilla-iot/addons/zigbee2mqtt-adapter/zigbee2mqtt-adapter.js:83 2020-01-18 10:14:26.540 ERROR : zigbee2mqtt: const description = Devices[msg.device.modelId]; 2020-01-18 10:14:26.541 ERROR : zigbee2mqtt:

as far as I can see the devices are sent as follows:

{ "type":"devices", "message":[ { "ieeeAddr":"0x00124b000be88ea7", "type":"Coordinator", "networkAddress":0, "friendly_name":"Coordinator", "softwareBuildID":"zStack12", "dateCode":"20190608", "lastSeen":1579346355132 }, { "ieeeAddr":"0x00158d0004249146", "type":"Router", "networkAddress":22354, "model":"ZNLDP12LM", "friendly_name":"0x00158d0004249146", "manufacturerID":4447, "manufacturerName":"LUMI", "powerSource":"DC Source", "modelID":"lumi.light.aqcn02", "hardwareVersion":1, "softwareBuildID":"1.23\u0000", "dateCode":"11-22-2018", "lastSeen":null } ] }

It seems that the "device" element is missing.

Another problem was that "modelId" ist sent as "modelID" (uppercase D).

After playing around for a bit I was able to fix it by changing zigbee2mqtt-adapter.js to

81: if (!topic.startsWith(${this.config.prefix}/bridge)) { to 81: if (!!msg.device && !topic.startsWith(${this.config.prefix}/bridge)) {

and

113: const description = Devices[info.modelId]; to 113: const description = Devices[info.modelID];

I understand that the first fix is merely a dirty work around but it seems to work correctly now.

Still I'm wondering if this is a general problem and if this should be fixed in the code?