-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathtuya.ts
5038 lines (5013 loc) · 267 KB
/
tuya.ts
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
import * as exposes from '../lib/exposes';
import * as legacy from '../lib/legacy';
import * as tuya from '../lib/tuya';
import * as ota from '../lib/ota';
import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import * as libColor from '../lib/color';
import * as utils from '../lib/utils';
import * as zosung from '../lib/zosung';
import * as globalStore from '../lib/store';
import {ColorMode, colorModeLookup} from '../lib/constants';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import {KeyValue, Definition, Tz, Fz, Expose, KeyValueAny, KeyValueNumberString, KeyValueString} from '../lib/types';
const e = exposes.presets;
const ea = exposes.access;
const fzZosung = zosung.fzZosung;
const tzZosung = zosung.tzZosung;
const ez = zosung.presetsZosung;
const tzLocal = {
led_control: {
key: ['brightness', 'color', 'color_temp', 'transition'],
options: [exposes.options.color_sync()],
convertSet: async (entity, _key, _value, meta) => {
const newState: KeyValue = {};
// The color mode encodes whether the light is using its white LEDs or its color LEDs
let colorMode = meta.state.color_mode ?? colorModeLookup[ColorMode.ColorTemp];
// Color mode switching is done by setting color temperature (switch to white LEDs) or setting color (switch
// to color LEDs)
if ('color_temp' in meta.message) colorMode = colorModeLookup[ColorMode.ColorTemp];
if ('color' in meta.message) colorMode = colorModeLookup[ColorMode.HS];
if (colorMode != meta.state.color_mode) {
newState.color_mode = colorMode;
// To switch between white mode and color mode, we have to send a special command:
const rgbMode = (colorMode == colorModeLookup[ColorMode.HS]);
await entity.command('lightingColorCtrl', 'tuyaRgbMode', {enable: rgbMode});
}
// A transition time of 0 would be treated as about 1 second, probably some kind of fallback/default
// transition time, so for "no transition" we use 1 (tenth of a second).
const transtime = typeof meta.message.transition === 'number' ? (meta.message.transition * 10) : 0.1;
if (colorMode == colorModeLookup[ColorMode.ColorTemp]) {
if ('brightness' in meta.message) {
const zclData = {level: Number(meta.message.brightness), transtime};
await entity.command('genLevelCtrl', 'moveToLevel', zclData, utils.getOptions(meta.mapped, entity));
newState.brightness = meta.message.brightness;
}
if ('color_temp' in meta.message) {
const zclData = {colortemp: meta.message.color_temp, transtime: transtime};
await entity.command('lightingColorCtrl', 'moveToColorTemp', zclData, utils.getOptions(meta.mapped, entity));
newState.color_temp = meta.message.color_temp;
}
} else if (colorMode == colorModeLookup[ColorMode.HS]) {
if ('brightness' in meta.message || 'color' in meta.message) {
// We ignore the brightness of the color and instead use the overall brightness setting of the lamp
// for the brightness because I think that's the expected behavior and also because the color
// conversion below always returns 100 as brightness ("value") even for very dark colors, except
// when the color is completely black/zero.
// Load current state or defaults
const newSettings = {
brightness: meta.state.brightness ?? 254, // full brightness
// @ts-expect-error
hue: (meta.state.color ?? {}).hue ?? 0, // red
// @ts-expect-error
saturation: (meta.state.color ?? {}).saturation ?? 100, // full saturation
};
// Apply changes
if ('brightness' in meta.message) {
newSettings.brightness = meta.message.brightness;
newState.brightness = meta.message.brightness;
}
if ('color' in meta.message) {
// The Z2M UI sends `{ hex:'#xxxxxx' }`.
// Home Assistant sends `{ h: xxx, s: xxx }`.
// We convert the former into the latter.
const c = libColor.Color.fromConverterArg(meta.message.color);
if (c.isRGB()) {
// https://github.com/Koenkk/zigbee2mqtt/issues/13421#issuecomment-1426044963
c.hsv = c.rgb.gammaCorrected().toXY().toHSV();
}
const color = c.hsv;
newSettings.hue = color.hue;
newSettings.saturation = color.saturation;
newState.color = {
hue: color.hue,
saturation: color.saturation,
};
}
// Convert to device specific format and send
utils.assertNumber(newSettings.brightness, 'brightness');
const zclData = {
brightness: utils.mapNumberRange(newSettings.brightness, 0, 254, 0, 1000),
hue: newSettings.hue,
saturation: utils.mapNumberRange(newSettings.saturation, 0, 100, 0, 1000),
};
// This command doesn't support a transition time
await entity.command('lightingColorCtrl', 'tuyaMoveToHueAndSaturationBrightness2', zclData,
utils.getOptions(meta.mapped, entity));
}
}
// If we're in white mode, calculate a matching display color for the set color temperature. This also kind
// of works in the other direction.
Object.assign(newState, libColor.syncColorState(newState, meta.state, entity, meta.options, meta.logger));
return {state: newState};
},
convertGet: async (entity, key, meta) => {
await entity.read('lightingColorCtrl', ['currentHue', 'currentSaturation', 'currentLevel', 'tuyaRgbMode', 'colorTemperature']);
},
} as Tz.Converter,
TS110E_options: {
key: ['min_brightness', 'max_brightness', 'light_type', 'switch_type'],
convertSet: async (entity, key, value, meta) => {
let payload = null;
if (key === 'min_brightness' || key == 'max_brightness') {
const id = key === 'min_brightness' ? 64515 : 64516;
utils.assertNumber(value, key);
payload = {[id]: {value: utils.mapNumberRange(value, 1, 255, 0, 1000), type: 0x21}};
} else if (key === 'light_type' || key === 'switch_type') {
utils.assertString(value, 'light_type/switch_type');
const lookup: KeyValue = key === 'light_type' ? {led: 0, incandescent: 1, halogen: 2} : {momentary: 0, toggle: 1, state: 2};
payload = {64514: {value: lookup[value], type: 0x20}};
}
await entity.write('genLevelCtrl', payload, utils.getOptions(meta.mapped, entity));
return {state: {[key]: value}};
},
convertGet: async (entity, key, meta) => {
let id = null;
if (key === 'min_brightness') id = 64515;
if (key === 'max_brightness') id = 64516;
if (key === 'light_type' || key === 'switch_type') id = 64514;
await entity.read('genLevelCtrl', [id]);
},
} as Tz.Converter,
TS110E_onoff_brightness: {
key: ['state', 'brightness'],
options: [],
convertSet: async (entity, key, value, meta) => {
const {message, state} = meta;
if (message.state === 'OFF' || (message.hasOwnProperty('state') && !message.hasOwnProperty('brightness'))) {
return await tz.on_off.convertSet(entity, key, value, meta);
} else if (message.hasOwnProperty('brightness')) {
// set brightness
if (state.state === 'OFF') {
await entity.command('genOnOff', 'on', {}, utils.getOptions(meta.mapped, entity));
}
utils.assertNumber(message.brightness, 'brightness');
const level = utils.mapNumberRange(message.brightness, 0, 254, 0, 1000);
await entity.command('genLevelCtrl', 'moveToLevelTuya', {level, transtime: 100}, utils.getOptions(meta.mapped, entity));
return {state: {state: 'ON', brightness: message.brightness}};
}
},
convertGet: async (entity, key, meta) => {
if (key === 'state') await tz.on_off.convertGet(entity, key, meta);
if (key === 'brightness') await entity.read('genLevelCtrl', [61440]);
},
} as Tz.Converter,
TS110E_light_onoff_brightness: {
...tz.light_onoff_brightness,
convertSet: async (entity, key, value, meta) => {
const {message} = meta;
if (message.state === 'ON' || (typeof message.brightness === 'number' && message.brightness > 1)) {
// Does not turn off with physical press when turned on with just moveToLevelWithOnOff, required on before.
// https://github.com/Koenkk/zigbee2mqtt/issues/15902#issuecomment-1382848150
await entity.command('genOnOff', 'on', {}, utils.getOptions(meta.mapped, entity));
}
return tz.light_onoff_brightness.convertSet(entity, key, value, meta);
},
} as Tz.Converter,
TS0504B_color: {
key: ['color'],
convertSet: async (entity, key, value, meta) => {
const color = libColor.Color.fromConverterArg(value);
const enableWhite =
(color.isRGB() && (color.rgb.red === 1 && color.rgb.green === 1 && color.rgb.blue === 1)) ||
// Zigbee2MQTT frontend white value
(color.isXY() && (color.xy.x === 0.3125 || color.xy.y === 0.32894736842105265)) ||
// Home Assistant white color picker value
(color.isXY() && (color.xy.x === 0.323 || color.xy.y === 0.329));
if (enableWhite) {
await entity.command('lightingColorCtrl', 'tuyaRgbMode', {enable: false});
const newState: KeyValue = {color_mode: 'xy'};
if (color.isXY()) {
newState.color = color.xy;
} else {
newState.color = color.rgb.gammaCorrected().toXY().rounded(4);
}
return {state: libColor.syncColorState(newState, meta.state, entity, meta.options, meta.logger) as KeyValue};
} else {
return await tz.light_color.convertSet(entity, key, value, meta);
}
},
} as Tz.Converter,
TS0224: {
key: ['light', 'duration', 'volume'],
convertSet: async (entity, key, value, meta) => {
if (key === 'light') {
utils.assertString(value, 'light');
await entity.command('genOnOff', value.toLowerCase() === 'on' ? 'on' : 'off', {}, utils.getOptions(meta.mapped, entity));
} else if (key === 'duration') {
await entity.write('ssIasWd', {'maxDuration': value}, utils.getOptions(meta.mapped, entity));
} else if (key === 'volume') {
const lookup: KeyValue = {'mute': 0, 'low': 10, 'medium': 30, 'high': 50};
utils.assertString(value, 'volume');
const lookupValue = lookup[value];
value = value.toLowerCase();
utils.validateValue(value, Object.keys(lookup));
await entity.write('ssIasWd', {0x0002: {value: lookupValue, type: 0x0a}}, utils.getOptions(meta.mapped, entity));
}
return {state: {[key]: value}};
},
} as Tz.Converter,
temperature_unit: {
key: ['temperature_unit'],
convertSet: async (entity, key, value, meta) => {
switch (key) {
case 'temperature_unit': {
utils.assertString(value, 'temperature_unit');
await entity.write('manuSpecificTuya_2', {'57355': {value: {'celsius': 0, 'fahrenheit': 1}[value], type: 48}});
break;
}
default: // Unknown key
meta.logger.warn(`Unhandled key ${key}`);
}
},
} as Tz.Converter,
TS011F_threshold: {
key: [
'temperature_threshold', 'temperature_breaker', 'power_threshold', 'power_breaker',
'over_current_threshold', 'over_current_breaker', 'over_voltage_threshold', 'over_voltage_breaker',
'under_voltage_threshold', 'under_voltage_breaker',
],
convertSet: async (entity, key, value, meta) => {
const onOffLookup = {'on': 1, 'off': 0};
switch (key) {
case 'temperature_threshold': {
utils.assertNumber(value, 'temperature_threshold');
const state = meta.state['temperature_breaker'];
const buf = Buffer.from([5, utils.getFromLookup(state, onOffLookup), 0, value]);
await entity.command('manuSpecificTuya_3', 'setOptions2', {data: buf});
break;
}
case 'temperature_breaker': {
const threshold = meta.state['temperature_threshold'];
utils.assertNumber(threshold, 'temperature_threshold');
const buf = Buffer.from([5, utils.getFromLookup(value, onOffLookup), 0, threshold]);
await entity.command('manuSpecificTuya_3', 'setOptions2', {data: buf});
break;
}
case 'power_threshold': {
const state = meta.state['power_breaker'];
utils.assertNumber(value, 'power_breaker');
const buf = Buffer.from([7, utils.getFromLookup(state, onOffLookup), 0, value]);
await entity.command('manuSpecificTuya_3', 'setOptions2', {data: buf});
break;
}
case 'power_breaker': {
const threshold = meta.state['power_threshold'];
utils.assertNumber(threshold, 'power_breaker');
const buf = Buffer.from([7, utils.getFromLookup(value, onOffLookup), 0, threshold]);
await entity.command('manuSpecificTuya_3', 'setOptions2', {data: buf});
break;
}
case 'over_current_threshold': {
const state = meta.state['over_current_breaker'];
utils.assertNumber(value, 'over_current_threshold');
const buf = Buffer.from([1, utils.getFromLookup(state, onOffLookup), 0, value]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
case 'over_current_breaker': {
const threshold = meta.state['over_current_threshold'];
utils.assertNumber(threshold, 'over_current_threshold');
const buf = Buffer.from([1, utils.getFromLookup(value, onOffLookup), 0, threshold]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
case 'over_voltage_threshold': {
const state = meta.state['over_voltage_breaker'];
utils.assertNumber(value, 'over_voltage_breaker');
const buf = Buffer.from([3, utils.getFromLookup(state, onOffLookup), 0, value]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
case 'over_voltage_breaker': {
const threshold = meta.state['over_voltage_threshold'];
utils.assertNumber(threshold, 'over_voltage_threshold');
const buf = Buffer.from([3, utils.getFromLookup(value, onOffLookup), 0, threshold]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
case 'under_voltage_threshold': {
const state = meta.state['under_voltage_breaker'];
utils.assertNumber(value, 'under_voltage_threshold');
const buf = Buffer.from([4, utils.getFromLookup(state, onOffLookup), 0, value]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
case 'under_voltage_breaker': {
const threshold = meta.state['under_voltage_threshold'];
utils.assertNumber(threshold, 'under_voltage_breaker');
const buf = Buffer.from([4, utils.getFromLookup(value, onOffLookup), 0, threshold]);
await entity.command('manuSpecificTuya_3', 'setOptions3', {data: buf});
break;
}
default: // Unknown key
meta.logger.warn(`Unhandled key ${key}`);
}
},
} as Tz.Converter,
};
const fzLocal = {
TS0222_humidity: {
...fz.humidity,
convert: (model, msg, publish, options, meta) => {
const result = fz.humidity.convert(model, msg, publish, options, meta);
result.humidity *= 10;
return result;
},
} as Fz.Converter,
TS110E: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
if (msg.data.hasOwnProperty('64515')) {
result['min_brightness'] = utils.mapNumberRange(msg.data['64515'], 0, 1000, 1, 255);
}
if (msg.data.hasOwnProperty('64516')) {
result['max_brightness'] = utils.mapNumberRange(msg.data['64516'], 0, 1000, 1, 255);
}
if (msg.data.hasOwnProperty('61440')) {
result['brightness'] = utils.mapNumberRange(msg.data['61440'], 0, 1000, 0, 255);
}
return result;
},
} as Fz.Converter,
TS110E_light_type: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
if (msg.data.hasOwnProperty('64514')) {
const lookup: KeyValue = {0: 'led', 1: 'incandescent', 2: 'halogen'};
result['light_type'] = lookup[msg.data['64514']];
}
return result;
},
} as Fz.Converter,
TS110E_switch_type: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
if (msg.data.hasOwnProperty('64514')) {
const lookup: KeyValue = {0: 'momentary', 1: 'toggle', 2: 'state'};
const propertyName = utils.postfixWithEndpointName('switch_type', msg, model, meta);
result[propertyName] = lookup[msg.data['64514']];
}
return result;
},
} as Fz.Converter,
scenes_recall_scene_65029: {
cluster: '65029',
type: ['raw', 'attributeReport'],
convert: (model, msg, publish, options, meta) => {
const id = meta.device.modelID === '005f0c3b' ? msg.data[0] : msg.data[msg.data.length - 1];
return {action: `scene_${id}`};
},
} as Fz.Converter,
TS0201_battery: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
// https://github.com/Koenkk/zigbee2mqtt/issues/11470
if (msg.data.batteryPercentageRemaining == 200 && msg.data.batteryVoltage < 30) return;
return fz.battery.convert(model, msg, publish, options, meta);
},
} as Fz.Converter,
TS0201_humidity: {
...fz.humidity,
convert: (model, msg, publish, options, meta) => {
if (meta.device.manufacturerName === '_TZ3000_ywagc4rj') {
msg.data['measuredValue'] *= 10;
}
return fz.humidity.convert(model, msg, publish, options, meta);
},
} as Fz.Converter,
humidity10: {
cluster: 'msRelativeHumidity',
type: ['attributeReport', 'readResponse'],
options: [exposes.options.precision('humidity'), exposes.options.calibration('humidity')],
convert: (model, msg, publish, options, meta) => {
const humidity = parseFloat(msg.data['measuredValue']) / 10.0;
if (humidity >= 0 && humidity <= 100) {
return {humidity: utils.calibrateAndPrecisionRoundOptions(humidity, options, 'humidity')};
}
},
} as Fz.Converter,
temperature_unit: {
cluster: 'manuSpecificTuya_2',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
if (msg.data.hasOwnProperty('57355')) {
result.temperature_unit = utils.getFromLookup(msg.data['57355'], {'0': 'celsius', '1': 'fahrenheit'});
}
return result;
},
} as Fz.Converter,
TS011F_electrical_measurement: {
...fz.electrical_measurement,
convert: (model, msg, publish, options, meta) => {
const result: KeyValueAny = fz.electrical_measurement.convert(model, msg, publish, options, meta);
const lookup: KeyValueString = {power: 'activePower', current: 'rmsCurrent', voltage: 'rmsVoltage'};
// Wait 5 seconds before reporting a 0 value as this could be an invalid measurement.
// https://github.com/Koenkk/zigbee2mqtt/issues/16709#issuecomment-1509599046
if (result && ['_TZ3000_gvn91tmx', '_TZ3000_amdymr7l', '_TZ3000_typdpbpg', '_TZ3000_hdopuwv6'].includes(meta.device.manufacturerName)) {
for (const key of ['power', 'current', 'voltage']) {
if (key in result) {
const value = result[key];
clearTimeout(globalStore.getValue(msg.endpoint, key));
if (value === 0) {
const configuredReporting = msg.endpoint.configuredReportings.find((c) =>
c.cluster.name === 'haElectricalMeasurement' && c.attribute.name === lookup[key]);
const time = ((configuredReporting ? configuredReporting.minimumReportInterval : 5) * 2) + 1;
globalStore.putValue(msg.endpoint, key, setTimeout(() => publish({[key]: value}), time * 1000));
delete result[key];
}
}
}
}
return result;
},
} as Fz.Converter,
TS011F_threshold: {
cluster: 'manuSpecificTuya_3',
type: 'raw',
convert: (model, msg, publish, options, meta) => {
const splitToAttributes = (value: Buffer): KeyValueAny => {
const result: KeyValue = {};
const len = value.length;
let i = 0;
while (i < len) {
const key = value.readUInt8(i);
result[key] = [value.readUInt8(i+1), value.readUInt16BE(i+2)];
i += 4;
}
return result;
};
const lookup: KeyValue = {0: 'OFF', 1: 'ON'};
const command = msg.data[2];
const data = msg.data.slice(3);
if (command == 0xE6) {
const value = splitToAttributes(data);
return {
'temperature_threshold': value[0x05][1],
'temperature_breaker': lookup[value[0x05][0]],
'power_threshold': value[0x07][1],
'power_breaker': lookup[value[0x07][0]],
};
}
if (command == 0xE7) {
const value = splitToAttributes(data);
return {
'over_current_threshold': value[0x01][1],
'over_current_breaker': lookup[value[0x01][0]],
'over_voltage_threshold': value[0x03][1],
'over_voltage_breaker': lookup[value[0x03][0]],
'under_voltage_threshold': value[0x04][1],
'under_voltage_breaker': lookup[value[0x04][0]],
};
}
},
} as Fz.Converter,
};
const definitions: Definition[] = [
{
zigbeeModel: ['TS0204'],
model: 'TS0204',
vendor: 'TuYa',
description: 'Gas sensor',
whiteLabel: [{vendor: 'Tesla Smart', model: 'TSL-SEN-GAS'}],
fromZigbee: [fz.ias_gas_alarm_1, fz.ignore_basic_report],
toZigbee: [],
exposes: [e.gas(), e.tamper()],
},
{
zigbeeModel: ['TS0205'],
model: 'TS0205',
vendor: 'TuYa',
description: 'Smoke sensor',
whiteLabel: [{vendor: 'Tesla Smart', model: 'TSL-SEN-SMOKE'}],
fromZigbee: [fz.ias_smoke_alarm_1, fz.battery, fz.ignore_basic_report],
toZigbee: [],
exposes: [e.smoke(), e.battery_low(), e.tamper(), e.battery()],
},
{
zigbeeModel: ['TS0111'],
model: 'TS0111',
vendor: 'TuYa',
description: 'Socket',
extend: tuya.extend.switch(),
},
{
zigbeeModel: ['TS0218'],
model: 'TS0218',
vendor: 'TuYa',
description: 'Button',
fromZigbee: [legacy.fromZigbee.TS0218_click, fz.battery],
exposes: [e.battery(), e.action(['click'])],
toZigbee: [],
},
{
zigbeeModel: ['TS0203'],
model: 'TS0203',
vendor: 'TuYa',
description: 'Door sensor',
fromZigbee: [fz.ias_contact_alarm_1, fz.battery, fz.ignore_basic_report, fz.ias_contact_alarm_1_report],
toZigbee: [],
exposes: [e.contact(), e.battery_low(), e.tamper(), e.battery(), e.battery_voltage()],
whiteLabel: [
{vendor: 'CR Smart Home', model: 'TS0203'},
{vendor: 'TuYa', model: 'iH-F001'},
{vendor: 'Tesla Smart', model: 'TSL-SEN-DOOR'},
{vendor: 'Cleverio', model: 'SS100'},
],
configure: async (device, coordinatorEndpoint, logger) => {
try {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint);
await reporting.batteryVoltage(endpoint);
} catch (error) {/* Fails for some*/}
},
},
{
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_bq5c8xfe'},
{modelID: 'TS0601', manufacturerName: '_TZE200_bjawzodf'},
{modelID: 'TS0601', manufacturerName: '_TZE200_qyflbnbj'},
{modelID: 'TS0601', manufacturerName: '_TZE200_vs0skpuc'},
{modelID: 'TS0601', manufacturerName: '_TZE200_44af8vyi'},
{modelID: 'TS0601', manufacturerName: '_TZE200_zl1kmjqx'}],
model: 'TS0601_temperature_humidity_sensor_1',
vendor: 'TuYa',
description: 'Temperature & humidity sensor',
fromZigbee: [legacy.fromZigbee.tuya_temperature_humidity_sensor],
toZigbee: [],
exposes: (device, options) => {
const exps: Expose[] = [e.temperature(), e.humidity(), e.battery()];
if (!device || device.manufacturerName === '_TZE200_qyflbnbj') {
exps.push(e.battery_low());
exps.push(e.enum('battery_level', ea.STATE, ['low', 'middle', 'high']).withDescription('Battery level state'));
}
exps.push(e.linkquality());
return exps;
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_yjjdcqsq', '_TZE200_9yapgbuv']),
model: 'TS0601_temperature_humidity_sensor_2',
vendor: 'TuYa',
description: 'Temperature and humidity sensor',
fromZigbee: [tuya.fz.datapoints, tuya.fz.gateway_connection_status],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [e.temperature(), e.humidity(), tuya.exposes.batteryState(), e.battery_low()],
meta: {
tuyaDatapoints: [
[1, 'temperature', tuya.valueConverter.divideBy10],
[2, 'humidity', tuya.valueConverter.raw],
[3, 'battery_state', tuya.valueConverter.batteryState],
// [9, 'temperature_unit', tuya.valueConverter.raw], This DP is not properly supported by the device
],
},
whiteLabel: [
tuya.whitelabel('TuYa', 'ZTH01', 'Temperature and humidity sensor', ['_TZE200_yjjdcqsq']),
tuya.whitelabel('TuYa', 'ZTH02', 'Temperature and humidity sensor', ['_TZE200_9yapgbuv']),
],
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_nvups4nh']),
model: 'TS0601_contact_temperature_humidity_sensor',
vendor: 'TuYa',
description: 'Contact, temperature and humidity sensor',
fromZigbee: [tuya.fz.datapoints, tuya.fz.gateway_connection_status],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [e.contact(), e.temperature(), e.humidity(), e.battery()],
meta: {
tuyaDatapoints: [
[1, 'contact', tuya.valueConverter.trueFalseInvert],
[2, 'battery', tuya.valueConverter.raw],
[7, 'temperature', tuya.valueConverter.divideBy10],
[8, 'humidity', tuya.valueConverter.raw],
],
},
whiteLabel: [
tuya.whitelabel('Aubess', '1005005194831629', 'Contact, temperature and humidity sensor', ['_TZE200_nvups4nh']),
],
},
{
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_vzqtvljm'}],
model: 'TS0601_illuminance_temperature_humidity_sensor',
vendor: 'TuYa',
description: 'Illuminance, temperature & humidity sensor',
fromZigbee: [legacy.fromZigbee.tuya_illuminance_temperature_humidity_sensor],
toZigbee: [],
exposes: [e.temperature(), e.humidity(), e.illuminance_lux(), e.battery()],
},
{
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_8ygsuhe1'},
{modelID: 'TS0601', manufacturerName: '_TZE200_yvx5lh6k'},
{modelID: 'TS0601', manufacturerName: '_TZE200_ryfmq5rl'},
{modelID: 'TS0601', manufacturerName: '_TZE200_c2fmom5z'}],
model: 'TS0601_air_quality_sensor',
vendor: 'TuYa',
description: 'Air quality sensor',
fromZigbee: [legacy.fromZigbee.tuya_air_quality],
toZigbee: [],
exposes: [e.temperature(), e.humidity(), e.co2(), e.voc().withUnit('ppm'), e.formaldehyd()],
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_dwcarsat', '_TZE200_mja3fuja']),
model: 'TS0601_smart_air_house_keeper',
vendor: 'TuYa',
description: 'Smart air house keeper',
fromZigbee: [legacy.fromZigbee.tuya_air_quality],
toZigbee: [],
exposes: [e.temperature(), e.humidity(), e.co2(), e.voc().withUnit('ppm'), e.formaldehyd().withUnit('µg/m³'),
e.pm25().withValueMin(0).withValueMax(999).withValueStep(1)],
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_ogkdpgy2', '_TZE200_3ejwxpmu']),
model: 'TS0601_co2_sensor',
vendor: 'TuYa',
description: 'NDIR co2 sensor',
fromZigbee: [legacy.fromZigbee.tuya_air_quality],
toZigbee: [],
exposes: [e.temperature(), e.humidity(), e.co2()],
},
{
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_7bztmfm1'}],
model: 'TS0601_smart_CO_air_box',
vendor: 'TuYa',
description: 'Smart air box (carbon monoxide)',
fromZigbee: [legacy.fromZigbee.tuya_CO],
toZigbee: [],
exposes: [e.carbon_monoxide(), e.co()],
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_ggev5fsl', '_TZE200_u319yc66', '_TZE204_yojqa8xn']),
model: 'TS0601_gas_sensor_1',
vendor: 'TuYa',
description: 'Gas sensor',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [e.gas(), tuya.exposes.selfTest(), tuya.exposes.selfTestResult(), tuya.exposes.faultAlarm(), tuya.exposes.silence()],
meta: {
tuyaDatapoints: [
[1, 'gas', tuya.valueConverter.trueFalse0],
[8, 'self_test', tuya.valueConverter.raw],
[9, 'self_test_result', tuya.valueConverter.selfTestResult],
[11, 'fault_alarm', tuya.valueConverter.trueFalse1],
[16, 'silence', tuya.valueConverter.raw],
],
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_yojqa8xn']),
model: 'TS0601_gas_sensor_2',
vendor: 'TuYa',
description: 'Gas sensor',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [
e.gas(), tuya.exposes.gasValue().withUnit('LEL'), tuya.exposes.selfTest(), tuya.exposes.selfTestResult(),
tuya.exposes.silence(),
e.enum('alarm_ringtone', ea.STATE_SET, ['1', '2', '3', '4', '5']).withDescription('Ringtone of the alarm'),
e.numeric('alarm_time', ea.STATE_SET).withValueMin(1).withValueMax(180).withValueStep(1)
.withUnit('s').withDescription('Alarm time'),
e.binary('preheat', ea.STATE, true, false).withDescription('Indicates sensor preheat is active'),
],
meta: {
tuyaDatapoints: [
[1, 'gas', tuya.valueConverter.trueFalseEnum0],
[2, 'gas_value', tuya.valueConverter.divideBy10],
[6, 'alarm_ringtone', tuya.valueConverterBasic.lookup({'1': 0, '2': 1, '3': 2, '4': 3, '5': 4})],
[7, 'alarm_time', tuya.valueConverter.raw],
[8, 'self_test', tuya.valueConverter.raw],
[9, 'self_test_result', tuya.valueConverter.selfTestResult],
[10, 'preheat', tuya.valueConverter.raw],
[13, null, null], // alarm_switch; ignore for now since it is unclear what it does
[16, 'silence', tuya.valueConverter.raw],
],
},
},
{
fingerprint: [{modelID: 'TS0001', manufacturerName: '_TZ3000_hktqahrq'}, {manufacturerName: '_TZ3000_hktqahrq'},
{manufacturerName: '_TZ3000_q6a3tepg'}, {modelID: 'TS000F', manufacturerName: '_TZ3000_m9af2l6g'},
{modelID: 'TS000F', manufacturerName: '_TZ3000_mx3vgyea'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_npzfdcof'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_5ng23zjs'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_rmjr4ufz'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_v7gnj3ad'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_3a9beq8a'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_ark8nv4y'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_mx3vgyea'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_qsp2pwtf'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_46t1rvdu'}],
model: 'WHD02',
vendor: 'TuYa',
whiteLabel: [{vendor: 'TuYa', model: 'iHSW02'}, {vendor: 'Aubess', model: 'TMZ02'}],
description: 'Wall switch module',
extend: tuya.extend.switch({switchType: true}),
configure: async (device, coordinatorEndpoint, logger) => {
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
await reporting.onOff(endpoint);
},
},
{
fingerprint: [{modelID: 'TS011F', manufacturerName: '_TZ3000_mvn6jl7x'},
{modelID: 'TS011F', manufacturerName: '_TZ3000_raviyuvk'}, {modelID: 'TS011F', manufacturerName: '_TYZB01_hlla45kx'},
{modelID: 'TS011F', manufacturerName: '_TZ3000_92qd4sqa'}, {modelID: 'TS011F', manufacturerName: '_TZ3000_zwaadvus'},
{modelID: 'TS011F', manufacturerName: '_TZ3000_k6fvknrr'}, {modelID: 'TS011F', manufacturerName: '_TZ3000_6s5dc9lx'}],
model: 'TS011F_2_gang_wall',
vendor: 'TuYa',
description: '2 gang wall outlet',
extend: tuya.extend.switch({backlightModeLowMediumHigh: true, childLock: true, endpoints: ['l1', 'l2']}),
whiteLabel: [{vendor: 'ClickSmart+', model: 'CMA30036'}],
endpoint: (device) => {
return {'l1': 1, 'l2': 2};
},
meta: {multiEndpoint: true},
configure: tuya.configureMagicPacket,
},
{
fingerprint: [{modelID: 'TS011F', manufacturerName: '_TZ3000_rk2yzt0u'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_o4cjetlm'}, {manufacturerName: '_TZ3000_o4cjetlm'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_iedbgyxt'}, {modelID: 'TS0001', manufacturerName: '_TZ3000_h3noz0a5'},
{modelID: 'TS0001', manufacturerName: '_TYZB01_4tlksk8a'}, {modelID: 'TS0011', manufacturerName: '_TYZB01_rifa0wlb'},
{modelID: 'TS0001', manufacturerName: '_TZ3000_5ucujjts'},
],
model: 'ZN231392',
vendor: 'TuYa',
description: 'Smart water/gas valve',
extend: tuya.extend.switch(),
configure: async (device, coordinatorEndpoint, logger) => {
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await endpoint.read('genOnOff', ['onOff', 'moesStartUpOnOff']);
},
},
{
zigbeeModel: ['CK-BL702-AL-01(7009_Z102LG03-1)'],
model: 'CK-BL702-AL-01',
vendor: 'TuYa',
description: 'Zigbee LED bulb',
extend: tuya.extend.light_onoff_brightness_colortemp_color({colorTempRange: [142, 500]}),
},
{
zigbeeModel: ['SM0001'],
model: 'SM0001',
vendor: 'TuYa',
description: 'Switch',
extend: tuya.extend.switch(),
configure: async (device, coordinatorEndpoint, logger) => {
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
await reporting.bind(device.getEndpoint(1), coordinatorEndpoint, ['genOnOff']);
},
whiteLabel: [
tuya.whitelabel('ZemiSmart', 'ZM-H7', 'Hand wave wall smart switch', ['_TZ3000_jcqs2mrv']),
],
},
{
zigbeeModel: ['TS0505B'],
model: 'TS0505B_1',
vendor: 'TuYa',
description: 'Zigbee RGB+CCT light',
whiteLabel: [{vendor: 'Mercator Ikuü', model: 'SMD4106W-RGB-ZB'},
{vendor: 'TuYa', model: 'A5C-21F7-01'}, {vendor: 'Mercator Ikuü', model: 'S9E27LED9W-RGB-Z'},
{vendor: 'Aldi', model: 'L122CB63H11A9.0W', description: 'LIGHTWAY smart home LED-lamp - bulb'},
{vendor: 'Lidl', model: '14153706L', description: 'Livarno smart LED ceiling light'},
{vendor: 'Zemismart', model: 'LXZB-ZB-09A', description: 'Zemismart LED Surface Mounted Downlight 9W RGBW'},
{vendor: 'Feconn', model: 'FE-GU10-5W', description: 'Zigbee GU10 5W smart bulb'},
{vendor: 'Nedis', model: 'ZBLC1E14'},
tuya.whitelabel('Aldi', 'L122FF63H11A5.0W', 'LIGHTWAY smart home LED-lamp - spot', ['_TZ3000_j0gtlepx']),
tuya.whitelabel('Aldi', 'L122AA63H11A6.5W', 'LIGHTWAY smart home LED-lamp - candle', ['_TZ3000_iivsrikg']),
tuya.whitelabel('Aldi', 'C422AC11D41H140.0W', 'MEGOS LED panel RGB+CCT 40W 3600lm 62 x 62 cm', ['_TZ3000_v1srfw9x']),
tuya.whitelabel('Aldi', 'C422AC14D41H140.0W', 'MEGOS LED panel RGB+CCT 40W 3600lm 30 x 120 cm', ['_TZ3000_gb5gaeca']),
tuya.whitelabel('MiBoxer', 'FUT066Z', 'RGB+CCT LED Downlight', ['_TZ3210_zrvxvydd']),
tuya.whitelabel('Miboxer', 'FUT039Z', 'RGB+CCT LED controller', ['_TZ3210_jicmoite']),
tuya.whitelabel('Lidl', '14156506L', 'Livarno Lux smart LED mood light', ['_TZ3210_r0xgkft5']),
tuya.whitelabel('Lidl', 'HG08010', 'Livarno Home outdoor spotlight', ['_TZ3210_umi6vbsz']),
tuya.whitelabel('Lidl', 'HG08008', 'Livarno Home LED ceiling light', ['_TZ3210_p9ao60da']),
tuya.whitelabel('TuYa', 'HG08007', 'Livarno Home outdoor LED band', ['_TZ3210_zbabx9wh']),
tuya.whitelabel('Lidl', '14158704L', 'Livarno Home LED floor lamp, RGBW', ['_TZ3210_z1vlyufu']),
tuya.whitelabel('Lidl', '14158804L', 'Livarno Home LED desk lamp RGBW', ['_TZ3210_hxtfthp5']),
tuya.whitelabel('Lidl', 'HG07834A', 'Livarno Lux GU10 spot RGB', ['_TZ3000_quqaeew6']),
tuya.whitelabel('Lidl', 'HG07834B', 'Livarno Lux E14 candle RGB', ['_TZ3000_th6zqqy6', '_TZ3000_wr6g6olr']),
tuya.whitelabel('Lidl', 'HG08131C', 'Livarno Home outdoor E27 bulb in set with flare', ['_TZ3000_q50zhdsc']),
tuya.whitelabel('Lidl', 'HG07834C', 'Livarno Lux E27 bulb RGB', ['_TZ3000_qd7hej8u']),
tuya.whitelabel('Lidl', 'HG08383B', 'Livarno outdoor LED light chain', ['_TZ3000_bwlvyjwk']),
tuya.whitelabel('Lidl', 'HG08383A', 'Livarno outdoor LED light chain', ['_TZ3000_taspddvq']),
tuya.whitelabel('Garza Smart', 'Garza-Standard-A60', 'Standard A60 bulb', ['_TZ3210_sln7ah6r']),
tuya.whitelabel('UR Lighting', 'TH008L10RGBCCT', '10W RGB+CCT downlight', ['_TZ3210_dn5higyl']),
tuya.whitelabel('Lidl', 'HG08010', 'Livarno Home outdoor spotlight', ['_TZ3210_umi6vbsz']),
tuya.whitelabel('Lidl', 'HG08008', 'Livarno Home LED ceiling light', ['_TZ3210_p9ao60da']),
tuya.whitelabel('Lidl', 'HG08007', 'Livarno Home outdoor LED band', ['_TZ3210_zbabx9wh']),
tuya.whitelabel('Lidl', '399629_2110', 'Livarno Lux Ceiling Panel RGB+CCT', ['_TZ3210_c0s1xloa']),
tuya.whitelabel('Skydance', 'WZ5_dim_2', 'Zigbee & RF 5 in 1 LED controller (DIM mode)', ['_TZB210_3zfp8mki']),
tuya.whitelabel('TuYa', 'TS0505B_1_1', 'Zigbee 3.0 18W led light bulb E27 RGBCW', ['_TZ3210_jd3z4yig']),
tuya.whitelabel('TuYa', 'TS0505B_1_2', 'Zigbee E14 dimmable smart bulb RGB+CW+WW', ['_TZ3210_it1u8ahz']),
tuya.whitelabel('TuYa', 'TS0505B_1_3', 'Zigbee 10W Downlight RGB CCW', ['_TZ3210_it1u8ahz']),
],
extend: tuya.extend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500], noConfigure: true}),
configure: async (device, coordinatorEndpoint, logger) => {
device.getEndpoint(1).saveClusterAttributeKeyValue('lightingColorCtrl', {colorCapabilities: 29});
},
},
{
fingerprint: tuya.fingerprint('TS0505B', ['_TZ3210_iystcadi']),
model: 'TS0505B_2',
vendor: 'TuYa',
description: 'Zigbee RGB+CCT light',
whiteLabel: [
tuya.whitelabel('Lidl', '14149505L/14149506L_2', 'Livarno Lux light bar RGB+CCT (black/white)', ['_TZ3210_iystcadi']),
],
toZigbee: [tz.on_off, tzLocal.led_control],
fromZigbee: [fz.on_off, fz.tuya_led_controller, fz.brightness, fz.ignore_basic_report],
exposes: [e.light_brightness_colortemp_colorhs([153, 500]).removeFeature('color_temp_startup')],
configure: async (device, coordinatorEndpoint, logger) => {
device.getEndpoint(1).saveClusterAttributeKeyValue('lightingColorCtrl', {colorCapabilities: 29});
},
},
{
zigbeeModel: ['TS0503B'],
model: 'TS0503B',
vendor: 'TuYa',
description: 'Zigbee RGB light',
whiteLabel: [{vendor: 'BTF-Lighting', model: 'C03Z'}],
extend: tuya.extend.light_onoff_brightness_color(),
},
{
zigbeeModel: ['TS0504B'],
model: 'TS0504B',
vendor: 'TuYa',
description: 'Zigbee RGBW light',
extend: tuya.extend.light_onoff_brightness_color(),
exposes: [e.light_brightness_color(false)
.setAccess('color_xy', ea.STATE_SET).setAccess('color_hs', ea.STATE_SET)],
toZigbee: utils.replaceInArray<Tz.Converter>(tuya.extend.light_onoff_brightness_color().toZigbee, [tz.light_color], [tzLocal.TS0504B_color]),
meta: {applyRedFix: true},
},
{
zigbeeModel: ['TS0501A'],
model: 'TS0501A',
description: 'Zigbee light',
vendor: 'TuYa',
extend: tuya.extend.light_onoff_brightness(),
meta: {turnsOffAtBrightness1: false},
whiteLabel: [
tuya.whitelabel('Lidl', 'HG06463A', 'Livarno Lux E27 ST64 filament bulb', ['_TZ3000_j2w1dw29']),
tuya.whitelabel('Lidl', 'HG06463B', 'Livarno Lux E27 G95 filament bulb', ['_TZ3000_nosnx7im']),
tuya.whitelabel('Lidl', 'HG06462A', 'Livarno Lux E27 A60 filament bulb', ['_TZ3000_7dcddnye', '_TZ3000_nbnmw9nc']),
],
},
{
zigbeeModel: ['TS0501B'],
model: 'TS0501B',
description: 'Zigbee light',
vendor: 'TuYa',
extend: tuya.extend.light_onoff_brightness(),
whiteLabel: [
tuya.whitelabel('Miboxer', 'FUT036Z', 'Single color LED controller', ['_TZ3210_dxroobu3', '_TZ3210_dbilpfqk']),
],
},
{
fingerprint: tuya.fingerprint('TS0202', ['_TYZB01_vwqnz1sn']),
model: 'TS0202_3',
vendor: 'TuYa',
description: 'Motion detector with illuminance',
fromZigbee: [fz.ias_occupancy_alarm_1, fz.battery, fz.ignore_basic_report, fz.ias_occupancy_alarm_1_report, fz.illuminance],
toZigbee: [],
onEvent: tuya.onEventSetTime,
configure: tuya.configureMagicPacket,
exposes: [e.occupancy(), e.battery_low(), e.battery(), e.tamper(), e.illuminance_lux()],
},
{
fingerprint: tuya.fingerprint('TS0202', ['_TZ3210_cwamkvua']),
model: 'TS0202_2',
vendor: 'TuYa',
description: 'Motion sensor with scene switch',
fromZigbee: [tuya.fz.datapoints, fz.ias_occupancy_alarm_1, fz.battery],
toZigbee: [tuya.tz.datapoints],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
await reporting.batteryPercentageRemaining(endpoint);
await reporting.batteryVoltage(endpoint);
},
exposes: [e.battery(), e.battery_voltage(), e.occupancy(), e.action(['single', 'double', 'hold']),
e.enum('light', ea.STATE, ['dark', 'bright'])],
meta: {
tuyaDatapoints: [
[102, 'light', tuya.valueConverterBasic.lookup({'dark': false, 'bright': true})],
[101, 'action', tuya.valueConverterBasic.lookup({'single': 0, 'double': 1, 'hold': 2})],
],
},
whiteLabel: [
{vendor: 'Linkoze', model: 'LKMSZ001'},
],
},
{
fingerprint: [{modelID: 'TS0202', manufacturerName: '_TYZB01_jytabjkb'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_lltemgsf'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_5nr7ncpl'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_mg4dy6z6'}],
model: 'TS0202_1',
vendor: 'TuYa',
description: 'Motion sensor',
// Requires alarm_1_with_timeout https://github.com/Koenkk/zigbee2mqtt/issues/2818#issuecomment-776119586
fromZigbee: [fz.ias_occupancy_alarm_1_with_timeout, fz.battery, fz.ignore_basic_report],
toZigbee: [],
exposes: [e.occupancy(), e.battery_low(), e.linkquality(), e.battery(), e.battery_voltage()],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint);
},
},
{
fingerprint: [{modelID: 'TS0202', manufacturerName: '_TYZB01_dr6sduka'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_ef5xlc9q'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_2b8f6cio'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_71kfvvma'},
{modelID: 'TS0202', manufacturerName: '_TZE200_bq5c8xfe'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_dl7cejts'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_nss8amz9'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_mmtwjmaq'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_zwvaj5wy'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_bsvqrxru'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_wrgn6xrz'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_tv3wxhcz'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_rwb0hxtf'},
{modelID: 'TS0202', manufacturerName: '_TYZB01_hqbdru35'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_otvn3lne'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_tiwq83wk'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_ykwcwxmz'},
// _TZ3000_kmh5qpmb = NAS-PD07 without temperature/humidity sensor
// https://github.com/Koenkk/zigbee2mqtt/issues/15481#issuecomment-1366003011
{modelID: 'TS0202', manufacturerName: '_TZ3000_kmh5qpmb'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_hgu1dlak'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_h4wnrtck'},
{modelID: 'TS0202', manufacturerName: '_TZ3000_sr0vaafi'},
{modelID: 'TS0202', manufacturerName: '_TZ3040_bb6xaihh'},
{modelID: 'WHD02', manufacturerName: '_TZ3000_hktqahrq'},
{modelID: 'TS0202', manufacturerName: '_TZ3040_wqmtjsyk'},
],
model: 'TS0202',
vendor: 'TuYa',
description: 'Motion sensor',
whiteLabel: [{vendor: 'Mercator Ikuü', model: 'SMA02P'},
{vendor: 'TuYa', model: 'TY-ZPR06'},
{vendor: 'Tesla Smart', model: 'TS0202'},
tuya.whitelabel('MiBoxer', 'PIR1-ZB', 'PIR sensor', ['_TZ3040_wqmtjsyk']),
tuya.whitelabel('TuYa', 'ZMS01', 'Motion sensor', ['_TZ3000_otvn3lne']),
tuya.whitelabel('Nous', 'E2', 'Motion sensor', ['_TZ3000_h4wnrtck']),
tuya.whitelabel('TuYa', '809WZT', 'Motion sensor', ['_TZ3040_bb6xaihh']),
],
fromZigbee: [fz.ias_occupancy_alarm_1, fz.battery, fz.ignore_basic_report, fz.ias_occupancy_alarm_1_report],
toZigbee: [],
exposes: [e.occupancy(), e.battery_low(), e.tamper(), e.battery(), e.battery_voltage()],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);