hobbyquaker / node-red-contrib-zigbee

Node-RED Nodes for ZigBee Devices 🐝
MIT License
86 stars 15 forks source link

SML001: Converter in JSON mode "looses" Zigbee messages #118

Closed hogthrob closed 3 years ago

hogthrob commented 4 years ago

Hi,

My setup: 0.19.0 ( Herdsman version: v0.12.101, Converters version: v12.0.139 ) on Node-RED version: v0.20.6, Node.js version: v10.16.0

My Problem: I have a strange issue: All of my Hue SML001 motion sensor stopped reporting motion/occupancy (they worked initially) via the converter nodes, but continue to report illuminance, temperature and battery level. All events including occupancy are seen by a event node, though.

I traced the issue down to an interesting problem:

If the converter node is set to report each attribute separately, occupancy is reported as wished, if I set it to produce an all in one JSON message, it does the illuminance etc, but not the occupancy.

The report below shows this ( 1e4f8074.a5cdezigbee shows the output of the Event Node, 17b02a18.93f2fezigbee of the plain converter, b4dc6451.adbeczigbee is the JSON converter):

8/4/2020, 9:44:51 AMnode: 1e4f8074.a5cdezigbee/0x0017880123456789/attributeReport/2/msOccupancySensing : msg.payload : Object
{ occupancy: 1 }
8/4/2020, 9:44:51 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/occupancy : msg.payload : boolean
true
8/4/2020, 9:44:51 AMnode: 1e4f8074.a5cdezigbee/0x0017880123456789/attributeReport/2/msIlluminanceMeasurement : msg.payload : Object
{ measuredValue: 20647 }
8/4/2020, 9:44:51 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance : msg.payload : number
20647
8/4/2020, 9:44:51 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance_lux : msg.payload : number
115
8/4/2020, 9:44:51 AMnode: b4dc6451.adbeczigbee/0x0017880123456789 : msg.payload : Object
{ illuminance: 20647, illuminance_lux: 115, linkquality: 141 }
8/4/2020, 9:45:01 AMnode: 1e4f8074.a5cdezigbee/0x0017880123456789/attributeReport/2/msIlluminanceMeasurement : msg.payload : Object
{ measuredValue: 20801 }
8/4/2020, 9:45:01 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance : msg.payload : number
20801
8/4/2020, 9:45:01 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance_lux : msg.payload : number
119
8/4/2020, 9:45:01 AMnode: b4dc6451.adbeczigbee/0x0017880123456789 : msg.payload : Object
{ illuminance: 20801, illuminance_lux: 119, linkquality: 141 }
8/4/2020, 9:45:05 AMnode: 1e4f8074.a5cdezigbee/0x0017880123456789/attributeReport/2/msOccupancySensing : msg.payload : Object
{ occupancy: 0 }
8/4/2020, 9:45:05 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/occupancy : msg.payload : boolean
false
8/4/2020, 9:45:11 AMnode: 1e4f8074.a5cdezigbee/0x0017880123456789/attributeReport/2/msIlluminanceMeasurement : msg.payload : Object
{ measuredValue: 20861 }
8/4/2020, 9:45:11 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance : msg.payload : number
20861
8/4/2020, 9:45:11 AMnode: 17b02a18.93f2fezigbee/0x0017880123456789/illuminance_lux : msg.payload : number
121
8/4/2020, 9:45:11 AMnode: b4dc6451.adbec zigbee/0x0017880123456789 : msg.payload : Object
{ illuminance: 20861, illuminance_lux: 121, linkquality: 144 }
hogthrob commented 4 years ago

A little digging in your code brought me too:

https://github.com/hobbyquaker/node-red-contrib-zigbee/blob/2bf0fad95ac6e8e52a52742c0d5a0bef45d313fe/nodes/converter.js#L316

https://github.com/hobbyquaker/node-red-contrib-zigbee/blob/2bf0fad95ac6e8e52a52742c0d5a0bef45d313fe/nodes/converter.js#L319

https://github.com/hobbyquaker/node-red-contrib-zigbee/blob/2bf0fad95ac6e8e52a52742c0d5a0bef45d313fe/nodes/converter.js#L331

and I found out that wait is set to 3 when the occupancy messages comes in, for all other messages wait is 1 and thus actually published.

I am not very fluent in JavaScript and the actual code used here I know even less, thus I am not able to easily figure out what is going on, but maybe it helps you to understand the problem better.

hogthrob commented 4 years ago

As the issue was basically not a difficult one and quite local, I was able to finally see the problem and fix it for me.

hogthrob commented 3 years ago

Thanks for integrating the PR. Hopefully this fixes also problems others have.