-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathOsram_gSpot_DTH
855 lines (756 loc) · 35 KB
/
Osram_gSpot_DTH
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
/**
* Osram LIGHTIFY GardenSpot Mini rgb - AAP Version
*
* - For use with directly connecting the US (Z HA) versions to SmartThings
*
* - Without the Osram Gateway, the color loop functionality does not work for the US version of the GardenSpots (at
* least until they update the firmware). But using the "hueLoop" and "hueRandom" attributes
* of this DTH, one create a CoRE Piston to cause color loop (even random colors)
*
* - Device Tile contains sliders for individual control of hue, saturation, and transition time.
*
* - Device Tile also contains buttons for (1) "hueLoop" (boolean "on" / "off" values) and
* (2) "Random Hue" (causes hue to change to a random color). Use these in CoRE to create color loop.
*
* Copyright 2016 SmartThings
*
* 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.
*
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "Osram GardenSpot Mini rgb - aap version", namespace: "info_fiend", author: "anthony pastor") {
capability "Switch Level"
capability "Actuator"
capability "Color Control"
capability "Color Temperature"
capability "Switch"
capability "Configuration"
capability "Polling"
capability "Refresh"
capability "Sensor"
command "setAdjustedColor"
command "startLoop"
command "stopLoop"
command "setLoopTime"
command "setDirection"
command "setHueLoop"
command "setRandomHue"
command "setTransitionTime"
command "alert"
command "toggle"
// This is a new temporary counter to keep track of no responses
attribute "unreachable", "number"
attribute "colorMode", "string"
attribute "colorName", "string"
attribute "switchColor", "string"
attribute "loopActive", "string"
attribute "loopDirection", "string"
attribute "loopTime", "number"
attribute "alert", "string"
attribute "level", "number"
attribute "hue", "number"
attribute "hueLoop", "string"
attribute "saturation", "number"
attribute "hueRandom", "number"
attribute "transitionTime", "number"
attribute "sliderTT", "number"
fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "Gardenspot RGB"
fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "LIGHTIFY Gardenspot RGB"
}
// simulator metadata
simulator {
// status messages
status "on": "on/off: 1"
status "off": "on/off: 0"
// reply messages
reply "zcl on-off on": "on/off: 1"
reply "zcl on-off off": "on/off: 0"
}
// UI tile definitions
tiles (scale: 2){
multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
tileAttribute("device.switchColor", key: "PRIMARY_CONTROL") {
attributeState "off", label: '${currentValue}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
attributeState "Red", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff0000"
attributeState "Brick Red", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff3700"
attributeState "Safety Orange", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff6F00"
attributeState "Dark Orange", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff9900"
attributeState "Amber", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ffbf00"
attributeState "Gold", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ffe1000"
attributeState "Yellow", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ffff00"
attributeState "Electric Lime", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#bfff00"
attributeState "Lawn Green", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#88ff00"
attributeState "Bright Green", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#48ff00"
attributeState "Lime", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00ff11"
attributeState "Spring Green", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00ff6a"
attributeState "Turquoise", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00ffd0"
attributeState "Aqua", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00ffff"
attributeState "Sky Blue", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00bfff"
attributeState "Dodger Blue", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#007bff"
attributeState "Navy Blue", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#0050ff"
attributeState "Blue", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#0000ff"
attributeState "Han Purple", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#3b00ff"
attributeState "Electric Indigo", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#6600ff"
attributeState "Electric Purple", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#b200ff"
attributeState "Orchid Purple", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#e900ff"
attributeState "Magenta", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff00dc"
attributeState "Hot Pink", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff00aa"
attributeState "Deep Pink", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff007b"
attributeState "Raspberry", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff0061"
attributeState "Crimson", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#ff003b"
attributeState "White", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
attributeState "Color Loop", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
}
tileAttribute ("device.color", key: "COLOR_CONTROL") {
attributeState "color", action: "setAdjustedColor"
}
tileAttribute ("device.colorName", key: "SECONDARY_CONTROL") {
attributeState "colorName", label: 'Color is ${currentValue}'
}
}
standardTile("refresh", "device.switch", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 4, inactiveLabel: false) {
state "level", action:"switch level.setLevel"
}
valueTile("level", "device.level", height: 1, width: 2, inactiveLabel: false, decoration: "flat") {
state "level", label: 'Level: ${currentValue}'
}
controlTile("hueSliderControl", "device.hue", "slider", height: 1, width: 4, inactiveLabel: false) {
state "hue", action:"setHue"
}
valueTile("hue", "device.hue", height: 1, width: 2, inactiveLabel: false, decoration: "flat") {
state "hue", label: 'Hue: ${currentValue}'
}
standardTile("hueLoop", "device.hueLoop", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "on", label: 'Hue Loop On', action: "setHueLoop", backgroundColor: "#ab1552", nextState: "off"
// state "startingHueLoop", label: "Starting", action: "setHueLoop", backgroundColor: "#79b821", nextState: "stoppingHueLoop"
state "off", label:'Hue Loop Off', action: "setHueLoop", backgroundColor: "#ffffff", nextState: "on"
// state "stoppingHueLoop", label: "Stopping", action: "setHueLoop", backgroundColor: "#ffffff", nextState: "startingHueLoop"
}
standardTile("hueRandom", "device.hueRandom", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "hueRandom", label: 'Random Hue', action: "setRandomHue"
}
controlTile("satSliderControl", "device.saturation", "slider", height: 1, width: 4, inactiveLabel: false) {
state "saturation", action:"setSaturation"
}
valueTile("saturation", "device.saturation", height: 1, width: 2, inactiveLabel: false, decoration: "flat") {
state "saturation", label: 'Sat: ${currentValue}'
}
controlTile("colorTempSliderControl", "device.colorTemperature", "slider", height: 1, width: 4, inactiveLabel: false, range:"(2000..6500)") {
state "colorTemperature", action:"color temperature.setColorTemperature"
}
valueTile("colorTemp", "device.colorTemperature", height: 1, width: 2, inactiveLabel: false, decoration: "flat") {
state "colorTemperature", label: '${currentValue} K'
}
controlTile("transTimeSliderControl", "device.sliderTT", "slider", height: 1, width: 3, inactiveLabel: false, range: "1..100") {
state "sliderTT", action:"setTransitionTime"
}
valueTile("transitionTime", "device.transitionTime", height: 1, width: 3, inactiveLabel: false, decoration: "flat") {
state "transitionTime", label: 'Transitions: ${currentValue} secs'
}
valueTile("colorName", "device.colorName", height: 1, width: 2, inactiveLabel: false, decoration: "flat") {
state "colorName", label: '${currentValue}'
}
valueTile("colorMode", "device.colorMode", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "colorMode", label: '${currentValue}'
}
standardTile("loop", "device.loopActive", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "Active", label:'${currentValue}', action: "stopLoop", backgroundColor: "#79b821", nextState: "stoppingLoop"
state "startingLoop", label: "Starting Loop", action: "stopLoop", backgroundColor: "#79b821", nextState: "stoppingLoop"
state "Inactive", label:'${currentValue}', action: "startLoop", backgroundColor: "#ffffff", nextState: "startingLoop"
state "stoppingLoop", label: "Stopping Loop", action: "startLoop", backgroundColor: "#ffffff", nextState: "startingLoop"
}
controlTile("loopTimeControl", "device.loopTime", "slider", height: 2, width: 4, range: "(1..60)", inactiveLabel: false) {
state "loopTime", action: "setLoopTime"
}
standardTile("loopDir", "device.loopDirection", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "default", label: '${currentValue}', action: "setDirection"
}
standardTile("alert", "device.alertStatus", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "Blink", label:'Blink', action: "alertBreathe",nextState: "Breathe"
state "Breathe", label:'Breathe', action: "alertOkay", nextState: "Okay"
state "Okay", label:'Okay', action: "alertStop", nextState: "Stop"
state "Stop", label:'Stop', action: "alertBlink", nextState: "Blink"
}
main(["switch"])
details(["switch", "levelSliderControl", "level", "hueSliderControl", "hue", "satSliderControl", "saturation", "transTimeSliderControl", "transitionTime", "hueLoop", "hueRandom","refresh"]) //"colorTempSliderControl", "colorTemp", "loop", "loopTimeControl", "loopDir", "colorMode", "alert",
}
}
// Parse incoming device messages to generate events
def parse(String description) {
log.info "description is $description"
// sendEvent(name: "unreachable", value: 0)
if (device.currentValue("loopActive") == "Active") {
}
else {
if (description?.startsWith("catchall:")) {
if(description?.endsWith("0100") ||description?.endsWith("1001") || description?.matches("on/off\\s*:\\s*1"))
{
def result = createEvent(name: "switch", value: "on")
sendEvent(name: "switchColor", value: ( device.currentValue("colorMode") == "White" ? "White" : device.currentValue("colorName")), displayed: false)
log.debug "Parse returned ${result?.descriptionText}"
return result
}
else if(description?.endsWith("0000") || description?.endsWith("1000") || description?.matches("on/off\\s*:\\s*0"))
{
if(!(description?.startsWith("catchall: 0104 0300") || description?.startsWith("catchall: 0104 0008"))){
def result = createEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off", displayed: false)
log.debug "Parse returned ${result?.descriptionText}"
return result
}
}
}
else if (description?.startsWith("read attr -")) {
def descMap = parseDescriptionAsMap(description)
// log.trace "descMap : $descMap"
if (descMap.cluster == "0300") {
if(descMap.attrId == "0000"){ //Hue Attribute
def hueValue = Math.round(convertHexToInt(descMap.value) / 255 * 100)
log.debug "Hue value returned is $hueValue"
def colorName = getColorName(hueValue)
sendEvent(name: "colorName", value: colorName, isStateChange: true)
if (device.currentValue("switch") == "on") { sendEvent(name: "switchColor", value: ( device.currentValue("colorMode") == "White" ? "White" : device.currentValue("colorName")), displayed: false) }
sendEvent(name: "hue", value: hueValue, displayed:false)
}
else if(descMap.attrId == "0001"){ //Saturation Attribute
def saturationValue = Math.round(convertHexToInt(descMap.value) / 255 * 100)
log.debug "Saturation from refresh is $saturationValue"
sendEvent(name: "saturation", value: saturationValue, displayed:false)
}
else if( descMap.attrId == "0007") {
def tempInMired = convertHexToInt(descMap.value)
def tempInKelvin = Math.round(1000000/tempInMired)
log.debug "Color temperature returned is $tempInKelvin"
sendEvent(name: "colorTemperature", value: tempInKelvin, isStateChange: true)
}
else if( descMap.attrId == "0008") {
def colorModeValue = (descMap.value == "02" ? "White" : "Color")
log.debug "Color mode returned $colorModeValue"
sendEvent(name: "colorMode", value: colorModeValue, isStateChange: true)
if (device.currentValue("switch") == "on") {
sendEvent(name: "switchColor", value: (descMap.value == "02" ? "White" : device.currentValue("colorName")), displayed: false, isStateChange: true)
}
}
}
else if(descMap.cluster == "0008"){
def dimmerValue = Math.round(convertHexToInt(descMap.value) * 100 / 255)
log.debug "dimmer value is $dimmerValue"
sendEvent(name: "level", value: dimmerValue, isStateChange: true)
}
}
else {
def name = description?.startsWith("on/off: ") ? "switch" : null
def value = null
if (name == "switch") {
value = (description?.endsWith(" 1") ? "on" : "off")
log.debug value
sendEvent(name: "switchColor", value: (value == "off" ? "off" : device.currentValue("colorName")), displayed: false, isStateChange: true)
}
else { value = null }
def result = createEvent(name: name, value: value)
log.debug "Parse returned ${result?.descriptionText}"
return result
}
}
}
def parseDescriptionAsMap(description) {
(description - "read attr - ").split(",").inject([:]) { map, param ->
def nameAndValue = param.split(":")
map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
}
}
def on(onTime = null) {
// just assume it works for now
log.debug "on()"
if (onTime) {
def newTime = onTime * 10
def finalHex = swapEndianHex(hexF(newTime, 4))
runIn(onTime, refresh)
"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0x42 {00 ${finalHex} 0000}"
}
else {
"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
}
sendEvent(name: "switch", value: "on")
sendEvent(name: "switchColor", value: ( device.currentValue("colorMode") == "White" ? "White" : device.currentValue("colorName")), displayed: false, isStateChange: true)
}
def off() {
// just assume it works for now
log.debug "off()"
// sendEvent(name: "loopActive", value: "Inactive")
sendEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off", displayed: false, isStateChange: true)
"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}"
}
def toggle() {
if (device.currentValue("switch") == "on") {
sendEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off")
}
else {
sendEvent(name: "switch", value: "on")
sendEvent(name: "switchColor", value: ( device.currentValue("colorMode") == "White" ? "White" : device.currentValue("colorName")), displayed: false, isStateChange: true)
}
"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 2 {}"
}
def alert(action) {
def value = "00"
def valid = true
// def curState = device.currentValue("alert")
switch(action) {
case "Blink":
value = "00"
break
case "Breathe":
value = "01"
break
case "Okay":
value = "02"
break
case "Stop":
value = "ff"
break
default:
valid = false
break
}
if (valid) {
log.debug "Alert: ${action}, Value: ${value}"
sendEvent(name: "alert", value: action, displayed: true, isStateChange: true)
"st cmd 0x${device.deviceNetworkId} ${endpointId} 3 0x40 {${value} 00}"
}
else { log.debug "Invalid action" }
}
/**
def setDirection() {
def direction = (device.currentValue("loopDirection") == "Down" ? "Up" : "Down")
log.trace direction
sendEvent(name: "loopDirection", value: direction, isStateChange: true)
if (device.currentValue("loopActive") == "Active") {
def dirHex = (direction == "Down" ? "00" : "01")
log.trace dirHex
"st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x44 {02 01 ${dirHex} 0000 0000}"
}
}
def setLoopTime(value) {
sendEvent(name:"loopTime", value: value, isStateChange: true)
if (device.currentValue("loopActive") == "Active") {
def finTime = swapEndianHex(hexF(value, 4))
"st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x44 {04 01 00 ${finTime} 0000}"
}
}
**/
def setHueLoop() {
if (device.currentValue("hueLoop") == "off") {
log.trace "hueLoop is now ON."
sendEvent(name: "hueLoop", value: "on", inStateChange: true)
} else {
log.trace "hueLoop is now OFF."
sendEvent(name: "hueLoop", value: "off", inStateChange: true)
}
// "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 2 {}"
// sendEvent(name:"hueLoop", value: "On", isStateChange: true)
// log.debug "sethueLoop: device.currentValue('${hueLoop}')"
}
/**
def startLoop(Map params) {
// direction either increments or decrements the hue value: "Up" will increment, "Down" will decrement
def direction = (device.currentValue("loopDirection") != null ? (device.currentValue("loopDirection") == "Down" ? "00" : "01") : "00")
log.trace direction
if (params?.direction != null) {
direction = (params.direction == "Down" ? "00" : "01")
sendEvent(name: "loopDirection", value: params.direction, isStateChange: true )
}
log.trace direction
// time parameter is the time in seconds for a full loop
def cycle = (device.currentValue("loopTime") != null ? device.currentValue("loopTime") : 2)
log.trace cycle
if (params?.time != null) {
cycle = params.time
if (cycle >= 1 && cycle <= 60) {sendEvent(name:"loopTime", value: cycle, isStateChange: true)}
}
log.trace cycle
def finTime = swapEndianHex(hexF(cycle, 4))
log.trace finTime
def cmds = []
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
cmds << "delay 200"
sendEvent(name: "switchColor", value: "Color Loop", displayed: false)
sendEvent(name: "loopActive", value: "Active", isStateChange: true)
if (params?.hue != null) {
// start hue was specified, so convert to enhanced hue and start loop from there
def sHue = Math.min(Math.round(params.hue * 255 / 100), 255)
finHue = swapEndianHex(hexF(sHue, 4))
log.debug "activating color loop from specified hue"
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x44 {0F 01 ${direction} ${finTime} ${sHue}}"
}
else {
// start hue was not specified, so start loop from current hue updating direction and time
log.debug "activating color loop from current hue"
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x44 {07 02 ${direction} ${finTime} 0000}"
}
cmds
}
def stopLoop() {
log.debug "deactivating color loop"
def cmds = [
"st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x44 {01 00 00 0000 0000}", "delay 200",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 0", "delay 200",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 1", "delay 200",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 7","delay 200",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 8", "delay 200",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 8 0"
]
sendEvent(name: "loopActive", value: "Inactive", isStateChange: true)
cmds
}
**/
def setColorTemperature(value) {
if(value<101){
value = (value*38) + 2700 //Calculation of mapping 0-100 to 2700-6500
}
def duration = (this.device.currentValue("transitionTime") * 10) ?: 32
def transitionTime = swapEndianHex(hexF(duration,4))
def tempInMired = Math.round(1000000/value)
def finalHex = swapEndianHex(hexF(tempInMired, 4))
// def genericName = getGenericName(value)
// log.debug "generic name is : $genericName"
def cmds = []
if (device.latestValue("switch") == "off") {
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
cmds << "delay 150"
}
sendEvent(name: "colorTemperature", value: value, displayed:false)
sendEvent(name: "colorMode", value: "White")
sendEvent(name: "switchColor", value: "White", displayed: false, isStateChange: true)
// sendEvent(name: "colorName", value: genericName)
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 0x0300 0x0a {${finalHex} ${transitionTime}}"
cmds
}
def setTransitionTime(inTime) {
def transitionTime = ( inTime / 10 )
log.trace "transitionTime = ${transitionTime} seconds."
sendEvent(name: "sliderTT", value: inTime, displayed:false)
sendEvent(name: "transitionTime", value: transitionTime, displayed:true, inStateChange: true)
}
def setHue(hue) {
log.trace "setHue($hue)"
def sat = this.device.currentValue("saturation") ?: 100
def level = this.device.currentValue("level") ?: 100
setColor([level:level, saturation:sat, hue:hue, switch:"on"])
}
def setRandomHue() {
def rHue = new Random().nextInt(100) + 1
log.trace "Random hue is ${rHue}."
def sat = this.device.currentValue("saturation") ?: 100
def level = this.device.currentValue("level") ?: 100
setColor([level:level, saturation:sat, hue:rHue, switch:"on"])
}
def setSaturation(sat) {
log.trace "setSaturation($sat)"
def hue = this.device.currentValue("hue") ?: 70
def level = this.device.currentValue("level") ?: 100
setColor([level:level, saturation:sat, hue:hue, switch:"on"])
}
def setLevel(value) {
log.trace "setLevel($value)"
def duration = (this.device.currentValue("transitionTime") * 10) ?: 32
state.levelValue = (value==null) ? 100 : value
def transitionTime = swapEndianHex(hexF(duration,4))
def cmds = []
if (value == 0) {
sendEvent(name: "switch", value: "off", isStateChange: true)
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}"
cmds << "delay 150"
} else if (device.latestValue("switch") == "off") {
sendEvent(name: "switch", value: "on", isStateChange: true)
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
cmds << "delay 150"
}
sendEvent(name: "level", value: state.levelValue, isStateChange: true)
def scaledLevel = hex(state.levelValue * 255 / 100)
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${scaledLevel} ${transitionTime}}"
//log.debug cmds
cmds
}
def setAdjustedColor(value) {
// log.debug "setAdjustedColor: ${value}"
def adjusted = value + [:]
adjusted.level = null // needed because color picker always sends 100
setColor(adjusted)
}
def setColor(value){
log.trace "setColor($value)"
def duration = (this.device.currentValue("transitionTime") * 10) ?: 32
log.trace "transition time = ${duration / 10} seconds."
def transitionTime = swapEndianHex(hexF(duration,4))
def max = 0xfe
if (value.hue == 0 && value.saturation == 0) { setColorTemperature(3500) }
else if (value.red == 255 && value.blue == 185 && value.green == 255) { setColorTemperature(2700) }
else {
if (value.hex) { sendEvent(name: "color", value: value.hex, displayed:false)}
def colorName = getColorName(value.hue)
sendEvent(name: "colorName", value: colorName)
sendEvent(name: "colorMode", value: "Color")
sendEvent(name: "switchColor", value: device.currentValue("colorName"), displayed: false, isStateChange: true)
log.debug "color name is : $colorName"
sendEvent(name: "hue", value: value.hue, displayed:true)
sendEvent(name: "saturation", value: value.saturation, displayed:true, isStateChange: true)
def scaledHueValue = evenHex(Math.round(value.hue * max / 100.0))
def scaledSatValue = evenHex(Math.round(value.saturation * max / 100.0))
def cmd = []
if (value.switch != "off" && device.latestValue("switch") == "off") {
cmd << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
cmd << "delay 150"
}
cmd << "st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x06 {${scaledHueValue} ${scaledSatValue} ${transitionTime}}"
if (value.level) {
cmd << "delay 150"
state.levelValue = value.level
sendEvent(name: "level", value: state.levelValue, isStateChange: true)
def scaledLevel = hex(state.levelValue * 255 / 100)
// sendEvent(name: "level", value: value.level, displayed: true, isStateChange: true)
// def level = hex(value.level * 254 / 100)
cmd << "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${scaledLevel} ${transitionTime}}" // "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${level} 1500}"
}
if (value.switch == "off") {
cmd << "delay 150"
cmd << off()
}
cmd
}
}
/**
def setSaturation(Integer value, duration = 32) {
def transitionTime = swapEndianHex(hexF(duration,4))
def max = 0xfe
// log.trace "setSaturation($value)"
sendEvent(name: "saturation", value: value)
def scaledValue = Math.round(value * max / 100.0)
def cmd = "st cmd 0x${device.deviceNetworkId} ${endpointId} 0x300 0x03 {${hex(scaledValue)} ${transitionTime}}"
//log.info cmd
cmd
}
**/
def refresh() {
/**
def unreachable = device.currentValue("unreachable")
if(unreachable == null) {
sendEvent(name: 'unreachable', value: 1)
}
else {
sendEvent(name: 'unreachable', value: unreachable + 1)
}
if(unreachable > 2) {
sendEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off", displayed: false)
}
**/
// Ping the device with color as to not get out of sync
[
"st rattr 0x${device.deviceNetworkId} ${endpointId} 6 0", "delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 8 0", "delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 1","delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 0","delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 7","delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 0x0300 8", "delay 500",
"st wattr 0x${device.deviceNetworkId} ${endpointId} 8 0x10 0x21 {0015}"
]
}
def poll(){
log.debug "Poll is calling refresh"
refresh()
}
def configure(){
log.debug "Initiating configuration reporting and binding"
[
zigbee.configSetup("6","0","0x10","0","60","{}"), "delay 1000",
zigbee.configSetup("8","0","0x20","5","600","{10}"), "delay 1500",
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 6 {${device.zigbeeId}} {}", "delay 1000",
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 8 {${device.zigbeeId}} {}", "delay 1000",
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 0x0300 {${device.zigbeeId}} {}"
]
}
//input Hue Integer values; returns color name for saturation 100%
private getColorName(hueValue){
if(hueValue>360 || hueValue<0)
return
hueValue = Math.round(hueValue / 100 * 360)
log.debug "hue value (in degrees) is $hueValue."
def colorName = "Color Mode"
if(hueValue>=0 && hueValue <= 4){
colorName = "Red"
}
else if (hueValue>=5 && hueValue <=21 ){
colorName = "Brick Red"
}
else if (hueValue>=22 && hueValue <=30 ){
colorName = "Safety Orange"
}
else if (hueValue>=31 && hueValue <=40 ){
colorName = "Dark Orange"
}
else if (hueValue>=41 && hueValue <=49 ){
colorName = "Amber"
}
else if (hueValue>=50 && hueValue <=56 ){
colorName = "Gold"
}
else if (hueValue>=57 && hueValue <=65 ){
colorName = "Yellow"
}
else if (hueValue>=66 && hueValue <=83 ){
colorName = "Electric Lime"
}
else if (hueValue>=84 && hueValue <=93 ){
colorName = "Lawn Green"
}
else if (hueValue>=94 && hueValue <=112 ){
colorName = "Bright Green"
}
else if (hueValue>=113 && hueValue <=135 ){
colorName = "Lime"
}
else if (hueValue>=136 && hueValue <=166 ){
colorName = "Spring Green"
}
else if (hueValue>=167 && hueValue <=171 ){
colorName = "Turquoise"
}
else if (hueValue>=172 && hueValue <=187 ){
colorName = "Aqua"
}
else if (hueValue>=188 && hueValue <=203 ){
colorName = "Sky Blue"
}
else if (hueValue>=204 && hueValue <=217 ){
colorName = "Dodger Blue"
}
else if (hueValue>=218 && hueValue <=223 ){
colorName = "Navy Blue"
}
else if (hueValue>=224 && hueValue <=251 ){
colorName = "Blue"
}
else if (hueValue>=252 && hueValue <=256 ){
colorName = "Han Purple"
}
else if (hueValue>=257 && hueValue <=274 ){
colorName = "Electric Indigo"
}
else if (hueValue>=275 && hueValue <=289 ){
colorName = "Electric Purple"
}
else if (hueValue>=290 && hueValue <=300 ){
colorName = "Orchid Purple"
}
else if (hueValue>=301 && hueValue <=315 ){
colorName = "Magenta"
}
else if (hueValue>=316 && hueValue <=326 ){
colorName = "Hot Pink"
}
else if (hueValue>=327 && hueValue <=335 ){
colorName = "Deep Pink"
}
else if (hueValue>=336 && hueValue <=339 ){
colorName = "Raspberry"
}
else if (hueValue>=340 && hueValue <=352 ){
colorName = "Crimson"
}
else if (hueValue>=353 && hueValue <=360 ){
colorName = "Red"
}
colorName
}
/**
def setLevel(level) {
def hue = this.device.currentValue("hue") ?: 23
def sat = this.device.currentValue("saturation") ?: 100
setColor([level:level, saturation:sat, hue:hue, switch:"on"])
}
// adding duration to enable transition time adjustments
def setLevel(value, duration = 21) {
log.trace "setLevel($value)"
def transitionTime = swapEndianHex(hexF(duration,4))
def unreachable = device.currentValue("unreachable")
log.debug unreachable
if(unreachable == null) {
sendEvent(name: 'unreachable', value: 1)
}
else {
sendEvent(name: 'unreachable', value: unreachable + 1)
}
if(unreachable > 2) {
sendEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off", displayed: false)
}
def cmds = []
if (value == 0) {
sendEvent(name: "switch", value: "off")
sendEvent(name: "switchColor", value: "off", displayed: false)
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}"
}
else if (device.currentValue("switch") == "off" && unreachable < 2) {
sendEvent(name: "switch", value: "on")
log.debug device.currentValue("colorMode")
sendEvent(name: "switchColor", value: (device.currentValue("colorMode") == "White" ? "White" : device.currentValue("colorName")), displayed: false)
}
sendEvent(name: "level", value: value)
def level = hex(value * 2.55)
if(value == 1) { level = hex(1) }
cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${level} ${transitionTime}}"
//log.debug cmds
cmds
}
**/
private getEndpointId() {
new BigInteger(device.endpointId, 16).toString()
}
private hex(value, width=2) {
def s = new BigInteger(Math.round(value).toString()).toString(16)
while (s.size() < width) {
s = "0" + s
}
s
}
private evenHex(value){
def s = new BigInteger(Math.round(value).toString()).toString(16)
while (s.size() % 2 != 0) {
s = "0" + s
}
s
}
//Need to reverse array of size 2
private byte[] reverseArray(byte[] array) {
byte tmp;
tmp = array[1];
array[1] = array[0];
array[0] = tmp;
return array
}
private hexF(value, width) {
def s = new BigInteger(Math.round(value).toString()).toString(16)
while (s.size() < width) {
s = "0" + s
}
s
}
private String swapEndianHex(String hex) {
reverseArray(hex.decodeHex()).encodeHex()
}
private Integer convertHexToInt(hex) {
Integer.parseInt(hex,16)
}