-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
fromZigbee.js
4702 lines (4523 loc) · 178 KB
/
fromZigbee.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
const common = require('./common');
const utils = require('./utils');
const clickLookup = {
1: 'single',
2: 'double',
3: 'triple',
4: 'quadruple',
};
const occupancyTimeout = 90; // In seconds
const defaultPrecision = {
temperature: 2,
humidity: 2,
pressure: 1,
};
const calibrateAndPrecisionRoundOptions = (number, options, type) => {
// Calibrate
const calibrateKey = `${type}_calibration`;
let calibrationOffset = options && options.hasOwnProperty(calibrateKey) ? options[calibrateKey] : 0;
if (type == 'illuminance' || type === 'illuminance_lux') {
// linear calibration because measured value is zero based
// +/- percent
calibrationOffset = Math.round(number * calibrationOffset / 100);
}
number = number + calibrationOffset;
// Precision round
const precisionKey = `${type}_precision`;
const defaultValue = defaultPrecision[type] || 0;
const precision = options && options.hasOwnProperty(precisionKey) ? options[precisionKey] : defaultValue;
return precisionRound(number, precision);
};
const precisionRound = (number, precision) => {
if (typeof precision === 'number') {
const factor = Math.pow(10, precision);
return Math.round(number * factor) / factor;
} else if (typeof precision === 'object') {
const thresholds = Object.keys(precision).map(Number).sort((a, b) => b - a);
for (const t of thresholds) {
if (! isNaN(t) && number >= t) {
return precisionRound(number, precision[t]);
}
}
}
return number;
};
const toPercentage = (value, min, max) => {
if (value > max) {
value = max;
} else if (value < min) {
value = min;
}
const normalised = (value - min) / (max - min);
return Math.round(normalised * 100);
};
const toPercentageCR2032 = (voltage) => {
let percentage = null;
if (voltage < 2100) {
percentage = 0;
} else if (voltage < 2440) {
percentage = 6 - ((2440 - voltage) * 6) / 340;
} else if (voltage < 2740) {
percentage = 18 - ((2740 - voltage) * 12) / 300;
} else if (voltage < 2900) {
percentage = 42 - ((2900 - voltage) * 24) / 160;
} else if (voltage < 3000) {
percentage = 100 - ((3000 - voltage) * 58) / 100;
} else if (voltage >= 3000) {
percentage = 100;
}
return Math.round(percentage);
};
const numberWithinRange = (number, min, max) => {
if (number > max) {
return max;
} else if (number < min) {
return min;
} else {
return number;
}
};
// get object property name (key) by it's value
const getKey = (object, value) => {
for (const key in object) {
if (object[key]==value) return key;
}
};
// Global variable store that can be used by devices.
const store = {};
const ictcg1 = (model, msg, publish, options, action) => {
const deviceID = msg.device.ieeeAddr;
const payload = {};
if (!store[deviceID]) {
store[deviceID] = {since: false, direction: false, value: 255, publish: publish};
}
const s = store[deviceID];
// if rate == 70 so we rotate slowly
const rate = (msg.data.rate == 70) ? 0.3 : 1;
if (action === 'move') {
s.since = Date.now();
const direction = msg.data.movemode === 1 ? 'left' : 'right';
s.direction = direction;
payload.action = `rotate_${direction}`;
} else if (action === 'level') {
s.value = msg.data.level;
const direction = s.value === 0 ? 'left' : 'right';
payload.action = `rotate_${direction}_quick`;
payload.brightness = s.value;
} else if (action === 'stop') {
if (s.direction) {
const duration = Date.now() - s.since;
const delta = Math.round(rate * (duration / 10) * (s.direction === 'left' ? -1 : 1));
const newValue = s.value + delta;
if (newValue >= 0 && newValue <= 255) {
s.value = newValue;
}
}
payload.action = 'rotate_stop';
payload.brightness = s.value;
s.direction = false;
}
if (s.timerId) {
clearInterval(s.timerId);
s.timerId = false;
}
if (action === 'move') {
s.timerId = setInterval(() => {
const duration = Date.now() - s.since;
const delta = Math.round(rate * (duration / 10) * (s.direction === 'left' ? -1 : 1));
const newValue = s.value + delta;
if (newValue >= 0 && newValue <= 255) {
s.value = newValue;
}
payload.brightness = s.value;
s.since = Date.now();
s.publish(payload);
}, 200);
}
return payload.brightness;
};
const getProperty = (name, msg, definition) => {
if (definition.meta && definition.meta.multiEndpoint) {
const endpointName = definition.hasOwnProperty('endpoint') ?
getKey(definition.endpoint(msg.device), msg.endpoint.ID) : msg.endpoint.ID;
return `${name}_${endpointName}`;
} else {
return name;
}
};
const ratelimitedDimmer = (model, msg, publish, options, meta) => {
const deviceID = msg.device.ieeeAddr;
const payload = {};
let duration = 0;
if (!store[deviceID]) {
store[deviceID] = {lastmsg: false};
}
const s = store[deviceID];
if (s.lastmsg) {
duration = Date.now() - s.lastmsg;
} else {
s.lastmsg = Date.now();
}
if (duration > 500) {
s.lastmsg = Date.now();
payload.action = 'brightness';
payload.brightness = msg.data.level;
publish(payload);
}
};
const holdUpdateBrightness324131092621 = (deviceID) => {
if (store[deviceID] && store[deviceID].brightnessSince && store[deviceID].brightnessDirection) {
const duration = Date.now() - store[deviceID].brightnessSince;
const delta = (duration / 10) * (store[deviceID].brightnessDirection === 'up' ? 1 : -1);
const newValue = store[deviceID].brightnessValue + delta;
store[deviceID].brightnessValue = numberWithinRange(newValue, 1, 255);
}
};
const tuyaThermostat = (model, msg, publish, options, meta) => {
const dp = msg.data.dp;
const data = msg.data.data;
const dataAsDecNumber = utils.convertMultiByteNumberPayloadToSingleDecimalNumber(data);
let temperature;
/*
* Structure of the ZCL payload used by Tuya:
*
* - status: unit8 - 1 byte
* - transid: unit8 - 1 byte
* - dp: uint16 - 2 bytes* (Big Endian format)
* - fn: uint8 - 1 byte
* - data: octStr - variable**
*
* Examples:
* | status | transid | dp | fn | data |
* | 0 | 4 | 0x02 0x02 -> 514 | 0 | [4, 0, 0, 0, 180] |
* | 0 | 16 | 0x04 0x04 -> 1028 | 0 | [1, 2] |
*
* * The 2 bytes field "dp" uses Big Endian which means that the most meaninful
* byte goes right. In plain English: a value like 0x07 0x01 has to be read
* from the left so, it becomes 0x0107 witch in base 10 is 263 (the code for
* child lock status).
*
* ** The type octStr prefixes the first byte of the value with the lenght of the
* data payload.
*/
switch (dp) {
case 104: // 0x6800 window params
return {
window_detection_params: {
valve: data[0] ? 'ON' : 'OFF',
temperature: data[1],
minutes: data[2],
},
};
case 112: // set schedule for workdays [6,0,20,8,0,15,11,30,15,12,30,15,17,30,20,22,0,15]
// 6:00 - 20*, 8:00 - 15*, 11:30 - 15*, 12:30 - 15*, 17:30 - 20*, 22:00 - 15*
return {workdays: [
{hour: data[0], minute: data[1], temperature: data[2]},
{hour: data[3], minute: data[4], temperature: data[5]},
{hour: data[6], minute: data[7], temperature: data[8]},
{hour: data[9], minute: data[10], temperature: data[11]},
{hour: data[12], minute: data[13], temperature: data[14]},
{hour: data[15], minute: data[16], temperature: data[17]},
]};
case 113: // set schedule for holidays [6,0,20,8,0,15,11,30,15,12,30,15,17,30,20,22,0,15]
// 6:00 - 20*, 8:00 - 15*, 11:30 - 15*, 12:30 - 15*, 17:30 - 20*, 22:00 - 15*
return {holidays: [
{hour: data[0], minute: data[1], temperature: data[2]},
{hour: data[3], minute: data[4], temperature: data[5]},
{hour: data[6], minute: data[7], temperature: data[8]},
{hour: data[9], minute: data[10], temperature: data[11]},
{hour: data[12], minute: data[13], temperature: data[14]},
{hour: data[15], minute: data[16], temperature: data[17]},
]};
case 263: // 0x0701 Changed child lock status
return {child_lock: dataAsDecNumber ? 'LOCKED' : 'UNLOCKED'};
case 274: // 0x1201 Enabled/disabled window detection feature
return {window_detection: dataAsDecNumber ? 'ON' : 'OFF'};
case 276: // 0x1401 Enabled/disabled Valve detection feature
return {valve_detection: dataAsDecNumber ? 'ON' : 'OFF'};
case 372: // 0x7401 auto lock mode
return {auto_lock: dataAsDecNumber ? 'AUTO' : 'MANUAL'};
case 514: // 0x0202 Changed target temperature
temperature = (dataAsDecNumber / 10).toFixed(1);
return {current_heating_setpoint: temperature};
case 515: // 0x0302 MCU reporting room temperature
temperature = (dataAsDecNumber / 10).toFixed(1);
return {local_temperature: temperature};
case 556: // 0x2c02 Temperature calibration
temperature = (dataAsDecNumber / 10).toFixed(1);
return {local_temperature_calibration: temperature};
case 533: // 0x1502 MCU reporting battery status
return {battery: dataAsDecNumber};
case 614: // 0x6602 min temperature limit
return {min_temperature: dataAsDecNumber};
case 615: // 0x6702 max temperature limit
return {max_temperature: dataAsDecNumber};
case 617: // 0x6902 boost time
return {boost_time: dataAsDecNumber};
case 619: // 0x6b02 comfort temperature
return {comfort_temperature: dataAsDecNumber};
case 620: // 0x6c02 ECO temperature
return {eco_temperature: dataAsDecNumber};
case 621: // 0x6d02 valve position
return {position: dataAsDecNumber};
case 626: // 0x7202 preset temp ?
return {preset_temperature: dataAsDecNumber};
case 629: // 0x7502 preset ?
return {preset: dataAsDecNumber};
case 1028: // 0x0404 Mode changed
if (common.TuyaThermostatSystemModes.hasOwnProperty(dataAsDecNumber)) {
return {system_mode: common.TuyaThermostatSystemModes[dataAsDecNumber]};
} else {
console.log(`TRV system mode ${dataAsDecNumber} is not recognized.`);
return;
}
case 1130: // 0x6a04 force mode 0 - normal, 1 - open, 2 - close
return {force: common.TuyaThermostatForceMode[dataAsDecNumber]};
case 1135: // Week select 0 - 5 days, 1 - 6 days, 2 - 7 days
return {week: common.TuyaThermostatWeekFormat[dataAsDecNumber]};
default: // The purpose of the codes 1041 & 1043 are still unknown
console.log(`zigbee-herdsman-converters:siterwell_gs361: NOT RECOGNIZED DP #${
dp} with data ${JSON.stringify(data)}`);
}
};
const converters = {
/**
* Generic/recommended converters, the converters below comply with the ZCL
* and are recommended to for re-use
*/
lock_operation_event: {
cluster: 'closuresDoorLock',
type: 'commandOperationEventNotification',
convert: (model, msg, publish, options, meta) => {
const unlockCodes = [2, 9, 14];
return {
state: unlockCodes.includes(msg.data['opereventcode']) ? 'UNLOCK' : 'LOCK',
user: msg.data['userid'],
source: msg.data['opereventsrc'],
};
},
},
lock: {
cluster: 'closuresDoorLock',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('lockState')) {
return {state: msg.data.lockState == 2 ? 'UNLOCK' : 'LOCK'};
}
},
},
battery: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const payload = {};
if (msg.data.hasOwnProperty('batteryPercentageRemaining')) {
payload['battery'] = precisionRound(msg.data['batteryPercentageRemaining'] / 2, 2);
}
if (msg.data.hasOwnProperty('batteryVoltage')) {
payload['voltage'] = msg.data['batteryVoltage'] * 100;
}
if (msg.data.hasOwnProperty('batteryAlarmState')) {
payload['battery_low'] = msg.data.batteryAlarmState;
}
if (Object.keys(payload).length !== 0) {
return payload;
}
},
},
battery_not_divided: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const payload = {};
if (msg.data.hasOwnProperty('batteryPercentageRemaining')) {
// Some devices do not comply to the ZCL and report a
// batteryPercentageRemaining of 100 when the battery is full.
payload['battery'] = precisionRound(msg.data['batteryPercentageRemaining'], 2);
}
if (msg.data.hasOwnProperty('batteryVoltage')) {
payload['voltage'] = msg.data['batteryVoltage'] * 100;
}
if (msg.data.hasOwnProperty('batteryAlarmState')) {
payload['battery_low'] = msg.data.batteryAlarmState;
}
if (Object.keys(payload).length !== 0) {
return payload;
}
},
},
temperature: {
cluster: 'msTemperatureMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const temperature = parseFloat(msg.data['measuredValue']) / 100.0;
return {temperature: calibrateAndPrecisionRoundOptions(temperature, options, 'temperature')};
},
},
humidity: {
cluster: 'msRelativeHumidity',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const humidity = parseFloat(msg.data['measuredValue']) / 100.0;
// https://github.com/Koenkk/zigbee2mqtt/issues/798
// Sometimes the sensor publishes non-realistic vales, it should only publish message
// in the 0 - 100 range, don't produce messages beyond these values.
if (humidity >= 0 && humidity <= 100) {
return {humidity: calibrateAndPrecisionRoundOptions(humidity, options, 'humidity')};
}
},
},
illuminance: {
cluster: 'msIlluminanceMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
// DEPRECATED: only return lux here (change illuminance_lux -> illuminance)
const illuminance = msg.data['measuredValue'];
const illuminanceLux = Math.pow(10, illuminance / 10000) - 1;
return {
illuminance: calibrateAndPrecisionRoundOptions(illuminance, options, 'illuminance'),
illuminance_lux: calibrateAndPrecisionRoundOptions(illuminanceLux, options, 'illuminance_lux'),
};
},
},
pressure: {
cluster: 'msPressureMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const pressure = parseFloat(msg.data['measuredValue']);
return {pressure: calibrateAndPrecisionRoundOptions(pressure, options, 'pressure')};
},
},
occupancy: {
// This is for occupancy sensor that send motion start AND stop messages
cluster: 'msOccupancySensing',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('occupancy')) {
return {occupancy: msg.data.occupancy === 1};
}
},
},
occupancy_with_timeout: {
// This is for occupancy sensor that only send a message when motion detected,
// but do not send a motion stop.
// Therefore we need to publish the no_motion detected by ourselves.
cluster: 'msOccupancySensing',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.occupancy !== 1) {
// In case of 0 no occupancy is reported.
// https://github.com/Koenkk/zigbee2mqtt/issues/467
return;
}
// The occupancy sensor only sends a message when motion detected.
// Therefore we need to publish the no_motion detected by ourselves.
const timeout = options && options.hasOwnProperty('occupancy_timeout') ?
options.occupancy_timeout : occupancyTimeout;
const deviceID = msg.device.ieeeAddr;
// Stop existing timers because motion is detected and set a new one.
if (store[deviceID]) {
store[deviceID].forEach((t) => clearTimeout(t));
}
store[deviceID] = [];
if (timeout !== 0) {
const timer = setTimeout(() => {
publish({occupancy: false});
}, timeout * 1000);
store[deviceID].push(timer);
}
// No occupancy since
if (options && options.no_occupancy_since) {
options.no_occupancy_since.forEach((since) => {
const timer = setTimeout(() => {
publish({no_occupancy_since: since});
}, since * 1000);
store[deviceID].push(timer);
});
}
if (options && options.no_occupancy_since) {
return {occupancy: true, no_occupancy_since: 0};
} else {
return {occupancy: true};
}
},
},
brightness: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('currentLevel')) {
const property = getProperty('brightness', msg, model);
return {[property]: msg.data['currentLevel']};
}
},
},
metering_power: {
cluster: 'seMetering',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const payload = {};
const multiplier = msg.endpoint.getClusterAttributeValue('seMetering', 'multiplier');
const divisor = msg.endpoint.getClusterAttributeValue('seMetering', 'divisor');
const factor = multiplier && divisor ? multiplier / divisor : null;
if (msg.data.hasOwnProperty('instantaneousDemand')) {
let power = msg.data['instantaneousDemand'];
if (factor != null) {
power = (power * factor) * 1000; // kWh to Watt
}
payload.power = precisionRound(power, 2);
}
if (factor != null && (msg.data.hasOwnProperty('currentSummDelivered') ||
msg.data.hasOwnProperty('currentSummReceived'))) {
let energy = 0;
if (msg.data.hasOwnProperty('currentSummDelivered')) {
const data = msg.data['currentSummDelivered'];
const value = (parseInt(data[0]) << 32) + parseInt(data[1]);
energy += value * factor;
}
if (msg.data.hasOwnProperty('currentSummReceived')) {
const data = msg.data['currentSummReceived'];
const value = (parseInt(data[0]) << 32) + parseInt(data[1]);
energy -= value * factor;
}
payload.energy = precisionRound(energy, 2);
}
return payload;
},
},
electrical_measurement_power: {
/**
* When using this converter also add the following to the configure method of the device:
* await readEletricalMeasurementConverterAttributes(endpoint);
*/
cluster: 'haElectricalMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const getFactor = (key) => {
const multiplier = msg.endpoint.getClusterAttributeValue('haElectricalMeasurement', `${key}Multiplier`);
const divisor = msg.endpoint.getClusterAttributeValue('haElectricalMeasurement', `${key}Divisor`);
const factor = multiplier && divisor ? multiplier / divisor : 1;
return factor;
};
const lookup = [
{key: 'activePower', name: 'power', factor: 'acPower'},
{key: 'activePowerPhB', name: 'power_phase_b', factor: 'acPower'},
{key: 'activePowerPhC', name: 'power_phase_c', factor: 'acPower'},
{key: 'rmsCurrent', name: 'current', factor: 'acCurrent'},
{key: 'rmsCurrentPhB', name: 'current_phase_b', factor: 'acCurrent'},
{key: 'rmsCurrentPhC', name: 'current_phase_c', factor: 'acCurrent'},
{key: 'rmsVoltage', name: 'voltage', factor: 'acVoltage'},
{key: 'rmsVoltagePhB', name: 'voltage_phase_b', factor: 'acVoltage'},
{key: 'rmsVoltagePhC', name: 'voltage_phase_c', factor: 'acVoltage'},
];
const payload = {};
for (const entry of lookup) {
if (msg.data.hasOwnProperty(entry.key)) {
const factor = getFactor(entry.factor);
const property = getProperty(entry.name, msg, model);
payload[property] = precisionRound(msg.data[entry.key] * factor, 2);
}
}
return payload;
},
},
on_off: {
cluster: 'genOnOff',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('onOff')) {
const property = getProperty('state', msg, model);
return {[property]: msg.data['onOff'] === 1 ? 'ON' : 'OFF'};
}
},
},
ias_water_leak_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
water_leak: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_gas_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
gas: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_gas_alarm_2: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
gas: (zoneStatus & 1<<1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_smoke_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
const zoneState = msg.data.zoneState;
return {
enrolled: zoneState === 1,
smoke: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
supervision_reports: (zoneStatus & 1<<4) > 0,
restore_reports: (zoneStatus & 1<<5) > 0,
trouble: (zoneStatus & 1<<6) > 0,
ac_status: (zoneStatus & 1<<7) > 0,
};
},
},
ias_contact_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
contact: !((zoneStatus & 1) > 0),
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_carbon_monoxide_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
carbon_monoxide: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_sos_alarm_2: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
sos: (zoneStatus & 1<<1) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_occupancy_alarm_1: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
occupancy: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_occupancy_alarm_2: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
return {
occupancy: (zoneStatus & 1<<1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
ias_occupancy_alarm_1_with_timeout: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
convert: (model, msg, publish, options, meta) => {
const zoneStatus = msg.data.zonestatus;
const deviceID = msg.device.ieeeAddr;
const timeout = options && options.hasOwnProperty('occupancy_timeout') ?
options.occupancy_timeout : occupancyTimeout;
if (store[deviceID]) {
clearTimeout(store[deviceID]);
store[deviceID] = null;
}
if (timeout !== 0) {
store[deviceID] = setTimeout(() => {
publish({occupancy: false});
store[deviceID] = null;
}, timeout * 1000);
}
return {
occupancy: (zoneStatus & 1) > 0,
tamper: (zoneStatus & 1<<2) > 0,
battery_low: (zoneStatus & 1<<3) > 0,
};
},
},
command_recall: {
cluster: 'genScenes',
type: 'commandRecall',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty(`recall_${msg.data.sceneid}`, msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_panic: {
cluster: 'ssIasAce',
type: 'commandPanic',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty(`panic`, msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_arm: {
cluster: 'ssIasAce',
type: 'commandArm',
convert: (model, msg, publish, options, meta) => {
const lookup = {
0: 'disarm',
1: 'arm_day_zones',
2: 'arm_night_zones',
3: 'arm_all_zones',
};
const payload = {action: getProperty(lookup[msg.data['armmode']], msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_on: {
cluster: 'genOnOff',
type: 'commandOn',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty('on', msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_off: {
cluster: 'genOnOff',
type: 'commandOff',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty('off', msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_off_with_effect: {
cluster: 'genOnOff',
type: 'commandOffWithEffect',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty(`off`, msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_move_with_on_off: {
cluster: 'genLevelCtrl',
type: 'commandMoveWithOnOff',
convert: (model, msg, publish, options, meta) => {
const direction = msg.data.movemode === 1 ? 'down' : 'up';
const action = getProperty(`brightness_move_${direction}`, msg, model);
const payload = {action, action_rate: msg.data.rate};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_stop_with_on_off: {
cluster: 'genLevelCtrl',
type: 'commandStopWithOnOff',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty(`brightness_stop`, msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_step_with_on_off: {
cluster: 'genLevelCtrl',
type: 'commandStepWithOnOff',
convert: (model, msg, publish, options, meta) => {
const direction = msg.data.stepmode === 1 ? 'down' : 'up';
const payload = {
action: getProperty(`brightness_step_${direction}`, msg, model),
action_step_size: msg.data.stepsize,
};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_step_color_temperature: {
cluster: 'lightingColorCtrl',
type: 'commandStepColorTemp',
convert: (model, msg, publish, options, meta) => {
const direction = msg.data.stepmode === 1 ? 'up' : 'down';
const payload = {
action: getProperty(`color_temperature_step_${direction}`, msg, model),
action_step_size: msg.data.stepsize,
};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_move_to_color_temp: {
cluster: 'lightingColorCtrl',
type: 'commandMoveToColorTemp',
convert: (model, msg, publish, options, meta) => {
const payload = {
action: getProperty(`color_temperature_move`, msg, model),
action_color_temperature: msg.data.colortemp,
action_transition_time: msg.data.transtime,
};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_move_to_color: {
cluster: 'lightingColorCtrl',
type: 'commandMoveToColor',
convert: (model, msg, publish, options, meta) => {
const payload = {
action: getProperty(`color_move`, msg, model),
action_color: {
x: precisionRound(msg.data.colorx / 65535, 3),
y: precisionRound(msg.data.colory / 65535, 3),
},
action_transition_time: msg.data.transtime,
};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_move_hue: {
cluster: 'lightingColorCtrl',
type: 'commandMoveHue',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty('hue_move', msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
command_emergency: {
cluster: 'ssIasAce',
type: 'commandEmergency',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty(`emergency`, msg, model)};
if (msg.groupID) payload.action_group = msg.groupID;
return payload;
},
},
identify: {
cluster: 'genIdentify',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
return {action: getProperty(`identify`, msg, model)};
},
},
/**
* Device specific converters, not recommended for re-use.
* TODO: This has not been fully sorted out yet.
*/
scenes_recall_scene_65029: {
cluster: 65029,
type: ['raw'],
convert: (model, msg, publish, options, meta) => {
return {action: `scene_${msg.data[msg.data.length - 1]}`};
},
},
HS2SK_SKHMP30I1_power: {
cluster: 'haElectricalMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.hasOwnProperty('activePower')) {
result.power = msg.data['activePower'] / 10;
}
if (msg.data.hasOwnProperty('rmsCurrent')) {
result.current = msg.data['rmsCurrent'] / 100;
}
if (msg.data.hasOwnProperty('rmsVoltage')) {
result.voltage = msg.data['rmsVoltage'] / 100;
}
return result;
},
},
genOnOff_cmdOn: {
cluster: 'genOnOff',
type: 'commandOn',
convert: (model, msg, publish, options, meta) => {
return {click: 'on'};
},
},
genOnOff_cmdOff: {
cluster: 'genOnOff',
type: 'commandOff',
convert: (model, msg, publish, options, meta) => {
return {click: 'off'};
},
},
E1743_brightness_down: {
cluster: 'genLevelCtrl',
type: 'commandMove',
convert: (model, msg, publish, options, meta) => {
return {click: 'brightness_down'};
},
},
E1743_brightness_up: {
cluster: 'genLevelCtrl',
type: 'commandMoveWithOnOff',
convert: (model, msg, publish, options, meta) => {
return {click: 'brightness_up'};
},
},
E1743_brightness_stop: {
cluster: 'genLevelCtrl',
type: 'commandStopWithOnOff',
convert: (model, msg, publish, options, meta) => {
return {click: 'brightness_stop'};
},
},
E1744_play_pause: {
cluster: 'genOnOff',
type: 'commandToggle',
convert: (model, msg, publish, options, meta) => {
return {action: 'play_pause'};
},
},
E1744_skip: {
cluster: 'genLevelCtrl',
type: 'commandStep',
convert: (model, msg, publish, options, meta) => {
const direction = msg.data.stepmode === 1 ? 'backward' : 'forward';
return {
action: `skip_${direction}`,
step_size: msg.data.stepsize,
transition_time: msg.data.transtime,
};
},
},
osram_lightify_switch_long_middle: {
cluster: 'lightingColorCtrl',
type: 'commandMoveHue',
convert: (model, msg, publish, options, meta) => {
return {click: 'long_middle'};
},
},
AV2010_34_click: {
cluster: 'genScenes',
type: 'commandRecall',
convert: (model, msg, publish, options, meta) => {
return {click: msg.data.groupid};
},
},
bitron_power: {
cluster: 'seMetering',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
return {power: parseFloat(msg.data['instantaneousDemand']) / 10.0};
},
},
bitron_battery_att_report: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (typeof msg.data['batteryVoltage'] == 'number') {
const battery = {max: 3200, min: 2500};
const voltage = msg.data['batteryVoltage'] * 100;