-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinovelli-vzm32-sn-zone.groovy
More file actions
4010 lines (3857 loc) · 206 KB
/
Copy pathinovelli-vzm32-sn-zone.groovy
File metadata and controls
4010 lines (3857 loc) · 206 KB
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
def getDriverDate() { return "2026-04-16" } // **** DATE OF THE DEVICE DRIVER
// ^^^^^^^^^^ UPDATE DRIVER DATE IF YOU MAKE ANY CHANGES ^^^^^^^^^^
/*
* Inovelli VZM32-SN Blue Series Zigbee 2-in-1 mmWave
*
* Author: Eric Maycock (erocm123)
* Contributor: Mark Amber (marka75160)
* Platform: Hubitat
*
* Copyright 2026 Eric Maycock / Inovelli
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !! !!
* !! DON'T FORGET TO UPDATE THE DRIVER DATE AT THE TOP OF THIS PAGE !!
* !! !!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* 2026-04-16(EM) Always bind to MMWave Private Cluster for Reports etc.
* 2026-01-30(EM) Added targetInfo and targetCount attributes
* 2025-12-26(EM) Fixing group binding input type from number to string. Change so that default settings are not cleared.
* 2025-12-12(EM) Fixing lux reporting parameters showing up twice.
* 2025-12-03(EM) Fixing bug in dimming method reporting.
* 2025-10-03(EM) Added feature to prevent updates to unchanged parameters.
* 2025-09-29(EM) Scaling for lux reporting added to configure().
* 2025-09-28(EM) Scaling the lux reporting min for the illuminance cluster 0x0400. Making reports min change correct.
* 2025-07-18(EM) Added configurable lux reporting intervals (parameters 301-303) for illuminance cluster 0x0400
* 2026-06-24(EM) calculate lux value according to zigbee spec and use a new method to differentiate between
* mmwave and regular preferences
* 2025-04-24(EM) temporarily not setting P52 as it is causing the switch load to shut off
* 2025-04-10(EM) fix on/off not reporting anymore. Had to set reporting with on/off cluster
* 2025-03-10(EM) fix binding for occupancy and illuminance.
* 2025-03-07(EM) fix for some mmwave parameters not being set.
* 2025-03-05(EM) adding advanced mmwave commands.
* 2025-03-04(EM) adding some attributes for firmware 0.03. Ability to check firmware versions by pressing refresh.
* 2025-03-01(EM) updating fingerprint for fw 0.03. Adding button to update mmwave firmware.
* 2024-07-29(EM) change size of p108 to 1
* 2024-07-25(EM) adding parameter 103 for mmWave sensitivity
*
*/
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovy.transform.Field
import hubitat.device.HubAction
import hubitat.device.HubMultiAction
import hubitat.device.Protocol
import hubitat.helper.ColorUtils
import hubitat.helper.HexUtils
import java.security.MessageDigest
metadata {
definition (name: "Inovelli mmWave Dimmer Blue Series VZM32-SN", namespace: "InovelliUSA", author: "E.Maycock/M.Amber", filename: "Inovelli-zigbee-2-in-1-dimmer", importUrl:"https://raw.githubusercontent.com/InovelliUSA/Hubitat/refs/heads/master/Drivers/inovelli-mmwave-dimmer-blue-series-vzm32-sn.src/inovelli-mmwave-dimmer-blue-series-vzm32-sn.groovy" )
{
capability "Actuator" //device can "do" something (has commands)
capability "Sensor" //device can "report" something (has attributes)
capability "ChangeLevel"
capability "Configuration"
capability "EnergyMeter" //Fan does not support energy monitoring but Dimmer does
//capability "FanControl"
capability "HoldableButton"
capability "Initialize"
capability "LevelPreset"
capability "PowerMeter" //Fan does not support power monitoring but Dimmer does
capability "PushableButton"
capability "Refresh"
capability "ReleasableButton"
capability "SignalStrength"
capability "Switch"
capability "SwitchLevel"
capability "Motion Sensor"
capability "Illuminance Measurement"
attribute "lastButton", "String" //last button event
attribute "ledEffect", "String" //last LED effect requested (may have timed-out and not necessarily displaying currently)
attribute "internalTemp", "String" //Internal Temperature in Celsius (read-only P32)
attribute "numberOfBindings", "String" //Group bindings count as 2 (read only P51)
attribute "overHeat", "String" //Overheat Indicator (read-only P33)
attribute "powerSource", "String" //Neutral/non-Neutral (read-only P21)
attribute "remoteProtection", "String" //Enabled or Disabled (read-only P257)
attribute "smartBulb", "String" //Smart Bulb mode enabled or disabled
attribute "switchMode", "String" //Dimmer or On/Off only
attribute "LQI", "String" //Link Quality Indicator
attribute "RSSI", "String" //Received Signal Strength Indicator
attribute "firmware", "String"
attribute "mmWaveFirmware", "String"
attribute "targetInfo", "string"
attribute "targetCount", "number"
// [zone-fork] Per-zone occupancy attributes. Up to 4 user-defined
// rectangular zones map to area0..area3. Driven by software in
// ReportTargetInfoCommandEvent — not by the device's hardware
// AnyoneInTheReportingArea command (which only reports a single
// boolean across all areas in the current firmware).
attribute "area0", "string"
attribute "area1", "string"
attribute "area2", "string"
attribute "area3", "string"
// Uncomment these lines if you would like to test your scenes with digital button presses.
/*
command "pressUpX1"
command "pressDownX1"
command "pressUpX2"
command "pressDownX2"
command "pressUpX3"
command "pressDownX3"
command "pressUpX4"
command "pressDownX4"
command "pressUpX5"
command "pressDownX5"
command "holdUp"
command "holdDown"
command "releaseUp"
command "releaseDown"
command "pressConfigX1"
command "pressConfigX2"
command "pressConfigX3"
command "pressConfigX4"
command "pressConfigX5"
command "holdConfig"
command "releaseConfig"
*/
command "bind", [[name:"Command String", type:"STRING", description: "passthru for Binding Apps but may be used to manually enter ZDO Bind/Unbind commands"]]
command "bindInitiator", [[name:"use this 2nd on source (initiator) switch to COMPLETE binding with slave switch"]]
command "bindTarget", [[name:"use this 1st on slave (target) switch to START binding with source switch"]]
command "configure", [[name:"Option", type:"ENUM", description:"blank=current states and user-changed settings, All=configure all settings, Default=set all settings to default", constraints:[" ","All","Default"]]]
command "getRssiLQI", [[name:"Get radio signal strength and link quality"]]
//command "getTemperature", [[name:"Get the switch internal operating temperature"]]
command "identify", [[name:"Seconds", type:"NUMBER", description:"number of seconds to blink the LED bar so it can be identified (leave blank to see remaining seconds in the logs)"],
[name:"number of seconds to blink the LED bar so it can be identified (leave blank to see remaining seconds in the logs)"]]
command "initialize", [[name:"clear state variables, clear LED notifications, refresh current states"]]
command "ledEffectAll", [[name:"Effect*", type:"ENUM",
description: "255=Stop, 1=Solid, 2=Fast Blink, 3=Slow Blink, 4=Pulse, 5=Chase, 6=Open/Close, 7=Small-to-Big, 8=Aurora, 9=Slow Falling, 10=Medium Falling, 11=Fast Falling, 12=Slow Rising, 13=Medium Rising, 14=Fast Rising, 15=Medium Blink, 16=Slow Chase, 17=Fast Chase, 18=Fast Siren, 19=Slow Siren, 0=LEDs off",
constraints: ["255=Stop","1=Solid","2=Fast Blink","3=Slow Blink","4=Pulse","5=Chase","6=Open/Close","7=Small-to-Big","8=Aurora","9=Slow Falling","10=Medium Falling","11=Fast Falling","12=Slow Rising","13=Medium Rising","14=Fast Rising","15=Medium Blink","16=Slow Chase","17=Fast Chase","18=Fast Siren","19=Slow Siren","0=LEDs off"]],
[name:"Color", type:"NUMBER", description: "0-254=Hue Color, 255=White, default=Red"],
[name:"Level", type:"NUMBER", description: "0-100=LED Intensity, default=100"],
[name:"Duration", type:"NUMBER", description: "1-60=seconds, 61-120=1-120 minutes, 121-254=1-134 hours, 255=Indefinitely, default=60"]]
command "ledEffectOne", [[name:"LEDnum*", type:"ENUM", description: "LED 1-7", constraints: ["7 (top)","6","5","4 (middle)","3","2","1 (bottom)","123 (bottom half)","567 (top half)","12 (bottom 3rd)","345 (middle 3rd)","67 (top 3rd)","147 (bottom-middle-top)","1357 (odd)","246 (even)"]],
[name:"Effect*", type:"ENUM",
description: "255=Stop, 1=Solid, 2=Fast Blink, 3=Slow Blink, 4=Pulse, 5=Chase, 6=Falling, 7=Rising, 8=Aurora, 0=LED off",
constraints:["255=Stop","1=Solid","2=Fast Blink","3=Slow Blink","4=Pulse","5=Chase","6=Falling","7=Rising","8=Aurora","0=LED off"]],
[name:"Color", type:"NUMBER", description:"0-254=Hue Color, 255=White, default=Red"],
[name:"Level", type:"NUMBER", description:"0-100=LED Intensity, default=100"],
[name:"Duration", type:"NUMBER", description:"1-60=seconds, 61-120=1-120 minutes, 121-254=1-134 hours, 255=Indefinitely, default=60"]]
command "presetLevel", [[name:"Level", type:"NUMBER", description:"Level to preset (1 to 101)"]]
command "refresh", [[name:"Option", type:"ENUM", description:"blank=current states and user-changed settings, All=refresh all settings", constraints: [" ","All"]]]
command "remoteControl", [[name:"Option*", type:"ENUM", description:"ability to control the switch remotely", constraints: [" ","Enabled","Disabled"]]]
command "resetEnergyMeter" //Fan does not support power/energy reporting but Dimmer does
command "setParameter", [[name:"Parameter*",type:"NUMBER", description:"Parameter number"],
[name:"Raw Value", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"Enter the internal raw value. Percentages and Color Hues are entered as 0-255. Leave blank to get current value"]]
//command "setSpeed", [[name:"FanSpeed*", type:"ENUM", constraints:["off","low","medium-low","medium","medium-high","high","up","down"]]] //Dimmer does not support setSpeed commands but Fan does
command "setZigbeeAttribute", [[name:"Cluster*", type:"NUMBER", description:"Cluster (in decimal) ex. Inovelli Private Cluster=0xFC31 input 64561"],
[name:"Attribute*",type:"NUMBER", description:"Attribute (in decimal) ex. 0x0100 input 256"],
[name:"Value", type:"NUMBER", description:"Enter the value (in decimal, ex. 0x0F input 15) Leave blank to get current value without changing it"],
[name:"Size", type:"ENUM", description:"8=uint8, 16=uint16, 32=unint32, 1=bool",constraints: ["8", "16","32","1"]]]
command "startLevelChange", [[name:"Direction*",type:"ENUM", description:"Direction for level change", constraints: ["up","down"]],
[name:"Duration", type:"NUMBER", description:"Transition duration in seconds"]]
command "toggle"
command "updateFirmware", [[name:"Firmware in this channel may be \"beta\" quality"]]
command "updateMMWaveFirmware", [[name:"Firmware in this channel may be \"beta\" quality"]]
// MMWave specific commands
//command "mmWaveSetHoldtime", [[name:"holdtime", type:"NUMBER", description:"holdtime"]] //Moved to cluster attribute
//command "mmWaveSetZAXIS", [[name:"zmin",type:"NUMBER", description:"zmin"], //Moved to cluster attribute
// [name:"zmax", type:"NUMBER", description:"zmax"]]
// Start and (automatically or manually) stop the MMWave Calibration
command "startCalibrationZoneCreation"
command "stopCalibrationZoneCreation"
command "mmWaveControlInstruction", [[name:"id", type:"NUMBER", description: "0=Reset mmWave Module, 1=Generate Interference Area, 2=Obtain Interference Area, 3=Clear Interference Area, 4=Reset Detection Area, 5=Clear the Stay Area"]]
command "mmWaveSetInterferenceArea", [[name:"areaid*",type:"NUMBER", description:"Parameter number"],
[name:"xmin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"xmax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"ymin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"ymax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"zmin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"zmax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"Enter the internal raw value. Percentages and Color Hues are entered as 0-255. Leave blank to get current value"]]
command "mmWaveSetDetectionArea", [[name:"areaid*",type:"NUMBER", description:"Parameter number"],
[name:"xmin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"xmax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"ymin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"ymax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"zmin", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"zmax", type:"NUMBER", description:"Value for the parameter (leave blank to get current value)"],
[name:"Enter the internal raw value. Percentages and Color Hues are entered as 0-255. Leave blank to get current value"]]
fingerprint profileId:"0104", endpointId:"01", inClusters:"0000,0003,0004,0005,0006,0008,0400,0406,0702,0B04,0B05,FC31,FC32,FC57", outClusters:"0019", model:"VZM32-SN", manufacturer:"Inovelli"
}
preferences {
(userSettableParams() + [301, 302, 303]).each{ i ->
switch(configParams["parameter${i.toString().padLeft(3,"0")}"].type){
case "number":
switch(i){
case readOnlyParams().contains(i):
//read-only params are non-settable, so skip user input
break
default:
input "parameter${i}", "number",
title: "${i}. " + bold(configParams["parameter${i.toString().padLeft(3,"0")}"].name),
description: italic(configParams["parameter${i.toString().padLeft(3,"0")}"].description +
"<br>Range=" + configParams["parameter${i.toString().padLeft(3,"0")}"].range +
" Default=" + configParams["parameter${i.toString().padLeft(3,"0")}"].default),
//defaultValue: configParams["parameter${i.toString().padLeft(3,"0")}"].default,
range: configParams["parameter${i.toString().padLeft(3,"0")}"].range
break
}
break
case "enum":
switch(i){
case readOnlyParams().contains(i):
//read-only params are non-settable, so skip user input
break
case 22: //Aux Type
case 52: //Smart Bulb Mode
case 158: //Switch Mode Zwave
case 258: //Switch Mode Zigbee
//these are important parameters so display in red to draw attention
input "parameter${i}", "enum",
title: "${i}. " + indianRed(bold(configParams["parameter${i.toString().padLeft(3,"0")}"].name)),
description: italic(configParams["parameter${i.toString().padLeft(3,"0")}"].description),
defaultValue: configParams["parameter${i.toString().padLeft(3,"0")}"].default,
options: configParams["parameter${i.toString().padLeft(3,"0")}"].range
break
case 95:
case 96:
//special case for custom color is below
break
default:
input "parameter${i}", "enum",
title: "${i}. " + bold(configParams["parameter${i.toString().padLeft(3,"0")}"].name),
description: italic(configParams["parameter${i.toString().padLeft(3,"0")}"].description),
//defaultValue: configParams["parameter${i.toString().padLeft(3,"0")}"].default,
options: configParams["parameter${i.toString().padLeft(3,"0")}"].range
break
}
break
}
if (i==95 || i==96) {
if ((i==95 && parameter95custom==null)||(i==96 && parameter96custom==null)){
input "parameter${i}", "enum",
title: "${i}. " + hue((settings?."parameter${i}"!=null?settings?."parameter${i}":configParams["parameter${i.toString().padLeft(3,"0")}"].default)?.toInteger(),
bold(configParams["parameter${i.toString().padLeft(3,"0")}"].name)),
description: italic(configParams["parameter${i.toString().padLeft(3,"0")}"].description),
//defaultValue: configParams["parameter${i.toString().padLeft(3,"0")}"].default,
options: configParams["parameter${i.toString().padLeft(3,"0")}"].range
} else {
input "parameter${i}", "enum",
title: "${i}. " + hue((settings?."parameter${i}"!=null?settings?."parameter${i}":configParams["parameter${i.toString().padLeft(3,"0")}"].default)?.toInteger(),
strike(configParams["parameter${i.toString().padLeft(3,"0")}"].name)) +
hue((settings?."parameter${i}custom"!=null?(settings."parameter${i}custom"/360*255):configParams["parameter${i.toString().padLeft(3,"0")}"].default)?.toInteger(),
italic(bold(" Overridden by Custom Hue Value"))),
description: italic(configParams["parameter${i.toString().padLeft(3,"0")}"].description),
//defaultValue: configParams["parameter${i.toString().padLeft(3,"0")}"].default,
options: configParams["parameter${i.toString().padLeft(3,"0")}"].range
}
input "parameter${i}custom", "number",
title: settings?."parameter${i}custom"!=null?
(hue((settings."parameter${i}custom"/360*255)?.toInteger(),
bold("Custom " + configParams["parameter${i.toString().padLeft(3,"0")}"].name))):
( bold("Custom " + configParams["parameter${i.toString().padLeft(3,"0")}"].name)),
description: italic("Hue value to override " + configParams["parameter${i.toString().padLeft(3,"0")}"].name+".<br>Range: 0-360 chosen from a "+
underline(''' <a href="https://community-assets.home-assistant.io/original/3X/6/c/6c0d1ea7c96b382087b6a34dee6578ac4324edeb.png" target="_blank">'''+
hue(0,"h")+hue(15,"u")+hue(30,"e")+hue(70," c")+hue(85,"o")+hue(100,"l")+hue(120,"o")+hue(140,"r")+hue(160," w")+hue(180,"h")+hue(200,"e")+hue(220,"e")+hue(240,"l")+"</a>")),
required: false,
range: "0..360"
}
}
input name: "groupBinding1", type: "string", title: bold("Group Bind #1"), description: italic("Enter the Zigbee Group ID or leave blank to UNBind. To specify the source endpoint proceed the group with \"ep#.\". So if you want to bind ep 3 to group 9 you would input 3.9"), defaultValue: null, range: "1..65527"
input name: "groupBinding2", type: "string", title: bold("Group Bind #2"), description: italic("Enter the Zigbee Group ID or leave blank to UNBind. To specify the source endpoint proceed the group with \"ep#.\". So if you want to bind ep 3 to group 9 you would input 3.9"), defaultValue: null, range: "1..65527"
input name: "groupBinding3", type: "string", title: bold("Group Bind #3"), description: italic("Enter the Zigbee Group ID or leave blank to UNBind. To specify the source endpoint proceed the group with \"ep#.\". So if you want to bind ep 3 to group 9 you would input 3.9"), defaultValue: null, range: "1..65527"
// [zone-fork] Software per-zone occupancy configuration.
input name: "zoneConfigJson", type: "text",
title: bold("Zone Config (JSON)"),
description: italic("Optional. JSON list of up to 4 rectangles in the device's mmWave coordinate space (mm; +x right, +y forward, origin at the switch). Each entry: {name:'area0..area3', xMin, xMax, yMin, yMax}. Leave blank to disable zone detection. Requires param 107 (targetInfo) enabled. Example: [{\"name\":\"area0\",\"xMin\":-600,\"xMax\":600,\"yMin\":0,\"yMax\":300}]"),
defaultValue: ""
input name: "infoEnable", type: "bool", title: bold("Enable Info Logging"), defaultValue: true, description: italic("Log general device activity<br>(optional and not required for normal operation)")
input name: "traceEnable", type: "bool", title: bold("Enable Trace Logging"), defaultValue: false, description: italic("Additional info for trouble-shooting (not needed unless having issues)")
input name: "debugEnable", type: "bool", title: bold("Enable Debug Logging"), defaultValue: false, description: italic("Detailed diagnostic data<br>"+fireBrick("(only enable when asked by a developer)"))
input name: "disableInfoLogging", type: "number", title: bold("Disable Info Logging after this number of minutes"), description: italic("(0=Do not disable, default=20)"), defaultValue: 20
input name: "disableTraceLogging", type: "number", title: bold("Disable Trace Logging after this number of minutes"), description: italic("(0=Do not disable, default=10)"), defaultValue: 10
input name: "disableDebugLogging", type: "number", title: bold("Disable Debug Logging after this number of minutes"), description: italic("(0=Do not disable, default=5)"), defaultValue: 5
}
}
def intTo16bitHex(value) {
value = (short)value
byte[] byteArray = new byte[2]
byteArray[0] = (value >> 8)
byteArray[1] = (value & 0xFF)
return String.format('%02X%02X',byteArray[1],byteArray[0]);
}
def mmWaveControlInstruction(cmdid) {
if (infoEnable) log.info "${device.displayName} mmWaveControlInstruction()"
state.lastCommandSent = "mmWaveControlInstruction()"
state.lastCommandTime = nowFormatted()
def cmds = zigbee.command(0xfc32,0x00,["mfgCode":"0x122F"],shortDelay,"${intTo8bitUnsignedHex(cmdid)}")
return cmds
}
def mmWaveSetInterferenceArea(areaid, xmin, xmax,ymin,ymax,zmin,zmax)
{
def cmds =[]
Integer cmdareaid = areaid.toInteger()
Integer cmdxmin = xmin.toInteger()
Integer cmdxmax = xmax.toInteger()
Integer cmdymin = ymin.toInteger()
Integer cmdymax= ymax.toInteger()
Integer cmdzmin = zmin.toInteger()
Integer cmdzmax= zmax.toInteger()
cmds += zigbee.command(0xfc32,0x01,["mfgCode":"0x122F"],shortDelay,"${intTo8bitUnsignedHex(cmdareaid)} ${intTo16bitHex(cmdxmin)} ${intTo16bitHex(cmdxmax)} ${intTo16bitHex(cmdymin)} ${intTo16bitHex(cmdymax)} ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}")
log.info "${intTo8bitUnsignedHex(cmdareaid)} ${intTo16bitHex(cmdxmin)} ${intTo16bitHex(cmdxmax)} ${intTo16bitHex(cmdymin)} ${intTo16bitHex(cmdymax)} ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}"
return cmds
}
def mmWaveSetZAXIS(zmin,zmax)
{
def cmds =[]
Integer cmdzmin = zmin.toInteger()
Integer cmdzmax= zmax.toInteger()
intTo32bitUnsignedHex
cmds += zigbee.command(0xfc32,0x01,["mfgCode":"0x122F"],shortDelay," ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}")
log.info " ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}"
return cmds
}
def mmWaveSetHoldtime(holdtime)
{
def cmds =[]
Integer cmdholdtime = holdtime.toInteger()
cmds += zigbee.command(0xfc32,0x03,["mfgCode":"0x122F"],shortDelay," ${intTo32bitUnsignedHex(cmdholdtime)}")
log.info "mmWaveSetHoldtime ${intTo32bitUnsignedHex(cmdholdtime)}"
return cmds
}
def mmWaveSetDetectionArea(areaid, xmin, xmax,ymin,ymax,zmin,zmax)
{
def cmds =[]
Integer cmdareaid = areaid.toInteger()
Integer cmdxmin = xmin.toInteger()
Integer cmdxmax = xmax.toInteger()
Integer cmdymin = ymin.toInteger()
Integer cmdymax= ymax.toInteger()
Integer cmdzmin = zmin.toInteger()
Integer cmdzmax= zmax.toInteger()
cmds += zigbee.command(0xfc32,0x02,["mfgCode":"0x122F"],shortDelay,"${intTo8bitUnsignedHex(cmdareaid)} ${intTo16bitHex(cmdxmin)} ${intTo16bitHex(cmdxmax)} ${intTo16bitHex(cmdymin)} ${intTo16bitHex(cmdymax)} ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}")
log.info "${intTo8bitUnsignedHex(cmdareaid)} ${intTo16bitHex(cmdxmin)} ${intTo16bitHex(cmdxmax)} ${intTo16bitHex(cmdymin)} ${intTo16bitHex(cmdymax)} ${intTo16bitHex(cmdzmin)} ${intTo16bitHex(cmdzmax)}"
return cmds
}
//def lastUpdateFwRemove() {if (state?.lastUpdateFw) state.remove("lastUpdateFw")}
void AnyoneInTheReportingAreaCommandEvent(data)
{
log.info "${device.displayName} ReportingArea:${data}"
// data[0..3] = area1..area4
Integer a1 = Integer.parseInt(data[0], 16)
Integer a2 = Integer.parseInt(data[1], 16)
Integer a3 = Integer.parseInt(data[2], 16)
Integer a4 = Integer.parseInt(data[3], 16)
boolean anyone = (a1 == 1 || a2 == 1 || a3 == 1 || a4 == 1)
// If nobody is present, clear target info immediately
if (!anyone) {
sendEvent(name: "targetCount", value: 0, isStateChange: true)
def payload = [
ts : now(),
count : 0,
targets: []
]
sendEvent(name: "targetInfo", value: JsonOutput.toJson(payload), isStateChange: true)
}
}
void ZigbeePrivateMMWaveAttrEvent(descMap)
{
def attrId= descMap.attrId
def attrInt= descMap.attrInt
def clusterId= descMap.clusterId!=null?descMap.clusterId:descMap.cluster
def clusterInt= descMap.clusterInt
def clusterName=clusterLookup(clusterInt)
valueInt = Integer.parseInt(descMap['value'],16)
def valueHex = intTo32bitUnsignedHex(valueInt)
def infoDev = "${device.displayName} "
def infoTxt = "P${attrInt}=${valueInt}"
def infoMsg = infoDev + infoTxt
switch (attrInt) {
case 115:
infoMsg += " mmWave Firmware Version: "
sendEvent(name:"mmWaveFirmware", value:valueInt)
break
default:
infoMsg += " [0x${valueInt<=0xFF?valueHex.substring(6):valueInt<=0xFFFF?valueHex.substring(4):valueHex}] " + orangeRed(bold("Undefined Parameter $attrInt"))
break
}
if (infoEnable) log.info infoMsg + ((traceEnable||debugEnable)?" [Cluster: 0xfc32, Param:$attrInt Value:$valueInt Default:${getDefaultValue(attrInt)}]":"")
}
void ReportTargetInfoCommandEvent(data)
{
//log.info "${device.displayName} ReportTargetInfo:${data}"
Integer targetnum = Integer.parseInt(data[0],8)
//log.info "${device.displayName} targetnum:${targetnum}"
sendEvent(name: "targetCount", value: targetnum, isStateChange: true)
def targets = []
if(targetnum > 0)
{
Integer index = 1
for(int i = 0;i < targetnum;i++)
{
int x = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int y = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int z = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int dop = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int id = Integer.parseUnsignedInt(data[index],16)
index++
x = (short) x
y = (short) y
z = (short) z
dop = (short) dop
// [zone-fork] Demoted from log.info to log.debug — this fires
// up to ~once/second per target while motion is present.
if (debugEnable) log.debug "${device.displayName} i:${i} x:$x y:$y z:$z dop:$dop id:${id}"
targets << [i: i, id: id, x: x, y: y, z: z, dop: dop]
}
}
// publish ALL targets at once as JSON
def payload = [ts: now(), count: targetnum, targets: targets]
sendEvent(name: "targetInfo", value: JsonOutput.toJson(payload), isStateChange: true)
// [zone-fork] Software per-zone occupancy detection.
//
// Iterate user-defined zones. Each zone is a rectangle in the device's
// mmWave coordinate space (mm; +x is right, +y is forward, origin is
// the switch). For every zone, emit an event of "active" / "inactive"
// on its named attribute (area0..area3) reflecting whether ANY target
// currently falls inside that rectangle.
//
// Zones are configured per-device via the `zoneConfigJson` preference,
// a JSON list of up to 4 zones. Example for one device:
//
// [
// {"name":"area0","xMin":-600,"xMax":600,"yMin":0, "yMax":130},
// {"name":"area1","xMin":-600,"xMax":170,"yMin":130,"yMax":270},
// {"name":"area2","xMin":170, "xMax":600,"yMin":130,"yMax":310},
// {"name":"area3","xMin":-600,"xMax":600,"yMin":310,"yMax":600}
// ]
//
// Leave the preference blank to disable zone detection on a device.
if (settings.zoneConfigJson) {
def zones
try {
zones = new groovy.json.JsonSlurper().parseText(settings.zoneConfigJson)
} catch (e) {
log.warn "${device.displayName} zone-fork: bad zoneConfigJson: ${e.message}"
zones = null
}
if (zones instanceof List) {
zones.each { zone ->
boolean occupied = targets.any { t ->
t.x >= zone.xMin && t.x <= zone.xMax &&
t.y >= zone.yMin && t.y <= zone.yMax
}
String newVal = occupied ? "active" : "inactive"
if (device.currentValue(zone.name) != newVal) {
sendEvent(name: zone.name, value: newVal)
}
}
}
}
}
void ReportInterferenceAreaCommandEvent(data)
{
log.info "${device.displayName} InterferenceArea:${data}"
Integer index = 1
for(int i = 0;i < 4;i++)
{
int xmin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int xmax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int ymin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int ymax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int zmin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int zmax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
xmin = (short) xmin
xmax = (short) xmax
ymin = (short) ymin
ymax = (short) ymax
zmin = (short) zmin
zmax = (short) zmax
log.info "${device.displayName} Interference Area i:${i} xmin:$xmin xmax:$xmax ymin:$ymin ymax:$ymax zmin:$zmin zmax:$zmax"
}
}
void ReportDetectionAreaCommandEvent(data)
{
log.info "${device.displayName} DetectionArea:${data}"
Integer index = 1
for(int i = 0;i < 4;i++)
{
int xmin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int xmax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int ymin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int ymax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int zmin = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
int zmax = ((Integer.parseInt(data[index+1],16) & 0xFF) << 8) | (Integer.parseInt(data[index],16) & 0xFF)
index+=2
xmin = (short) xmin
xmax = (short) xmax
ymin = (short) ymin
ymax = (short) ymax
zmin = (short) zmin
zmax = (short) zmax
log.info "${device.displayName} Detection Area i:${i} xmin:$xmin xmax:$xmax ymin:$ymin ymax:$ymax zmin:$zmin zmax:$zmax"
}
}
void ReportDetectionSensitivityCommandEvent(data)
{
log.info "${device.displayName} ReportDetectionSensitivity:${data}"
Integer Sensitivity = Integer.parseInt(data[0],8)
log.info "${device.displayName} Sensitivity:${Sensitivity}"
}
void ReportTriggerSpeedCommandEvent(data)
{
log.info "${device.displayName} ReportTriggerSpeed:${data}"
Integer TriggerSpeed = Integer.parseInt(data[0],8)
log.info "${device.displayName} TriggerSpeed:${TriggerSpeed}"
}
def infoLogsOff() {
log.warn "${device.displayName} " + fireBrick("Disabling Info logging after timeout")
device.updateSetting("infoEnable",[value:"false",type:"bool"])
//device.updateSetting("disableInfoLogging",[value:"",type:"number"])
}
def traceLogsOff() {
log.warn "${device.displayName} " + fireBrick("Disabling Trace logging after timeout")
device.updateSetting("traceEnable",[value:"false",type:"bool"])
//device.updateSetting("disableTraceLogging",[value:"",type:"number"])
}
def debugLogsOff() {
log.warn "${device.displayName} " + fireBrick("Disabling Debug logging after timeout")
device.updateSetting("debugEnable",[value:"false",type:"bool"])
//device.updateSetting("disableDebugLogging",[value:"",type:"number"])
}
def bind(cmds=[]) {
if (infoEnable) log.info "${device.displayName} bind(${cmds})"
state.lastCommandSent = "bind(${cmds})"
state.lastCommandTime = nowFormatted()
return cmds
}
def bindGroup(action="", group=0) {
if (infoEnable) log.info "${device.displayName} bindGroup($action, $group))"
state.lastCommandSent = "bindGroup($action, $group))"
state.lastCommandTime = nowFormatted()
if (group.toString().split('\\.').length > 1) {
endpoint = group.toString().split('\\.')[0]
group = group.toString().split('\\.')[1]
} else {
group = group
endpoint = 2
}
def cmds = []
if (action=="bind" || action=="unbind") {
cmds += ["zdo $action 0x${device.deviceNetworkId} 0x0${endpoint} 0x01 0x0006 {${device.zigbeeId}} {${zigbee.convertToHexString(group.toInteger(),4)}}"]
cmds += ["zdo $action 0x${device.deviceNetworkId} 0x0${endpoint} 0x01 0x0008 {${device.zigbeeId}} {${zigbee.convertToHexString(group.toInteger(),4)}}"]
cmds += "delay 60000" //binding can take up to 60 seconds
} else {
if (infoEnable) log.warn "${device.displayName} " + fireBrick("Invalid Bind action: '$action'")
}
if (debugEnable) log.debug "${device.displayName} bindGroup $cmds"
sendHubCommand(new HubMultiAction(cmds, Protocol.ZIGBEE))
}
def bindInitiator() {
if (infoEnable) log.info "${device.displayName} bindInitiator()"
state.lastCommandSent = "bindInitiator()"
state.lastCommandTime = nowFormatted()
def cmds = zigbee.command(0xfc31,0x04,["mfgCode":"0x122F"],shortDelay,"0")
if (debugEnable) log.debug "${device.displayName} bindInitiator $cmds"
return cmds
}
def bindTarget(Integer timeout=30) {
if (infoEnable) log.info "${device.displayName} bindTarget($timeout)"
state.lastCommandSent = "bindTarget($timeout)"
state.lastCommandTime = nowFormatted()
setZigbeeAttribute(3,0,timeout,16)
}
def calculateParameter(Integer paramNum) {
paramNum = (paramNum?:0).toInteger()
//def value = Math.round((settings?."parameter${paramNum}"!=null?settings?."parameter${paramNum}":getDefaultValue(paramNum))?.toFloat())?.toInteger()
def value = settings."parameter${paramNum}"!=null?settings."parameter${paramNum}":getDefaultValue(paramNum)
switch (paramNum){
case 9: //Min Level
case 10: //Max Level
case 13: //Default Level (local)
case 14: //Default Level (remote)
case 15: //Level after power restored
case 24: //QuickStart Level
case 55: //Double-Tap UP Level
case 56: //Double-Tap DOWN Level
value = convertPercentToByte(value.toInteger()) //convert levels from percent to byte values before sending to the device
break
case 18: //Active Power Reports (percent change)
case 97: //LED Bar Intensity(when On)
case 98: //LED Bar Intensity(when Off)
value = Math.min(Math.max(value.toInteger(),0),100)
break
case 95: //custom hue for LED Bar (when On)
case 96: //custom hue for LED Bar (when Off)
//360-hue values need to be converted to byte values before sending to the device
if (settings."parameter${paramNum}custom" =~ /^([0-9]{1}|[0-9]{2}|[0-9]{3})$/) {
value = Math.round((settings."parameter${paramNum}custom").toInteger()/360*255)
} else { //else custom hue is invalid format or not selected
if(settings."parameter${paramNum}custom"!=null) {
device.removeSetting("parameter${paramNum}custom")
if (infoEnable||traceEnable||debugEnable) log.warn "${device.displayName} " + fireBrick("Cleared invalid custom hue: ${settings."parameter${paramNum}custom"}")
}
}
break
}
return value?:0
}
def calculateSize(size) {
if (traceEnable) log.trace "${device.displayName} calculateSize(${size})"
//if (size==null || size==" ") size = configParams["parameter${number.toString().padLeft(3,'0')}"]?.size?:8
if (size.toInteger() == 1) return 0x10 //1-bit boolean
else if (size.toInteger() == 8) return 0x20 //1-byte unsigned integer
else if (size.toInteger() == 16) return 0x21 //2-byte unsigned integer
else if (size.toInteger() == 17) return 0x29 //2-byte signed integer
else if (size.toInteger() == 24) return 0x22 //3-byte unsigned integer
else if (size.toInteger() == 32) return 0x23 //4-byte unsigned integer
else if (size.toInteger() == 40) return 0x24 //5-byte unsigned integer
else if (size.toInteger() == 48) return 0x25 //6-byte unsigned integer
else if (size.toInteger() == 56) return 0x26 //7-byte unsigned integer
else if (size.toInteger() == 64) return 0x27 //8-byte unsigned integer
else {
log.warn "${device.displayName} Invalid size '$size'"
return 0x20 //default to 1-byte unsigned if no other matches
}
}
def clearSetting(i) {
i = i?:0
def cleared = false
if (settings."parameter${i}"!=null) {cleared=true; device.removeSetting("parameter" + i)}
if (state."parameter${i}value"!=null) {cleared=true; state.remove("parameter" + i + "value")}
if (cleared && (infoEnable||traceEnable||debugEnable)) log.info "${device.displayName} " + blueViolet("cleared P${i} since it is the default")
}
def clusterLookup(cluster) {
if (cluster==null) return "null ClusterID"
else {
//return zigbee.clusterLookup(cluster)
return zigbee.clusterLookup(cluster)?:cluster==0x8021?"Binding Cluster":
cluster==0x8022?"UNBinding Cluster":
cluster==0x8032?"Routing Table Cluster":
cluster==0xFC31?"Private Cluster":
cluster==0xFC32?"MMWave Private Cluster":
"Cluster:0x${zigbee.convertToHexString(cluster,4)}"
}
}
def configure(option) { //THIS GETS CALLED AUTOMATICALLY WHEN NEW DEVICE IS ADDED OR WHEN CONFIGURE BUTTON SELECTED ON DEVICE PAGE
option = (option==null||option==" ")?"":option
if (infoEnable) log.info "${device.displayName} configure($option)"
state.lastCommandSent = "configure($option)"
state.lastCommandTime = nowFormatted()
sendEvent(name: "numberOfButtons", value: settings.parmeter23?28:14)
def cmds = []
if (infoEnable) log.info "${device.displayName} re-establish lifeline bindings to hub"
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0000 {${device.zigbeeId}} {}"] //Basic Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0003 {${device.zigbeeId}} {}"] //Identify Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0004 {${device.zigbeeId}} {}"] //Group Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0005 {${device.zigbeeId}} {}"] //Scenes Cluster
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0006 {${device.zigbeeId}} {}"] //On_Off Cluster
cmds += zigbee.configureReporting(0x0006, 0x0000, 0x10, 1, 65534, 0) // 0x10 = Boolean Type
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0008 {${device.zigbeeId}} {}"] //Level Control Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0019 {${device.zigbeeId}} {}"] //OTA Upgrade Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0202 {${device.zigbeeId}} {}"] //Fan Control Cluster
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0702 {${device.zigbeeId}} {}"] //Simple Metering - to get energy reports
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0B04 {${device.zigbeeId}} {}"] //Electrical Measurement - to get power reports
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0406 {${device.zigbeeId}} {}"] //Occupancy Cluster
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0400 {${device.zigbeeId}} {}"] //Illuminance Cluster
//For a 50 minReportChange: Math.floor(10000 * Math.log10(50) + 1) = 16990
cmds += zigbee.configureReporting(0x0400, 0x0000, 0x21, 30, 3600, 16990) // 0x21 = 16 Bit Unsigned Type zigbee.configureReporting(0x0400, 0x0000, 0x21, minReportTime, maxReportTime, reportableChange)
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x0B05 {${device.zigbeeId}} {}"] //Diagnostics Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x8021 {${device.zigbeeId}} {}"] //Binding Cluster
// cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0x8022 {${device.zigbeeId}} {}"] //UnBinding Cluster
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0xFC31 {${device.zigbeeId}} {}"] //Private Cluster
cmds += ["zdo bind ${device.deviceNetworkId} 0x02 0x01 0xFC31 {${device.zigbeeId}} {}"] //Private Cluster ep2
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0xFC32 {${device.zigbeeId}} {}"] //MMWave Private Cluster for Reports etc.
cmds += ["zdo bind ${device.deviceNetworkId} 0x01 0x01 0xFC57 {${device.zigbeeId}} {}"] //???? ???? (listed in fingerprint)
if (debugEnable) log.debug "${device.displayName} configure $cmds"
sendHubCommand(new HubMultiAction(delayBetween(cmds, shortDelay), Protocol.ZIGBEE))
if (option=="") { //IF we didn't pick an option
refresh() //THEN refresh read-only and key parameters
} else { //ELSE read device attributes and pass on to update settings.
if (option=="Default") settings.each {settings.remove(it)} //if DEFAULT was requested then clear any user settings
readDeviceAttributes()
updated(option)
}
}
def convertByteToPercent(int value=0) { //convert a 0-254 range where 254=100%. 255 is reserved for special meaning.
//if (debugEnable) log.debug "${device.displayName} convertByteToPercent(${value})"
value = value==null?0:value //default to 0 if null
value = Math.min(Math.max(value.toInteger(),0),255) //make sure input byte value is in the 0-255 range
value = value>=255?256:value //this ensures that byte values of 255 get rounded up to 101%
value = Math.ceil(value/255*100) //convert to 0-100 where 254=100% and 255 becomes 101 for special meaning
return value
}
def convertPercentToByte(int value=0) { //convert a 0-100 range where 100%=254. 255 is reserved for special meaning.
//if (debugEnable) log.debug "${device.displayName} convertPercentToByte(${value})"
value = value==null?0:value //default to 0 if null
value = Math.min(Math.max(value.toInteger(),0),101) //make sure input percent value is in the 0-101 range
value = Math.floor(value/100*255) //convert to 0-255 where 100%=254 and 101 becomes 255 for special meaning
value = value==255?254:value //this ensures that 100% rounds down to byte value 254
value = value>255?255:value //this ensures that 101% rounds down to byte value 255
return value
}
def cycleSpeed() { // FOR FAN ONLY
def cmds =[]
if (parameter158=="1" || parameter258=="1") {
toggle() //if we are in on/off mode then do a toggle instead of cycle
return
} else {
def currentLevel = device.currentValue("level")==null?0:device.currentValue("level").toInteger()
if (device.currentValue("switch")=="off") currentLevel = 0
boolean smartMode = device.currentValue("smartFan")=="Enabled"
def newLevel = 0
def newSpeed =""
if (currentLevel<=0 ) {newLevel=20; newSpeed="low" }
else if (currentLevel<=20) {newLevel=(smartMode?40:60); newSpeed=(smartMode?"medium-low":"medium")}
else if (currentLevel<=40) {newLevel=60; newSpeed="medium"}
else if (currentLevel<=60) {newLevel=(smartMode?80:100); newSpeed=(smartMode?"medium-high":"high")}
else if (currentLevel<=80) {newLevel=100; newSpeed="high"}
else {newLevel=0; newSpeed="off"}
if (infoEnable) log.info "${device.displayName} cycleSpeed(${device.currentValue("speed")?:off}->${newSpeed})"
state.lastCommandSent = "cycleSpeed(${device.currentValue("speed")?:off}->${newSpeed})"
state.lastCommandTime = nowFormatted()
cmds += zigbee.setLevel(newLevel)
if (debugEnable) log.debug "${device.displayName} cycleSpeed $cmds"
sendHubCommand(new HubMultiAction(delayBetween(cmds, shortDelay), Protocol.ZIGBEE))
}
}
def getDefaultValue(paramNum=0) {
paramValue=configParams["parameter${paramNum.toString()?.padLeft(3,"0")}"]?.default?.toInteger()
return paramValue?:0
}
def getRssiLQI(){
if (infoEnable) log.info "${device.displayName} getRssiLQI()"
state.lastCommandSent = "getRssiLQI()"
state.lastCommandTime = nowFormatted()
def cmds = []
cmds += zigbee.readAttribute(0x0b05, 0x011c, [destEndpoint: 0x01])
cmds += zigbee.readAttribute(0x0b05, 0x011d, [destEndpoint: 0x01])
return cmds
}
def getTemperature() {
if (infoEnable) log.info "${device.displayName} getTemperature()"
state.lastCommandSent = "getTemperature()"
state.lastCommandTime = nowFormatted()
def cmds = []
cmds += zigbee.readAttribute(0xfc31, 0x0020, ["mfgCode": "0x122f"])
cmds += zigbee.readAttribute(0xfc31, 0x0021, ["mfgCode": "0x122f"])
return cmds
}
def identify(seconds) {
if (infoEnable) log.info "${device.displayName} identify(${seconds==null?"":seconds})"
state.lastCommandSent = "identify(${seconds==null?"":seconds})"
state.lastCommandTime = nowFormatted()
setZigbeeAttribute(3,0,seconds,16)
}
def initialize() { //CALLED DURING HUB BOOTUP IF "INITIALIZE" CAPABILITY IS DECLARED IN METADATA SECTION
if (infoEnable||infoEnable==null) log.info "${device.displayName} initialize()"
//save the group IDs before clearing all the state variables and reset them after
if (state.groupBinding1) saveBinding1 = state.groupBinding1
if (state.groupBinding2) saveBinding2 = state.groupBinding2
if (state.groupBinding3) saveBinding3 = state.groupBinding3
state.clear()
if (saveBinding1) state.groupBinding1 = saveBinding1
if (saveBinding2) state.groupBinding2 = saveBinding2
if (saveBinding3) state.groupBinding3 = saveBinding3
state.lastCommandSent = "initialize()"
state.lastCommandTime = nowFormatted()
state.driverDate = getDriverDate()
state.model = device.getDataValue('model')
device.removeSetting("parameter95custom")
device.removeSetting("parameter96custom")
ledEffectOne(1234567,255,0,0,0) //clear any outstanding oneLED Effects
ledEffectAll(255,0,0,0) //clear any outstanding allLED Effects
refresh()
}
def installed() { //THIS IS CALLED WHEN A DEVICE IS INSTALLED
log.info "${device.displayName} installed()"
state.lastCommandSent = "installed()"
state.lastCommandTime = nowFormatted()
state.driverDate = getDriverDate()
state.model = device.getDataValue('model')
log.info "${device.displayName} Driver Date $state.driverDate"
log.info "${device.displayName} Model=$state.model"
//configure() //I confirmed configure() gets called at Install time so this isn't needed here
return
}
def intTo8bitUnsignedHex(value) {
return zigbee.convertToHexString(value.toInteger(),2)
}
def intTo16bitUnsignedHex(value) {
return zigbee.convertToHexString(value.toInteger(),4)
}
def intTo32bitUnsignedHex(value) {
return zigbee.convertToHexString(value.toInteger(),8)
}
def ledEffectAll(effect=255, color=0, level=100, duration=60) {
effect = effect.toString().split(/=/)[0]
def effectName = "unknown($effect)"
switch (effect){
case "255": effectName = "Stop"; break
case "1": effectName = "Solid"; break
case "2": effectName = "Fast Blink"; break
case "3": effectName = "Slow Blink"; break
case "4": effectName = "Pulse"; break
case "5": effectName = "Chase"; break
case "6": effectName = "Open/Close"; break
case "7": effectName = "Small-to-Big"; break
case "8": effectName = "Aurora"; break
case "9": effectName = "Slow Falling"; break
case "10": effectName = "Medium Falling"; break
case "11": effectName = "Fast Falling"; break
case "12": effectName = "Slow Rising"; break
case "13": effectName = "Medium Rising"; break
case "14": effectName = "Fast Rising"; break
case "15": effectName = "Medium Blink"; break
case "16": effectName = "Slow Chase"; break
case "17": effectName = "Fast Chase"; break
case "18": effectName = "Fast Siren"; break
case "19": effectName = "Slow Siren"; break
case "0": effectName = "LEDs Off"; break
default: effectName = "Unknown Effect #$effect"; break
}
sendEvent(name:"ledEffect", value: "$effectName All")
if (infoEnable) log.info "${device.displayName} ledEffectAll(${effect},${color},${level},${duration})"
state.lastCommandSent = "ledEffectAll(${effect},${color},${level},${duration})"
state.lastCommandTime = nowFormatted()
effect = Math.min(Math.max((effect!=null?effect:255).toInteger(),0),255)
color = Math.min(Math.max((color!=null?color:0).toInteger(),0),255)
level = Math.min(Math.max((level!=null?level:100).toInteger(),0),100)
duration = Math.min(Math.max((duration!=null?duration:60).toInteger(),0),255)
def cmds =[]
Integer cmdEffect = effect.toInteger()
Integer cmdColor = color.toInteger()
Integer cmdLevel = level.toInteger()
Integer cmdDuration = duration.toInteger()
cmds += zigbee.command(0xfc31,0x01,["mfgCode":"0x122F"],shortDelay,"${intTo8bitUnsignedHex(cmdEffect)} ${intTo8bitUnsignedHex(cmdColor)} ${intTo8bitUnsignedHex(cmdLevel)} ${intTo8bitUnsignedHex(cmdDuration)}")
if (debugEnable) log.debug "${device.displayName} ledEffectAll $cmds"
return cmds
}
def ledEffectOne(lednum, effect=255, color=0, level=100, duration=60) {
lednum = lednum.toString().split(/ /)[0].replace(",","")
effect = effect.toString().split(/=/)[0]
def effectName = "unknown($effect)"
switch (effect){
case "255": effectName = "Stop"; break
case "1": effectName = "Solid"; break
case "2": effectName = "Fast Blink"; break
case "3": effectName = "Slow Blink"; break
case "4": effectName = "Pulse"; break
case "5": effectName = "Chase"; break
case "6": effectName = "Falling"; break
case "7": effectName = "Rising"; break
case "8": effectName = "Aurora"; break
case "0": effectName = "LEDs Off"; break
default: effectName = "Unknown Effect #$effect"; break
}
sendEvent(name:"ledEffect", value: "$effectName LED${lednum.toString().split(/ /)[0]}")
if (infoEnable) log.info "${device.displayName} ledEffectOne(${lednum},${effect},${color},${level},${duration})"
state.lastCommandSent = "ledEffectOne(${lednum},${effect},${color},${level},${duration})"
state.lastCommandTime = nowFormatted()
effect = Math.min(Math.max((effect!=null?effect:255).toInteger(),0),255)
color = Math.min(Math.max((color!=null?color:0).toInteger(),0),255)
level = Math.min(Math.max((level!=null?level:100).toInteger(),0),100)
duration = Math.min(Math.max((duration!=null?duration:60).toInteger(),0),255)
def cmds = []
lednum.toString().each {
it= Math.min(Math.max((it!=null?it:1).toInteger(),1),7)
Integer cmdLedNum = (it.toInteger()-1) //lednum is 0-based in firmware
Integer cmdEffect = effect.toInteger()
Integer cmdColor = color.toInteger()
Integer cmdLevel = level.toInteger()
Integer cmdDuration = duration.toInteger()
cmds += zigbee.command(0xfc31,0x03,["mfgCode":"0x122F"],100,"${intTo8bitUnsignedHex(cmdLedNum)} ${intTo8bitUnsignedHex(cmdEffect)} ${intTo8bitUnsignedHex(cmdColor)} ${intTo8bitUnsignedHex(cmdLevel)} ${intTo8bitUnsignedHex(cmdDuration)}")
}
if (debugEnable) log.debug "${device.displayName} ledEffectOne $cmds"
return cmds
}
def nowFormatted() {
if(location.timeZone) return new Date().format("yyyy-MMM-dd h:mm:ss a", location.timeZone)
else return new Date().format("yyyy MMM dd EEE h:mm:ss a")
}
def off() {
if (infoEnable) log.info "${device.displayName} off()"
state.lastCommandSent = "off()"
state.lastCommandTime = nowFormatted()
def cmds = []
cmds += zigbee.off(shortDelay)
if (debugEnable) log.debug "${device.displayName} off $cmds"