-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
HueSensor.js
2699 lines (2640 loc) · 91.2 KB
/
HueSensor.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
// homebridge-hue/lib/HueSensor.js
// Copyright © 2016-2020 Erik Baauw. All rights reserved.
//
// Homebridge plugin for Philips Hue and/or deCONZ.
//
// HueSensor provides support for Philips Hue sensors.
'use strict'
const moment = require('moment')
// Link this module to HuePlatform.
module.exports = {
setHomebridge: setHomebridge,
HueSensor: HueSensor
}
function toInt (value, minValue, maxValue) {
const n = parseInt(value)
if (isNaN(n) || n < minValue) {
return minValue
}
if (n > maxValue) {
return maxValue
}
return n
}
const daylightEvents = {
100: { name: 'Solar Midnight', period: 'Night' },
110: { name: 'Astronomical Dawn', period: 'Astronomical Twilight' },
120: { name: 'Nautical Dawn', period: 'Nautical Twilight' },
130: { name: 'Dawn', period: 'Twilight' },
140: { name: 'Sunrise', period: 'Sunrise' },
150: { name: 'End Sunrise', period: 'Golden Hour' },
160: { name: 'End Golden Hour', period: 'Day' },
170: { name: 'Solar Noon', period: 'Day' },
180: { name: 'Start Golden Hour', period: 'Golden Hour' },
190: { name: 'Start Sunset', period: 'Sunset' },
200: { name: 'Sunset', period: 'Twilight' },
210: { name: 'Dusk', period: 'Nautical Twilight' },
220: { name: 'Nautical Dusk', period: 'Astronomical Twilight' },
230: { name: 'Astronomical Dusk', period: 'Night' }
}
const daylightPeriods = {
Night: { lightlevel: 0, daylight: false, dark: true },
'Astronomical Twilight': { lightlevel: 100, daylight: false, dark: true },
'Nautical Twilight': { lightlevel: 1000, daylight: false, dark: true },
Twilight: { lightlevel: 10000, daylight: false, dark: false },
Sunrise: { lightlevel: 15000, daylight: true, dark: false },
Sunset: { lightlevel: 20000, daylight: true, dark: false },
'Golden Hour': { lightlevel: 40000, daylight: true, dark: false },
Day: { lightlevel: 65535, daylight: true, dark: false }
}
// ===== Homebridge ============================================================
// Link this module to homebridge.
let Service
let Characteristic
let my
let eve
// let HistoryService
let SINGLE
let SINGLE_DOUBLE
let SINGLE_LONG
let SINGLE_DOUBLE_LONG
// let DOUBLE
let DOUBLE_LONG
let LONG
function setHomebridge (homebridge, _my, _eve) {
Service = homebridge.hap.Service
Characteristic = homebridge.hap.Characteristic
my = _my
eve = _eve
SINGLE = {
minValue: Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
}
SINGLE_DOUBLE = {
minValue: Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS
}
SINGLE_LONG = {
minValue: Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.LONG_PRESS,
validValues: [
Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
Characteristic.ProgrammableSwitchEvent.LONG_PRESS
]
}
SINGLE_DOUBLE_LONG = {
minValue: Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.LONG_PRESS
}
// DOUBLE = {
// minValue: Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS,
// maxValue: Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS
// }
DOUBLE_LONG = {
minValue: Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.LONG_PRESS
}
LONG = {
minValue: Characteristic.ProgrammableSwitchEvent.LONG_PRESS,
maxValue: Characteristic.ProgrammableSwitchEvent.LONG_PRESS
}
}
function hkLightLevel (v) {
let l = v ? Math.pow(10, (v - 1) / 10000) : 0.0001
l = Math.round(l * 10000) / 10000
return l > 100000 ? 100000 : l < 0.0001 ? 0.0001 : l
}
const PRESS = 0
const HOLD = 1
const SHORT_RELEASE = 2
const LONG_RELEASE = 3
const DOUBLE_PRESS = 4
const TRIPLE_PRESS = 5
const QUADRUPLE_PRESS = 6
const SHAKE = 7
const DROP = 8
// const TILT = 9
// As homebridge-hue polls the Hue bridge, not all dimmer switch buttonevents
// are received reliably. Consequently, we only issue one HomeKit change per
// Press/Hold/Release event series.
function hkZLLSwitchAction (value, oldValue, repeat = false) {
const button = Math.floor(value / 1000)
const oldButton = Math.floor(oldValue / 1000)
const event = value % 1000
const oldEvent = oldValue % 1000
switch (event) {
case PRESS:
// Wait for Hold or Release after press.
return null
case SHORT_RELEASE:
return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
case HOLD:
case LONG_RELEASE:
if (repeat && (button === 2 || button === 3)) {
return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
}
if (button === oldButton && oldEvent === HOLD) {
// Already issued action on previous Hold.
return null
}
// falls through
case TRIPLE_PRESS:
case QUADRUPLE_PRESS:
return Characteristic.ProgrammableSwitchEvent.LONG_PRESS
case DOUBLE_PRESS:
case SHAKE:
case DROP:
return Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS
default:
return null
}
}
// ===== HueSensor =============================================================
function HueSensor (accessory, id, obj) {
this.accessory = accessory
this.id = id
this.obj = obj
this.bridge = this.accessory.bridge
this.log = this.accessory.log
this.serialNumber = this.accessory.serialNumber
this.name = this.obj.name
this.hk = {}
this.resource = '/sensors/' + id
this.serviceList = []
if (this.obj.type[0] === 'Z') {
// Zigbee sensor.
this.manufacturer = this.obj.manufacturername
this.model = this.obj.modelid
this.endpoint = this.obj.uniqueid.split('-')[1]
this.cluster = this.obj.uniqueid.split('-')[2]
this.subtype = this.endpoint + '-' + this.cluster
this.version = this.obj.swversion
} else {
// Hue bridge internal sensor.
this.manufacturer = this.bridge.manufacturername
if (this.accessory.isMulti) {
this.model = 'MultiCLIP'
this.subtype = this.id
} else if (
this.obj.manufacturername === 'homebridge-hue' &&
this.obj.modelid === this.obj.type &&
this.obj.uniqueid.split('-')[1] === this.id
) {
// Combine multiple CLIP sensors into one accessory.
this.model = 'MultiCLIP'
this.subtype = this.id
} else {
this.model = this.obj.type
}
this.version = this.bridge.version
}
this.infoService = this.accessory.getInfoService(this)
// See: http://www.developers.meethue.com/documentation/supported-sensors
let durationKey = 'duration'
switch (this.obj.type) {
case 'ZGPSwitch':
if (
this.obj.manufacturername === 'Philips' &&
this.obj.modelid === 'ZGPSWITCH'
) {
// 1.1 - Hue tap
this.createLabel(Characteristic.ServiceLabelNamespace.DOTS)
this.createButton(1, '1', SINGLE)
this.createButton(2, '2', SINGLE)
this.createButton(3, '3', SINGLE)
this.createButton(4, '4', SINGLE)
this.createButton(5, '1 and 2', SINGLE)
this.createButton(6, '3 and 4', SINGLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) {
return { 34: 1, 16: 2, 17: 3, 18: 4, 101: 5, 99: 6 }[v]
},
homekitAction: function () { return 0 }
}
} else if (
this.obj.manufacturername === 'PhilipsFoH' &&
this.obj.modelid === 'FOHSWITCH'
) {
// Friends of Hue switch
if (this.bridge.model === 'deCONZ') {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Top Left', SINGLE_LONG)
this.createButton(2, 'Bottom Left', SINGLE_LONG)
this.createButton(3, 'Top Right', SINGLE_LONG)
this.createButton(4, 'Bottom Right', SINGLE_LONG)
this.createButton(5, 'Top Both', SINGLE_LONG)
this.createButton(6, 'Bottom Both', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Top Left', SINGLE)
this.createButton(2, 'Bottom Left', SINGLE)
this.createButton(3, 'Top Right', SINGLE)
this.createButton(4, 'Bottom Right', SINGLE)
this.createButton(5, 'Top Both', SINGLE)
this.createButton(6, 'Bottom Both', SINGLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) {
return { 20: 1, 21: 2, 23: 3, 22: 4, 101: 5, 99: 6 }[v]
},
homekitAction: function () { return 0 }
}
}
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
break
case 'ZLLSwitch':
case 'ZHASwitch':
if (
this.obj.manufacturername === 'Philips' &&
(this.obj.modelid === 'RWL021' || this.obj.modelid === 'RWL020')
) {
// 1.2 - Hue wireless dimmer switch
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On', SINGLE_LONG)
if (this.bridge.platform.config.hueDimmerRepeat) {
this.repeat = true
this.createButton(2, 'Dim Up', SINGLE)
this.createButton(3, 'Dim Down', SINGLE)
} else {
this.createButton(2, 'Dim Up', SINGLE_LONG)
this.createButton(3, 'Dim Down', SINGLE_LONG)
}
this.createButton(4, 'Off', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Philips' &&
this.obj.modelid === 'ROM001'
) {
// Hue smart button
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Button', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'TRADFRI remote control'
) {
// Ikea Trådfri remote
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On/Off', SINGLE)
this.createButton(2, 'Dim Up', SINGLE_LONG)
this.createButton(3, 'Dim Down', SINGLE_LONG)
this.createButton(4, 'Previous', SINGLE_LONG)
this.createButton(5, 'Next', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'TRADFRI wireless dimmer'
) {
// Ikea Trådfri dimmer
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On', SINGLE)
this.createButton(2, 'Dim Up', SINGLE)
this.createButton(3, 'Dim Down', SINGLE)
this.createButton(4, 'Off', SINGLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'TRADFRI on/off switch'
) {
// Ikea Trådfri on/off switch
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On', SINGLE_LONG)
this.createButton(2, 'Off', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'TRADFRI open/close remote'
) {
// Ikea Trådfri open/close remote
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Open', SINGLE_LONG)
this.createButton(2, 'Close', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'SYMFONISK Sound Controller'
) {
// Ikea Symfonisk sound controller
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Button', SINGLE_DOUBLE_LONG)
this.createButton(2, 'Turn Right', LONG)
this.createButton(3, 'Turn Left', LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'innr' &&
this.obj.modelid === 'RC 110'
) {
// innr RC 110 remote, exposed as multiple ZHASwitch resources
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
if (this.endpoint === '01') {
this.createButton(1, 'On/Off', SINGLE)
this.createButton(2, 'Dim Up', SINGLE_LONG)
this.createButton(3, 'Dim Down', SINGLE_LONG)
this.createButton(4, '1', SINGLE)
this.createButton(5, '2', SINGLE)
this.createButton(6, '3', SINGLE)
this.createButton(7, '4', SINGLE)
this.createButton(8, '5', SINGLE)
this.createButton(9, '6', SINGLE)
} else {
const light = parseInt(this.endpoint) - 2
const button = 7 + light * 3
this.createButton(button, `On/Off ${light}`, SINGLE)
this.createButton(button + 1, `Dim Up ${light}`, SINGLE_LONG)
this.createButton(button + 2, `Dim Down ${light}`, SINGLE_LONG)
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'ubisys' &&
this.obj.modelid === 'S1 (5501)'
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, '1', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'ubisys' && (
this.obj.modelid === 'S1-R (5601)' ||
this.obj.modelid === 'S2 (5502)' ||
this.obj.modelid === 'S2-R (5602)' ||
this.obj.modelid === 'D1 (5503)' ||
this.obj.modelid === 'D1-R (5603)'
)
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, '1', SINGLE_LONG)
this.createButton(2, '2', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'ubisys' && (
this.obj.modelid === 'C4 (5504)' ||
this.obj.modelid === 'C4-R (5604)'
)
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, '1', SINGLE_LONG)
this.createButton(2, '2', SINGLE_LONG)
this.createButton(3, '3', SINGLE_LONG)
this.createButton(4, '4', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'dresden elektronik' &&
this.obj.modelid === 'Lighting Switch' && this.endpoint === '01'
) {
// dresden elektronik lighting switch
if (this.obj.mode !== 2) {
this.log.warn(
'%s: %s: warning: Lighting Switch mode %d instead of 2',
this.bridge.name, this.resource, this.obj.mode
)
}
this.createButton(1, 'Top Left', SINGLE_LONG)
this.createButton(2, 'Bottom Left', SINGLE_LONG)
this.createButton(3, 'Top Right', SINGLE_LONG)
this.createButton(4, 'Bottom Right', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'dresden elektronik' &&
this.obj.modelid === 'Scene Switch'
) {
// dresden elektronik scene switch
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On', SINGLE_LONG)
this.createButton(2, 'Off', SINGLE_LONG)
this.createButton(3, 'Scene 1', SINGLE)
this.createButton(4, 'Scene 2', SINGLE)
this.createButton(5, 'Scene 3', SINGLE)
this.createButton(6, 'Scene 4', SINGLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' &&
this.obj.modelid === 'lumi.sensor_86sw1'
) {
// Xiaomi wall switch (single button)
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Button', SINGLE_DOUBLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.sensor_switch' ||
this.obj.modelid === 'lumi.sensor_switch.aq2' ||
this.obj.modelid === 'lumi.sensor_switch.aq3'
)
) {
// Xiaomi Mi wireless switch
// Xiaomi Aqara smart wireless switch
// Xiaomi Aqara smart wireless switch with gyro
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Button', SINGLE_DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.sensor_86sw2' ||
this.obj.modelid === 'lumi.ctrl_ln2.aq1'
)
) {
// Xiaomi wall switch (two buttons)
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Left', SINGLE_DOUBLE)
this.createButton(2, 'Right', SINGLE_DOUBLE)
this.createButton(3, 'Both', SINGLE_DOUBLE)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.remote.b1acn01' ||
this.obj.modelid === 'lumi.remote.b186acn01'
)
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Left', SINGLE_DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' &&
this.obj.modelid === 'lumi.remote.b286acn01'
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Left', SINGLE_DOUBLE_LONG)
this.createButton(2, 'Right', SINGLE_DOUBLE_LONG)
this.createButton(3, 'Both', SINGLE_DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'LUMI' &&
this.obj.modelid.startsWith('lumi.sensor_cube')
) {
// Xiaomi Mi smart cube
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
if (this.endpoint === '02') {
this.createButton(1, 'Side 1', SINGLE_DOUBLE_LONG)
this.createButton(2, 'Side 2', SINGLE_DOUBLE_LONG)
this.createButton(3, 'Side 3', SINGLE_DOUBLE_LONG)
this.createButton(4, 'Side 4', SINGLE_DOUBLE_LONG)
this.createButton(5, 'Side 5', SINGLE_DOUBLE_LONG)
this.createButton(6, 'Side 6', SINGLE_DOUBLE_LONG)
this.createButton(7, 'Cube', DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: function (v) {
if (v % 1000 === 0) {
return Characteristic.ProgrammableSwitchEvent.LONG_PRESS
} else if (v % 1000 === Math.floor(v / 1000) || v % 1000 === 8) {
return Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS
} else {
return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
}
}
}
} else if (this.endpoint === '03') {
this.createButton(8, 'Turn Right', SINGLE_DOUBLE_LONG)
this.createButton(9, 'Turn Left', SINGLE_DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return v > 0 ? 8 : 9 },
homekitAction: function (v) {
return Math.abs(v) < 4500
? Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
: Math.abs(v) < 9000
? Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS
: Characteristic.ProgrammableSwitchEvent.LONG_PRESS
}
}
}
} else if (
this.obj.manufacturername === 'Insta' && (
this.obj.modelid === 'WS_3f_G_1' ||
this.obj.modelid === 'HS_4f_GJ_1' ||
this.obj.modelid === 'WS_4f_J_1'
)
) {
// Gira Light Link wall transmitter
// Gira/Jung Light Link hand transmitter
// Jung Light Link wall transmitter
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Off', SINGLE_DOUBLE_LONG)
this.createButton(2, 'On', SINGLE_DOUBLE_LONG)
this.createButton(3, 'Scene 1', SINGLE)
this.createButton(4, 'Scene 2', SINGLE)
this.createButton(5, 'Scene 3', SINGLE)
this.createButton(6, 'Scene 4', SINGLE)
if (this.obj.modelid !== 'WS_3f_G_1') {
this.createButton(7, 'Scene 5', SINGLE)
this.createButton(8, 'Scene 6', SINGLE)
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Busch-Jaeger' && (
this.obj.modelid === 'RM01' ||
this.obj.modelid === 'RB01'
)
) {
// Busch-Jaeger Light Link control element (mains-powered)
// Busch-Jaeger Light Link wall-mounted transmitter
// Exposed as multiple ZHASwitch resources?
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
if (this.endpoint === '0a') {
this.createButton(1, 'Button 1', SINGLE_LONG)
this.createButton(2, 'Button 2', SINGLE_LONG)
} else if (this.endpoint === '0b') {
this.createButton(3, 'Button 3', SINGLE_LONG)
this.createButton(4, 'Button 4', SINGLE_LONG)
} else if (this.endpoint === '0c') {
this.createButton(5, 'Button 5', SINGLE_LONG)
this.createButton(6, 'Button 6', SINGLE_LONG)
} else if (this.endpoint === '0d') {
this.createButton(7, 'Button 7', SINGLE_LONG)
this.createButton(8, 'Button 8', SINGLE_LONG)
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'icasa' && (
this.obj.modelid === 'ICZB-KPD12' ||
this.obj.modelid === 'ICZB-KPD14S' ||
this.obj.modelid === 'ICZB-KPD18S'
)
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Off', SINGLE_LONG)
this.createButton(2, 'On', SINGLE_LONG)
if (this.obj.modelid !== 'ICZB-KPD12') {
this.createButton(3, 'S1', SINGLE)
this.createButton(4, 'S2', SINGLE)
if (this.obj.modelid === 'ICZB-KPD18S') {
this.createButton(5, 'S3', SINGLE)
this.createButton(6, 'S4', SINGLE)
this.createButton(7, 'S5', SINGLE)
this.createButton(8, 'S6', SINGLE)
}
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Lutron' &&
this.obj.modelid === 'Z3-1BRL'
) {
// Lutron Aurora, see #522.
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
if (this.bridge.isHue) {
this.createButton(1, 'Button', SINGLE_LONG)
} else {
this.createButton(1, 'Button', SINGLE)
this.createButton(2, 'Turn Right', SINGLE)
this.createButton(3, 'Turn Left', SINGLE)
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Samjin' &&
this.obj.modelid === 'button'
) {
// Samsung SmartThings Button
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'Button', SINGLE_DOUBLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Sunricher' &&
this.obj.modelid === 'ZG2833K8_EU05'
) {
// Sunricher 8-button remote, see #529.
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
if (this.endpoint === '01') {
this.createButton(1, 'On 1', SINGLE_LONG)
this.createButton(2, 'Off 1', SINGLE_LONG)
} else if (this.endpoint === '02') {
this.createButton(3, 'On 2', SINGLE_LONG)
this.createButton(4, 'Off 2', SINGLE_LONG)
} else if (this.endpoint === '03') {
this.createButton(5, 'On 3', SINGLE_LONG)
this.createButton(6, 'Off 3', SINGLE_LONG)
} else if (this.endpoint === '04') {
this.createButton(7, 'On 4', SINGLE_LONG)
this.createButton(8, 'Off 4', SINGLE_LONG)
}
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else if (
this.obj.manufacturername === 'Sunricher' &&
this.obj.modelid === 'ZGRC-KEY-002'
) {
// Sunricher CCT remote, see #529.
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(1, 'On', SINGLE)
this.createButton(2, 'Off', SINGLE)
this.createButton(3, 'Dim', LONG)
this.createButton(4, 'C/W', SINGLE_LONG)
this.type = {
key: 'buttonevent',
homekitValue: function (v) { return Math.floor(v / 1000) },
homekitAction: hkZLLSwitchAction
}
} else {
this.log.warn(
'%s: %s: warning: ignoring unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
break
case 'ZLLRelativeRotary':
// Lutron Aurora, see #522.
if (
this.obj.manufacturername === 'Lutron' &&
this.obj.modelid === 'Z3-1BRL'
) {
this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS)
this.createButton(2, 'Turn Right', SINGLE)
this.createButton(3, 'Turn Left', SINGLE)
this.type = {
key: 'expectedrotation',
homekitValue: function (v) { return v > 0 ? 2 : 3 },
homekitAction: function () {
return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
}
}
} else {
this.log.warn(
'%s: %s: warning: ignoring unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
break
case 'CLIPSwitch': // 2.1
// We'd need a way to specify the number of buttons, cf. max value for
// a CLIPGenericStatus sensor.
this.log.warn(
'%s: %s: warning: ignoring unsupported sensor type %s',
this.bridge.name, this.resource, this.obj.type
)
break
case 'ZLLPresence':
this.duration = 0
// falls through
case 'ZHAPresence':
if (
this.obj.manufacturername === 'Philips' &&
(this.obj.modelid === 'SML001' || this.obj.modelid === 'SML002')
) {
// 1.3 - Hue motion sensor
durationKey = 'delay'
} else if (
this.obj.manufacturername === 'IKEA of Sweden' &&
this.obj.modelid === 'TRADFRI motion sensor'
) {
// Ikea Trådfri motion sensor
this.obj.state.dark = false
} else if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.sensor_motion' ||
this.obj.modelid === 'lumi.sensor_motion.aq2'
)
) {
// Xiaomi motion sensor
// Xiaomi Aqara motion sensor
} else if (
this.obj.manufacturername === 'Heiman' &&
this.obj.modelid === 'PIR_TPV11'
) {
// Heiman motion sensor
} else if (
this.obj.manufacturername === 'SmartThings' &&
this.obj.modelid === 'tagv4'
) {
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPPresence': // 2.3
case 'Geofence': // Undocumented
this.service = new eve.Services.MotionSensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: Characteristic.MotionDetected,
key: 'presence',
name: 'motion',
unit: '',
history: 'motion',
homekitValue: function (v) { return v ? 1 : 0 },
durationKey: durationKey,
sensitivitymax: this.obj.config.sensitivitymax
}
break
case 'ZLLTemperature':
case 'ZHATemperature':
if (
this.obj.manufacturername === 'Philips' &&
(this.obj.modelid === 'SML001' || this.obj.modelid === 'SML002')
) {
// 1.4 - Hue motion sensor
} else if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.weather' ||
this.obj.modelid === 'lumi.sensor_ht'
)
) {
// Xiaomi temperature/humidity sensor
// Xiaomi Aqara weather sensor
} else if (
this.obj.manufacturername === 'Heiman' &&
(this.obj.modelid === 'TH-H_V15' || this.obj.modelid === 'TH-T_V15')
) {
// Heiman temperature/humidity sensor
} else if (
this.obj.manufacturername === 'Samjin' &&
this.obj.modelid === 'button'
) {
// Samsung SmartThings Button temperature sensor
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPTemperature': // 2.4
this.service = new eve.Services.TemperatureSensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: Characteristic.CurrentTemperature,
props: { minValue: -40.0, maxValue: 100.0 },
key: 'temperature',
name: 'temperature',
unit: '°C',
history: 'weather',
homekitValue: function (v) { return v ? Math.round(v / 10) / 10 : 0 }
}
break
case 'ZLLLightLevel': // 2.7 - Hue Motion Sensor
case 'ZHALightLevel':
if (
this.obj.manufacturername === 'Philips' &&
(this.obj.modelid === 'SML001' || this.obj.modelid === 'SML002')
) {
// 1.4 - Hue motion sensor
} else if (
this.obj.manufacturername === 'LUMI' &&
this.obj.modelid === 'lumi.sensor_motion.aq2'
) {
// Xiaomi Aqara motion sensor
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPLightLevel': // 2.7
this.service = new Service.LightSensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: Characteristic.CurrentAmbientLightLevel,
key: 'lightlevel',
name: 'light level',
unit: ' lux',
homekitValue: hkLightLevel
}
break
case 'ZHAOpenClose':
if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.sensor_magnet.aq2' ||
this.obj.modelid === 'lumi.sensor_magnet'
)
) {
// Xiaomi Aqara door/window sensor
// Xiaomi Mi door/window sensor
} else if (
this.obj.manufacturername === 'Heiman' &&
this.obj.modelid === 'DOOR_TPV13'
) {
// Heiman smart door sensor
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPOpenClose': // 2.2
this.service = new eve.Services.ContactSensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: Characteristic.ContactSensorState,
key: 'open',
name: 'contact',
unit: '',
history: 'door',
homekitValue: function (v) { return v ? 1 : 0 }
}
break
case 'ZHAHumidity':
if (
this.obj.manufacturername === 'LUMI' && (
this.obj.modelid === 'lumi.weather' ||
this.obj.modelid === 'lumi.sensor_ht'
)
) {
// Xiaomi Aqara weather sensor
// Xiaomi Mi temperature/humidity sensor
} else if (
this.obj.manufacturername === 'Heiman' &&
(this.obj.modelid === 'TH-H_V15' || this.obj.modelid === 'TH-T_V15')
) {
// Heiman temperature/humidity sensor
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPHumidity': // 2.5
this.service = new Service.HumiditySensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: Characteristic.CurrentRelativeHumidity,
key: 'humidity',
name: 'humidity',
unit: '%',
history: 'weather',
homekitValue: function (v) { return v ? Math.round(v / 100) : 0 }
}
break
case 'ZHAPressure':
if (
this.obj.manufacturername === 'LUMI' &&
this.obj.modelid === 'lumi.weather'
) {
// Xiaomi Aqara weather sensor
} else {
this.log.warn(
'%s: %s: warning: unknown %s sensor %j',
this.bridge.name, this.resource, this.obj.type, this.obj
)
}
// falls through
case 'CLIPPressure':
this.service = new eve.Services.AirPressureSensor(this.name, this.subtype)
this.serviceList.push(this.service)
this.type = {
Characteristic: eve.Characteristics.AirPressure,