forked from Koenkk/zigbee-herdsman-converters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inovelli.js
1315 lines (1270 loc) · 42.2 KB
/
inovelli.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
const fz = require('../converters/fromZigbee');
const tz = require('../converters/toZigbee');
const exposes = require('../lib/exposes');
const globalStore = require('../lib/store');
const reporting = require('../lib/reporting');
const ota = require('../lib/ota');
const utils = require('../lib/utils');
const e = exposes.presets;
const ea = exposes.access;
const clickLookup = {
0: 'single',
1: 'release',
2: 'held',
3: 'double',
4: 'triple',
5: 'quadruple',
6: 'quintuple',
};
const buttonLookup = {
1: 'down',
2: 'up',
3: 'config',
};
const ledEffects = {
off: 0,
solid: 1,
fast_blink: 2,
slow_blink: 3,
pulse: 4,
chase: 5,
open_close: 6,
small_to_big: 7,
aurora: 8,
slow_falling: 9,
medium_falling: 10,
fast_falling: 11,
slow_rising: 12,
medium_rising: 13,
fast_rising: 14,
medium_blink: 15,
slow_chase: 16,
fast_chase: 17,
fast_siren: 18,
slow_siren: 19,
clear_effect: 255,
};
const individualLedEffects = {
off: 0,
solid: 1,
fast_blink: 2,
slow_blink: 3,
pulse: 4,
chase: 5,
falling: 6,
rising: 7,
aurora: 8,
clear_effect: 255,
};
const UINT8 = 32;
const BOOLEAN = 16;
const UINT16 = 33;
const INOVELLI = 0x122f;
const ATTRIBUTES = {
dimmingSpeedUpRemote: {
ID: 1,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light dims up when controlled from the hub. ' +
'A setting of 0 turns the light immediately on. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 25 (2.5s)',
},
dimmingSpeedUpLocal: {
ID: 2,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light dims up when controlled at the switch. ' +
'A setting of 0 turns the light immediately on. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with dimmingSpeedUpRemote setting.',
},
rampRateOffToOnRemote: {
ID: 3,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light turns on when controlled from the hub. ' +
'A setting of 0 turns the light immediately on. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with dimmingSpeedUpRemote setting.',
},
rampRateOffToOnLocal: {
ID: 4,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light turns on when controlled at the switch. ' +
'A setting of 0 turns the light immediately on. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with dimmingSpeedUpRemote setting.',
},
dimmingSpeedDownRemote: {
ID: 5,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light dims down when controlled from the hub. ' +
'A setting of 0 turns the light immediately off. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with dimmingSpeedUpRemote setting.',
},
dimmingSpeedDownLocal: {
ID: 6,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light dims down when controlled at the switch. ' +
'A setting of 0 turns the light immediately off. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with dimmingSpeedUpLocal setting.',
},
rampRateOnToOffRemote: {
ID: 7,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light turns off when controlled from the hub. ' +
'A setting of \'instant\' turns the light immediately off. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with rampRateOffToOnRemote setting.',
},
rampRateOnToOffLocal: {
ID: 8,
dataType: UINT8,
min: 0,
max: 127,
description:
'This changes the speed that the light turns off when controlled at the switch. ' +
'A setting of \'instant\' turns the light immediately off. Increasing the value slows down the transition speed. ' +
'Every number represents 100ms. Default = 127 - Keep in sync with rampRateOffToOnLocal setting.',
},
minimumLevel: {
ID: 9,
dataType: UINT8,
min: 1,
max: 253,
description:
'The minimum level that the dimmer allows the bulb to be dimmed to. ' +
'Useful when the user has an LED bulb that does not turn on or flickers at a lower level.',
},
maximumLevel: {
ID: 10,
dataType: UINT8,
min: 2,
max: 254,
description:
'The maximum level that the dimmer allows the bulb to be dimmed to.' +
'Useful when the user has an LED bulb that reaches its maximum level before the ' +
'dimmer value of 99 or when the user wants to limit the maximum brightness.',
},
invertSwitch: {
ID: 11,
dataType: BOOLEAN,
displayType: 'enum',
values: {Yes: 1, No: 0},
min: 0,
max: 1,
description:
'Inverts the orientation of the switch.' +
' Useful when the switch is installed upside down. Essentially up becomes down and down becomes up.',
},
autoTimerOff: {
ID: 12,
min: 0,
max: 32767,
dataType: UINT16,
unit: 'seconds',
values: {Disabled: 0},
description:
'Automatically turns the switch off after this many seconds.' +
' When the switch is turned on a timer is started. When the timer expires, the switch is turned off. 0 = Auto off is disabled.',
},
defaultLevelLocal: {
ID: 13,
dataType: UINT8,
min: 0,
max: 255,
description:
'Default level for the dimmer when it is turned on at the switch.' +
' A setting of 255 means that the switch will return to the level that it was on before it was turned off.',
},
defaultLevelRemote: {
ID: 14,
dataType: UINT8,
min: 0,
max: 255,
description:
'Default level for the dimmer when it is turned on from the hub.' +
' A setting of 255 means that the switch will return to the level that it was on before it was turned off.',
},
stateAfterPowerRestored: {
ID: 15,
dataType: UINT8,
min: 0,
max: 255,
description:
'The state the switch should return to when power is restored after power failure. 0 = off, 1-254 = level, 255 = previous.',
},
loadLevelIndicatorTimeout: {
ID: 17,
dataType: UINT8,
description:
'Shows the level that the load is at for x number of seconds after the load is adjusted' +
' and then returns to the Default LED state. 0 = Stay Off, 1-10 = seconds, 11 = Stay On.',
displayType: 'enum',
values: {
'Stay Off': 0,
'1 Second': 1,
'2 Seconds': 2,
'3 Seconds': 3,
'4 Seconds': 4,
'5 Seconds': 5,
'6 Seconds': 6,
'7 Seconds': 7,
'8 Seconds': 8,
'9 Seconds': 9,
'10 Seconds': 10,
'Stay On': 11,
},
min: 0,
max: 11,
},
activePowerReports: {
ID: 18,
dataType: UINT8,
min: 0,
max: 100,
description:
'Percent power level change that will result in a new power report being sent. 0 = Disabled',
},
periodicPowerAndEnergyReports: {
ID: 19,
min: 0,
max: 32767,
dataType: UINT16,
description:
'Time period between consecutive power & energy reports being sent (in seconds). The timer is reset after each report is sent.',
},
activeEnergyReports: {
ID: 20,
dataType: UINT16,
min: 0,
max: 32767,
description:
'Energy reports Energy level change which will result in sending a new energy report.' +
'0 = disabled, 1-32767 = 0.01kWh-327.67kWh. Default setting: 10 (0.1 kWh)',
},
powerType: {
ID: 21,
dataType: BOOLEAN,
displayType: 'enum',
values: {'Non Neutral': 0, 'Neutral': 1},
min: 0,
max: 1,
readOnly: true,
description: 'Set the power type for the device.',
},
switchType: {
ID: 22,
dataType: UINT8,
displayType: 'enum',
values: {'Single Pole': 0, '3-Way Dumb Switch': 1, '3-Way Aux Switch': 2},
min: 0,
max: 2,
description: 'Set the switch configuration.',
},
buttonDelay: {
ID: 50,
dataType: UINT8,
values: {
'0ms': 0,
'100ms': 1,
'200ms': 2,
'300ms': 3,
'400ms': 4,
'500ms': 5,
'600ms': 6,
'700ms': 7,
'800ms': 8,
'900ms': 9,
},
displayType: 'enum',
min: 0,
max: 9,
description:
'This will set the button press delay. 0 = no delay (Disables Button Press Events),' +
'Default = 500ms.',
},
smartBulbMode: {
ID: 52,
dataType: BOOLEAN,
displayType: 'enum',
values: {'Disabled': 0, 'Smart Bulb Mode': 1},
description:
'For use with Smart Bulbs that need constant power and are controlled via commands rather than power.',
},
ledColorWhenOn: {
ID: 95,
dataType: UINT8,
min: 0,
max: 255,
values: {
Red: 0,
Orange: 21,
Yellow: 42,
Green: 85,
Cyan: 127,
Blue: 170,
Violet: 212,
Pink: 234,
White: 255,
},
description: 'Set the color of the LED Indicator when the load is on.',
},
ledColorWhenOff: {
ID: 96,
dataType: UINT8,
min: 0,
max: 255,
values: {
Red: 0,
Orange: 21,
Yellow: 42,
Green: 85,
Cyan: 127,
Blue: 170,
Violet: 212,
Pink: 234,
White: 255,
},
description: 'Set the color of the LED Indicator when the load is off.',
},
ledIntensityWhenOn: {
ID: 97,
dataType: UINT8,
min: 0,
max: 100,
description: 'Set the intensity of the LED Indicator when the load is on.',
},
ledIntensityWhenOff: {
ID: 98,
dataType: UINT8,
min: 0,
max: 100,
description: 'Set the intensity of the LED Indicator when the load is off.',
},
localProtection: {
ID: 256,
dataType: BOOLEAN,
values: {Disabled: 0, Enabled: 1},
description: 'Ability to control switch from the wall.',
displayType: 'enum',
},
remoteProtection: {
ID: 257,
dataType: BOOLEAN,
values: {Disabled: 0, Enabled: 1},
readOnly: true,
description: 'Ability to control switch from the hub.',
displayType: 'enum',
},
outputMode: {
ID: 258,
min: 0,
max: 1,
values: {'Dimmer': 0, 'On/Off': 1},
dataType: BOOLEAN,
description: 'Use device as a Dimmer or an On/Off switch.',
displayType: 'enum',
},
onOffLedMode: {
ID: 259,
min: 0,
max: 1,
values: {All: 0, One: 1},
dataType: BOOLEAN,
description:
'When the device is in On/Off mode, use full LED bar or just one LED.',
displayType: 'enum',
},
firmwareUpdateInProgressIndicator: {
ID: 260,
dataType: BOOLEAN,
values: {Disabled: 0, Enabled: 1},
description: 'Display progress on LED bar during firmware update.',
displayType: 'enum',
},
defaultLed1ColorWhenOn: {
ID: 60,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed1ColorWhenOff: {
ID: 61,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed1IntensityWhenOn: {
ID: 62,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed1IntensityWhenOff: {
ID: 63,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed2ColorWhenOn: {
ID: 65,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed2ColorWhenOff: {
ID: 66,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed2IntensityWhenOn: {
ID: 67,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed2IntensityWhenOff: {
ID: 68,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed3ColorWhenOn: {
ID: 70,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed3ColorWhenOff: {
ID: 71,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed3IntensityWhenOn: {
ID: 72,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed3IntensityWhenOff: {
ID: 73,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed4ColorWhenOn: {
ID: 75,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed4ColorWhenOff: {
ID: 76,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed4IntensityWhenOn: {
ID: 77,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed4IntensityWhenOff: {
ID: 78,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed5ColorWhenOn: {
ID: 80,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed5ColorWhenOff: {
ID: 81,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed5IntensityWhenOn: {
ID: 82,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed5IntensityWhenOff: {
ID: 83,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed6ColorWhenOn: {
ID: 85,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed6ColorWhenOff: {
ID: 86,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed6IntensityWhenOn: {
ID: 87,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed6IntensityWhenOff: {
ID: 88,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed7ColorWhenOn: {
ID: 90,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed7ColorWhenOff: {
ID: 91,
dataType: UINT8,
min: 0,
max: 255,
description:
'0-254:This is the color of the LED strip in a hex representation. 255:Synchronization with default all LED strip color parameter.',
},
defaultLed7IntensityWhenOn: {
ID: 92,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when on. 101 = Syncronized with default all LED strip intensity parameter.',
},
defaultLed7IntensityWhenOff: {
ID: 93,
dataType: UINT8,
min: 0,
max: 101,
description:
'Intesity of LED strip when off. 101 = Syncronized with default all LED strip intensity parameter.',
},
doubleTapUpForFullBrightness: {
ID: 53,
dataType: BOOLEAN,
min: 0,
max: 1,
description: 'Result of a double tap on the up button.',
values: {
'Button Press Event Only': 0,
'Button Press Event + Set Load to 100%': 1,
},
displayType: 'enum',
},
relayClick: {
ID: 261,
dataType: BOOLEAN,
min: 0,
max: 1,
description:
'In neutral on/off setups, the default is to have a clicking sound to notify you that the relay ' +
'is open or closed. You may disable this sound by creating a, “simulated” on/off where the switch ' +
'only will turn onto 100 or off to 0.',
values: {'Disabled (Click Sound On)': 0, 'Enabled (Click Sound Off)': 1},
displayType: 'enum',
},
doubleTapClearNotifications: {
ID: 262,
dataType: BOOLEAN,
min: 0,
max: 1,
description: 'Double-Tap the Config button to clear notifications.',
values: {'Enabled (Default)': 0, 'Disabled': 1},
displayType: 'enum',
},
};
const tzLocal = {};
// Generate toZigbee items from attribute list.
tzLocal.inovelli_vzw31sn_parameters = {
key: Object.keys(ATTRIBUTES).filter((a) => !ATTRIBUTES[a].readOnly),
convertSet: async (entity, key, value, meta) => {
const payload = {
[ATTRIBUTES[key].ID]: {
value:
ATTRIBUTES[key].displayType === 'enum' ?
ATTRIBUTES[key].values[value] :
value,
type: ATTRIBUTES[key].dataType,
},
};
await entity.write('manuSpecificInovelliVZM31SN', payload, {
manufacturerCode: INOVELLI,
});
meta.state[key] = value;
return {
state: {
[key]: value,
},
};
},
convertGet: async (entity, key, meta) => {
const value = await entity.read('manuSpecificInovelliVZM31SN', [key], {
manufacturerCode: INOVELLI,
});
if (ATTRIBUTES[key].displayType === 'enum') {
const valueState = Object.keys(ATTRIBUTES[key].values).find(
(a) => ATTRIBUTES[key].values[a] === value[key],
);
meta.state[key] = valueState;
return {
state: {
[key]: valueState,
},
};
} else {
meta.state[key] = value[key];
return {state: value};
}
},
};
tzLocal.inovelli_vzw31sn_parameters_readOnly = {
key: Object.keys(ATTRIBUTES).filter((a) => ATTRIBUTES[a].readOnly),
convertGet: async (entity, key, meta) => {
const value = await entity.read('manuSpecificInovelliVZM31SN', [key], {
manufacturerCode: INOVELLI,
});
if (ATTRIBUTES[key].displayType === 'enum') {
const valueState = Object.keys(ATTRIBUTES[key].values).find(
(a) => ATTRIBUTES[key].values[a] === value[key],
);
meta.state[key] = valueState;
return {
state: {
[key]: valueState,
},
};
} else {
meta.state[key] = value[key];
return {state: value};
}
},
convertSet: undefined,
};
tzLocal.inovelli_led_effect = {
key: ['led_effect'],
convertSet: async (entity, key, values, meta) => {
await entity.command(
'manuSpecificInovelliVZM31SN',
'ledEffect',
{
effect: ledEffects[values.effect],
color: Math.min(Math.max(0, values.color), 255),
level: Math.min(Math.max(0, values.level), 100),
duration: Math.min(Math.max(0, values.duration), 255),
},
{disableResponse: true, disableDefaultResponse: true},
);
return {state: {[key]: values}};
},
};
tzLocal.inovelli_individual_led_effect = {
key: ['individual_led_effect'],
convertSet: async (entity, key, values, meta) => {
await entity.command(
'manuSpecificInovelliVZM31SN',
'individualLedEffect',
{
led: Math.min(Math.max(0, parseInt(values.led)), 7),
effect: individualLedEffects[values.effect],
color: Math.min(Math.max(0, values.color), 255),
level: Math.min(Math.max(0, values.level), 100),
duration: Math.min(Math.max(0, values.duration), 255),
},
{disableResponse: true, disableDefaultResponse: true},
);
return {state: {[key]: values}};
},
};
/*
* Inovelli VZM31SN has a default transition property that the device should
* fallback to if a transition is not specified by passing 0xffff
*/
const inovelliOnOffConvertSet = async (entity, key, value, meta) => {
const state = meta.message.hasOwnProperty('state') ?
meta.message.state.toLowerCase() :
null;
utils.validateValue(state, ['toggle', 'off', 'on']);
if (
state === 'on' &&
(meta.message.hasOwnProperty('on_time') ||
meta.message.hasOwnProperty('off_wait_time'))
) {
const onTime = meta.message.hasOwnProperty('on_time') ?
meta.message.on_time :
0;
const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ?
meta.message.off_wait_time :
0;
if (typeof onTime !== 'number') {
throw Error('The on_time value must be a number!');
}
if (typeof offWaitTime !== 'number') {
throw Error('The off_wait_time value must be a number!');
}
const payload = {
ctrlbits: 0,
ontime: meta.message.hasOwnProperty('on_time') ?
Math.round(onTime * 10) :
0xffff,
offwaittime: meta.message.hasOwnProperty('off_wait_time') ?
Math.round(offWaitTime * 10) :
0xffff,
};
await entity.command(
'genOnOff',
'onWithTimedOff',
payload,
utils.getOptions(meta.mapped, entity),
);
} else {
await entity.command(
'genOnOff',
state,
{},
utils.getOptions(meta.mapped, entity),
);
if (state === 'toggle') {
const currentState =
meta.state[
`state${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`
];
return currentState ?
{state: {state: currentState === 'OFF' ? 'ON' : 'OFF'}} :
{};
} else {
return {state: {state: state.toUpperCase()}};
}
}
};
/**
* Inovelli VZM31SN has a default transition property that the device should
* fallback to if a transition is not specified by passing 0xffff
*/
tzLocal.light_onoff_brightness_inovelli = {
key: ['state', 'brightness', 'brightness_percent'],
convertSet: async (entity, key, value, meta) => {
const {message} = meta;
const transition = utils.getTransition(entity, 'brightness', meta);
const turnsOffAtBrightness1 = utils.getMetaValue(
entity,
meta.mapped,
'turnsOffAtBrightness1',
'allEqual',
false,
);
let state = message.hasOwnProperty('state') ?
message.state.toLowerCase() :
undefined;
let brightness = undefined;
if (message.hasOwnProperty('brightness')) {
brightness = Number(message.brightness);
} else if (message.hasOwnProperty('brightness_percent')) {
brightness = utils.mapNumberRange(
Number(message.brightness_percent),
0,
100,
0,
255,
);
}
if (
brightness !== undefined &&
(isNaN(brightness) || brightness < 0 || brightness > 255)
) {
// Allow 255 value, changing this to 254 would be a breaking change.
throw new Error(
`Brightness value of message: '${JSON.stringify(
message,
)}' invalid, must be a number >= 0 and =< 254`,
);
}
if (
state !== undefined &&
['on', 'off', 'toggle'].includes(state) === false
) {
throw new Error(
`State value of message: '${JSON.stringify(
message,
)}' invalid, must be 'ON', 'OFF' or 'TOGGLE'`,
);
}
if (
state === 'toggle' ||
state === 'off' ||
(brightness === undefined && state === 'on')
) {
if (transition.specified && transition.time > 0) {
if (state === 'toggle') {
state = meta.state.state === 'ON' ? 'off' : 'on';
}
if (
state === 'off' &&
meta.state.brightness &&
meta.state.state === 'ON'
) {
// https://github.com/Koenkk/zigbee2mqtt/issues/2850#issuecomment-580365633
// We need to remember the state before turning the device off as we need to restore
// it once we turn it on again.
// We cannot rely on the meta.state as when reporting is enabled the bulb will reports
// it brightness while decreasing the brightness.
globalStore.putValue(entity, 'brightness', meta.state.brightness);
globalStore.putValue(entity, 'turnedOffWithTransition', true);
}
const fallbackLevel = utils.getObjectProperty(
meta.state,
'brightness',
254,
);
let level =
state === 'off' ?
0 :
globalStore.getValue(entity, 'brightness', fallbackLevel);
if (state === 'on' && level === 0) {
level = turnsOffAtBrightness1 ? 2 : 1;
}
const payload = {level, transtime: transition.time};
await entity.command(
'genLevelCtrl',
'moveToLevelWithOnOff',
payload,
utils.getOptions(meta.mapped, entity),
);
const result = {state: {state: state.toUpperCase()}};
if (state === 'on') result.state.brightness = level;
return result;
} else {
if (
state === 'on' &&
globalStore.getValue(entity, 'turnedOffWithTransition') === true
) {
/**
* In case the bulb it turned OFF with a transition and turned ON WITHOUT
* a transition, the brightness is not recovered as it turns on with brightness 1.
* https://github.com/Koenkk/../issues/1073
*/
globalStore.putValue(entity, 'turnedOffWithTransition', false);
await entity.command(
'genLevelCtrl',
'moveToLevelWithOnOff',
{
level: globalStore.getValue(entity, 'brightness'),
transtime: transition.specified ? transition.time : 0xffff,
},
utils.getOptions(meta.mapped, entity),
);
const defaultTransitionTime = await entity.read(
'manuSpecificInovelliVZM31SN',
['rampRateOffToOnRemote'],
);
return {
state: {state: 'ON'},
readAfterWriteTime: transition.specified ?
transition.time * 100 :
defaultTransitionTime.rampRateOffToOnRemote * 100,
};
} else {
// Store brightness where the bulb was turned off with as we need it when the bulb is turned on
// with transition.
if (meta.state.hasOwnProperty('brightness') && state === 'off') {
globalStore.putValue(entity, 'brightness', meta.state.brightness);
globalStore.putValue(entity, 'turnedOffWithTransition', true);
}
const result = await inovelliOnOffConvertSet(
entity,
'state',
state,
meta,
);
result.readAfterWriteTime = 0;
if (
result.state &&
result.state.state === 'ON' &&
meta.state.brightness === 0
) {
result.state.brightness = 1;
}
return result;
}