-
Notifications
You must be signed in to change notification settings - Fork 19
/
Shelly-GU10.groovy
758 lines (675 loc) · 24.9 KB
/
Shelly-GU10.groovy
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
/**
* Shelly GU10 Device Handler
*
* Copyright © 2018-2019 Scott Grayban
* Copyright © 2020 Allterco Robotics US
*
* 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.
*
* Hubitat is the Trademark and intellectual Property of Hubitat Inc.
* Shelly is the Trademark and Intellectual Property of Allterco Robotics Ltd
*
*-------------------------------------------------------------------------------------------------------------------
*
* Changes:
* 1.0.1 - Change in color lighteffects code
* - Change how dbCleanUp works
* 1.0.0 - Initial release
*
*/
import groovy.transform.Field
import groovy.json.*
import hubitat.helper.ColorUtils
@Field static Map lightEffects = [1:"Meteor Shower",2:"Gradual Change",3:"Flash"]
def setVersion(){
state.Version = "1.0.1"
state.InternalName = "ShellyGU10"
}
metadata {
definition (
name: "Shelly GU10",
namespace: "sgrayban",
author: "Scott Grayban",
importUrl: "https://raw.githubusercontent.com/ShellyUSA/Hubitat-Drivers/master/Shelly-GU10.groovy"
)
{
capability "Actuator"
capability "Sensor"
capability "Refresh" // refresh command
capability "Switch"
capability "Bulb"
capability "Polling"
capability "ChangeLevel"
capability "SwitchLevel"
capability "ColorControl"
capability "PowerMeter"
capability "ColorMode"
command "Red"
command "Blue"
command "Green"
command "White"
command "Cyan"
command "Magenta"
command "Orange"
command "Purple"
command "Yellow"
command "Pink"
command "WarmWhite"
command "CoolWhite"
command "Daylight"
command "CustomRGBColor", ["r","g","b"]
command "setCustomEffect", [[name:"Effect to use (0=OFF)", type: "ENUM", description: "Effect to use (0=OFF)", constraints: ["0","1","2","3"]]]
command "Effect", [[name:"Effect to use", type: "ENUM", description: "Effect to use", constraints: ["0","1","2","3"] ] ]
command "UpdateDeviceFW" // ota?update=1
attribute "switch", "string"
attribute "colorMode", "string"
attribute "HEX", "string"
attribute "RGB", "string"
attribute "hue", "number"
attribute "saturation", "number"
attribute "huelevel", "number"
attribute "level", "number"
attribute "effectName", "string"
attribute "ColorLightEffects", "string"
attribute "WhiteModeOnly", "tring"
attribute "MAC", "string"
attribute "FW_Update_Needed", "string"
attribute "Cloud", "string"
attribute "IP", "string"
attribute "SSID", "string"
attribute "Cloud_Connected", "string"
attribute "WiFiSignal", "string"
attribute "LastRefresh", "string"
}
preferences {
def refreshRate = [:]
refreshRate << ["1 min" : "Refresh every minute"]
refreshRate << ["5 min" : "Refresh every 5 minutes"]
refreshRate << ["15 min" : "Refresh every 15 minutes"]
refreshRate << ["30 min" : "Refresh every 30 minutes"]
def Color_Mode = [:]
Color_Mode << ["color" : "Color"]
Color_Mode << ["white" : "White"]
input("ip", "string", title:"Shelly IP Address:", description:"EG; 192.168.0.100", defaultValue:"" , required: true, displayDuringSetup: true)
input name: "username", type: "text", title: "Username:", description: "(blank if none)", required: false
input name: "password", type: "password", title: "Password:", description: "(blank if none)", required: false
input ("ColorMode", "enum", title: "Colour Mode", options: Color_Mode, defaultValue: "white")
input ("refresh_Rate", "enum", title: "Device Refresh Rate", options: refreshRate, defaultValue: "30 min")
input "locale", "enum", title: "Choose refresh date format", required: true, defaultValue: true, //RK
options: [US:"US MM/DD/YYYY",UK:"UK DD/MM/YYYY"] //RK
input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true //RK
input name: "debugParse", type: "bool", title: "Enable JSON parse logging?", defaultValue: false
input name: "Shellyinfo", type: "text", title: "<center><font color=blue>Info Box</font><br>Shelly API docs located</center>", description: "<center><a href='http://shelly-api-docs.shelly.cloud/'>[here]</a></center>"
}
}
def ping() {
if (txtEnable) log.info "ping"
poll()
}
def initialize() {
log.info "initialize"
}
def installed() {
log.debug "Installed"
}
def uninstalled() {
log.debug "Uninstalled"
unschedule()
}
def updated() {
log.debug "Updated"
log.info "Preferences updated..."
log.warn "Debug logging is: ${debugOutput == true}"
unschedule()
dbCleanUp()
def le = new groovy.json.JsonBuilder(lightEffects)
sendEvent(name:"ColorLightEffects",value:le)
switch(ColorMode) {
case "color" :
setModeColor()
if (txtEnable) log.info "Executing mode=${ColorMode}"
break
case "white" :
setModeWhite()
if (txtEnable) log.info "Executing mode=${ColorMode}"
break
default:
setModeWhite()
}
switch(refresh_Rate) {
case "1 min" :
runEvery1Minute(autorefresh)
break
case "5 min" :
runEvery5Minutes(autorefresh)
break
case "15 min" :
runEvery15Minutes(autorefresh)
break
default:
runEvery30Minutes(autorefresh)
}
if (txtEnable) log.info ("Refresh set for every ${refresh_Rate} minute(s).")
if (debugOutput) runIn(1800,logsOff)
if (debugParse) runIn(1800,logsOff)
state.lightEffects = [1:"Meteor Shower",2:"Gradual Change",3:"Flash"]
sendEvent(name: "lightEffects", value: "${state.lightEffects}")
state.WhiteModeOnly = ["WarmWhite, CoolWhite & Daylight"]
sendEvent(name: "WhiteModeOnly", value:"${state.WhiteModeOnly}")
state.LastRefresh = new Date().format("YYYY/MM/dd \n HH:mm:ss", location.timeZone)
version()
refresh()
}
def refresh(){
logDebug "Shelly Status called"
def params1 = [uri: "http://${username}:${password}@${ip}/status"]
try {
httpGet(params1) {
resp1 -> resp1.headers.each {
logJSON "Response1: ${it.name} : ${it.value}"
}
obs1 = resp1.data
logJSON "params1: ${params1}"
logJSON "response1 contentType: ${resp1.contentType}"
logJSON "response1 data: ${resp1.data}"
// def each state
state.rssi = obs1.wifi_sta.rssi
state.ssid = obs1.wifi_sta.ssid
state.mac = obs1.mac
state.has_update = obs1.has_update
state.cloud = obs1.cloud.enabled
state.effect = obs1.lights.effect[0]
state.cloud_connected = obs1.cloud.connected
ison = obs1.lights.ison[0]
colorMode = obs1.lights.mode[0]
red = obs1.lights.red[0]
green = obs1.lights.green[0]
blue = obs1.lights.blue[0]
rgbCode = "${red},${green},${blue}"
sendEvent(name: "MAC", value: state.mac)
sendEvent(name: "SSID", value: state.ssid)
sendEvent(name: "level", value: obs1.lights.gain[0])
sendEvent(name: "colorMode", value: colorMode)
sendEvent(name: "IP", value: obs1.wifi_sta.ip)
sendEvent(name: "power", value: obs1.meters.power[0])
/*
-30 dBm Excellent | -67 dBm Good | -70 dBm Poor | -80 dBm Weak | -90 dBm Dead
*/
signal = state.rssi
if (signal <= 0 && signal >= -70) {
sendEvent(name: "WiFiSignal", value: "<font color='green'>Excellent</font>", isStateChange: true);
} else
if (signal < -70 && signal >= -80) {
sendEvent(name: "WiFiSignal", value: "<font color='green'>Good</font>", isStateChange: true);
} else
if (signal < -80 && signal >= -90) {
sendEvent(name: "WiFiSignal", value: "<font color='yellow'>Poor</font>", isStateChange: true);
} else
if (signal < -90 && signal >= -100) {
sendEvent(name: "WiFiSignal", value: "<font color='red'>Weak</font>", isStateChange: true);
}
updateDataValue("model", state.DeviceType)
updateDataValue("ShellyHostname", state.ShellyHostname)
updateDataValue("ShellyIP", obs1.wifi_sta.ip)
updateDataValue("ShellySSID", state.ssid)
updateDataValue("manufacturer", "Allterco Robotics")
updateDataValue("MAC", state.mac)
if (colorMode == "color") if (txtEnable) log.info "rgbCode = $red,$green,$blue,$white"
if (colorMode == "color") sendEvent(name: "RGB", value: rgbCode)
if (colorMode == "color") Hex = ColorUtils.rgbToHEX( [red, blue, green] )
if (colorMode == "color") sendEvent(name: "HEX", value: Hex)
hsvColors = ColorUtils.rgbToHSV([red.toInteger(), green.toInteger(), blue.toInteger()])
sendEvent(name: "hue", value: hsvColors[0])
sendEvent(name: "saturation", value: hsvColors[1])
sendEvent(name: "huelevel", value: hsvColors[2])
if (ison == true) {
sendEvent(name: "switch", value: "on")
} else {
sendEvent(name: "switch", value: "off")
}
if (cloud == enabled) {
sendEvent(name: "Cloud", value: "<font color='green'>Enabled</font>")
} else {
sendEvent(name: "Cloud", value: "<font color='red'>Disabled</font>")
}
state.cloudConnected = obs1.cloud.connected
if (state.cloudConnected == true) {
sendEvent(name: "Cloud_Connected", value: "<font color='green'>Connected</font>")
} else {
sendEvent(name: "Cloud_Connected", value: "<font color='red'>Not Connected</font>")
}
// FW Updates
if (state.has_update == true) {
if (txtEnable) log.info "sendEvent NEW SHELLY FIRMWARE"
sendEvent(name: "FW_Update_Needed", value: "<font color='red'>FIRMWARE Update Required</font>")
}
if (state.has_update == false) {
if (txtEnable) log.info "sendEvent Device FW is current"
sendEvent(name: "FW_Update_Needed", value: "<font color='green'>Device FW is current</font>")
}
// send Effects
if (state.effect == 0) {
if (txtEnable) log.info "sendEvent effect None"
sendEvent(name: "effectName", value: "Disabled")
}
if (state.effect == 1) {
if (txtEnable) log.info "sendEvent effect Meteor shower"
sendEvent(name: "effectName", value: "Meteor Shower")
}
if (state.effect == 2) {
if (txtEnable) log.info "sendEvent effect Gradual change"
sendEvent(name: "effectName", value: "Gradual Change")
}
if (state.effect == 3) {
if (txtEnable) log.info "sendEvent effect Breath"
sendEvent(name: "effectName", value: "Breath")
}
if (state.effect == 4) {
if (txtEnable) log.info "sendEvent effect Flash"
sendEvent(name: "effectName", value: "Flash")
}
if (state.effect == 5) {
if (txtEnable) log.info "sendEvent effect Gradual On/Off"
sendEvent(name: "effectName", value: "Gradual On/Off")
}
if (state.effect == 6) {
if (txtEnable) log.info "sendEvent effect Red/Green Change"
sendEvent(name: "effectName", value: "Red/Green Change")
}
} // End try
} catch (e) {
log.error "something went wrong: $e"
}
} // End refresh
def getSettings(){
logDebug "Shelly Settings called"
def params = [uri: "http://${username}:${password}@${ip}/settings"]
try {
httpGet(params) {
resp -> resp.headers.each {
logJSON "Response: ${it.name} : ${it.value}"
}
obs = resp.data
logJSON "params: ${params}"
logJSON "response contentType: ${resp.contentType}"
logJSON "response data: ${resp.data}"
state.DeviceType = obs.device.type
state.ShellyHostname = obs.device.hostname
} // End try
} catch (e) {
log.error "something went wrong: $e"
}
} // End refresh
//switch.on
def on() {
if (txtEnable) log.info "Executing switch.on"
sendSwitchCommand "/light/0?turn=on"
}
//switch.off
def off() {
if (txtEnable) log.info "Executing switch.off"
sendSwitchCommand "/light/0?turn=off"
}
def Red() {
if (txtEnable) log.info "Executing colour red"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=0&blue=0&turn=on"
}
def Green() {
if (txtEnable) log.info "Executing colour green"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=0&green=128&blue=0&turn=on"
}
def Blue() {
if (txtEnable) log.info "Executing colour blue"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=0&green=0&blue=255&turn=on"
}
def White() {
if (txtEnable) log.info "Executing colour white"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=255&blue=255&turn=on"
}
def Cyan() {
if (txtEnable) log.info "Executing colour cyan"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=0&green=255&blue=255&turn=on"
}
def Magenta() {
if (txtEnable) log.info "Executing colour magenta"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=0&blue=33&turn=on"
}
def Orange() {
if (txtEnable) log.info "Executing colour orange"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=102&blue=0&turn=on"
}
def Purple() {
if (txtEnable) log.info "Executing colour purple"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=170&green=0&blue=255&turn=on"
}
def Yellow() {
if (txtEnable) log.info "Executing colour yellow"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=255&blue=0&turn=on"
}
def Pink() {
if (txtEnable) log.info "Executing colour pink"
sendSwitchCommand "/light/0?turn=on&gain=100&effect=0&red=255&green=20&blue=147&turn=on"
}
// White mode colours
// http://www.westinghouselighting.com/color-temperature.aspx
// http://planetpixelemporium.com/tutorialpages/light.html
// temp is in Kevin
def WarmWhite() {
if (txtEnable) log.info "Executing colour warmWhite"
if (colorMode == "white") sendSwitchCommand "/light/0?turn=on&white=0&temp=3000"
}
def CoolWhite() {
if (txtEnable) log.info "Executing colour coolWhite"
if (colorMode == "white") sendSwitchCommand "/light/0?turn=on&white=50&temp=4500"
}
def Daylight() {
if (txtEnable) log.info "Executing colour daylight"
if (colorMode == "white") sendSwitchCommand "/light/0?turn=on&white=100&temp=6500"
}
// switch.CustomRGBwColor
def CustomRGBColor(r,g,b) {
if (txtEnable) log.info "Executing Custom Color Red:${r} Green:${g} Blue:${b}"
if (w == null) {
sendSwitchCommand "/light/0?turn=on&gain=100&red=${r}&green=${g}&blue=${b}"
} else {
sendSwitchCommand "/light/0?turn=on&gain=100&red=${r}&green=${g}&blue=${b}"
}
}
def setHue(value)
{
refresh()
setColor([hue: value, saturation: device.currentValue("saturation").toInteger(), level: device.currentValue("huelevel").toInteger()])
}
def setSaturation(value)
{
refresh()
setColor([hue: device.currentValue("hue").toInteger(), saturation: value, level: device.currentValue("huelevel").toInteger()])
}
def setColor( parameters ){
logDebug "Color set to ${parameters}"
sendEvent(name: "hue", value: parameters.hue)
sendEvent(name: "saturation", value: parameters.saturation)
sendEvent(name: "huelevel", value: parameters.level)
rgbColors = ColorUtils.hsvToRGB( [parameters.hue, parameters.saturation, parameters.level] )
r = rgbColors[0].toInteger()
g = rgbColors[1].toInteger()
b = rgbColors[2].toInteger()
def Hex = ColorUtils.rgbToHEX([r, g, b])
if (txtEnable) log.info "Red: ${r},Green:${g},Blue:${b}"
if (txtEnable) log.info "HEX: ${HEX}"
CustomRGBColor(r,g,b)
}
//switch.effect
def Effect(number) {
if (txtEnable) log.info "Executing colour white"
sendSwitchCommand "/light/0?effect=${number}"
}
//switch.mode
def Mode(string) {
if (txtEnable) log.info "Executing colour mode"
sendSwitchCommand "/settings?mode=${string}"
}
//switch.gain
def setLevel() {
if (txtEnable) log.info "Executing Brightness Level"
sendLevelSwitchCommand "turn=on&effect=0&gain=${number}"
}
//switch.level
// TODO: Need to add rate and transition to Shelly FW
def setLevel(percent, transTime) {
if (ColorMode == "white") {
sendLevelCommand "turn=on&brightness=${percent}"
if (txtEnable) log.info ("White Mode setLevel(x): transition time = ${transTime}")
} else
sendLevelCommand "turn=on&gain=${percent}"
if (txtEnable) log.info ("Color Mode setLevel(x): transition time = ${transTime}")
}
def setRateLevel(percentage, rate) {
if (percentage < 0 || percentage > 100) {
log.warn ("$device.name $device.label: Entered brightness is not from 0...100")
return
}
// percentage = percentage.toInteger()
if (ColorMode == "white") {
sendLevelCommand "turn=on&brightness=${percentage}"
if (txtEnable) log.info ("White Mode setLevel(x,x): rate = ${rate} // percentage = ${percentage}")
} else
sendLevelCommand "turn=on&gain=${percentage}"
if (txtEnable) log.info ("Color Mode setLevel(x,x): rate = ${rate} // percentage = ${percentage}")
}
// End Direct Device Commands
def startLevelChange(direction) {
if (txtEnable) log.info ("startLevelChange: direction = ${direction}")
if (direction == "up") {
levelUp()
} else {
levelDown()
}
}
def stopLevelChange() {
if (txtEnable) log.info ("stopLevelChange")
unschedule(levelUp)
unschedule(levelDown)
}
def levelUp() {
def newLevel = device.currentValue("level").toInteger() + 2
if (newLevel > 101) { return }
if (newLevel > 100) { newLevel = 100 }
setRateLevel(newLevel, 0)
runInMillis(500, levelUp)
}
def levelDown() {
def newLevel = device.currentValue("level").toInteger() - 2
if (newLevel < -1) { return }
else if (newLevel <= 0) { off() }
else {
setRateLevel(newLevel, 0)
runInMillis(500, levelDown)
}
}
def logsOff(){
log.warn "debug logging auto disabled..."
device.updateSetting("debugOutput",[value:"false",type:"bool"])
device.updateSetting("debugParse",[value:"false",type:"bool"])
}
def autorefresh() {
if (locale == "UK") {
if (debugOutput) log.info "Get last UK Date DD/MM/YYYY"
state.LastRefresh = new Date().format("d/MM/YYYY \n HH:mm:ss", location.timeZone)
sendEvent(name: "LastRefresh", value: state.LastRefresh, descriptionText: "Last refresh performed")
}
if (locale == "US") {
if (debugOutput) log.info "Get last US Date MM/DD/YYYY"
state.LastRefresh = new Date().format("MM/d/YYYY \n HH:mm:ss", location.timeZone)
sendEvent(name: "LastRefresh", value: state.LastRefresh, descriptionText: "Last refresh performed")
}
if (txtEnable) log.info "Executing 'auto refresh'" //RK
getSettings()
refresh()
}
private logDebug(msg) {
if (settings?.debugOutput || settings?.debugOutput == null) {
log.debug "$msg"
}
}
private logJSON(msg) {
if (settings?.debugParse || settings?.debugParse == null) {
log.info "$msg"
}
}
// handle commands
//RK Updated to include last refreshed
def poll() {
if (locale == "UK") {
if (debugOutput) log.info "Get last UK Date DD/MM/YYYY"
state.LastRefresh = new Date().format("d/MM/YYYY \n HH:mm:ss", location.timeZone)
sendEvent(name: "LastRefresh", value: state.LastRefresh, descriptionText: "Last refresh performed")
}
if (locale == "US") {
if (debugOutput) log.info "Get last US Date MM/DD/YYYY"
state.LastRefresh = new Date().format("MM/d/YYYY \n HH:mm:ss", location.timeZone)
sendEvent(name: "LastRefresh", value: state.LastRefresh, descriptionText: "Last refresh performed")
}
if (txtEnable) log.info "Executing 'poll'" //RK
dbCleanUp()
refresh()
}
def setModeWhite() {
if (txtEnable) log.info "color mode white"
def params = [uri: "http://${username}:${password}@${ip}/settings?mode=white"]
try {
httpGet(params) {
resp -> resp.headers.each {
logDebug "Response: ${it.name} : ${it.value}"
}
} // End try
} catch (e) {
log.error "something went wrong: $e"
}
runIn(15,refresh)
}
def setModeColor() {
if (txtEnable) log.info "color mode color"
def params = [uri: "http://${username}:${password}@${ip}/settings?mode=color"]
try {
httpGet(params) {
resp -> resp.headers.each {
logDebug "Response: ${it.name} : ${it.value}"
}
} // End try
} catch (e) {
log.error "something went wrong: $e"
}
runIn(15,refresh)
}
def sendSwitchCommand(action) {
if (txtEnable) log.info "Calling ${action}"
def path = path
def body = body
def headers = [:]
if (username != null) {
headers.put("HOST", "${username}:${password}@${ip}")
} else {
headers.put("HOST", "${ip}")
}
headers.put("Content-Type", "application/x-www-form-urlencoded")
runIn(2, refresh)
try {
def hubAction = new hubitat.device.HubAction(
method: method,
path: action,
body: body,
headers: headers
)
logDebug hubAction
return hubAction
}
catch (Exception e) {
logDebug "sendSwitchCommand hit exception ${e} on ${hubAction}"
}
}
def sendLevelCommand(action) {
if (txtEnable) log.info "Setting Level ${action}"
if (username != null) {
host = "${username}:${password}@${ip}"
} else {
host = "${ip}"
}
sendHubCommand(new hubitat.device.HubAction(
method: "POST",
path: "/light/0",
body: action,
headers: [
HOST: host,
"Content-Type": "application/x-www-form-urlencoded"
]
))
refresh()
}
def UpdateDeviceFW() {
if (txtEnable) log.info "Updating Device FW"
if (username != null) {
host = "${username}:${password}@${ip}"
} else {
host = "${ip}"
}
sendEvent(name: "FW_Update_Needed", value: "Please Wait..Updating FW.")
sendHubCommand(new hubitat.device.HubAction(
method: "POST",
path: "/ota?update=1",
body: action,
headers: [
HOST: host,
"Content-Type": "application/x-www-form-urlencoded"
]
))
runIn(30,refresh)
}
def parse(description) {
return
}
private dbCleanUp() {
// unschedule()
state.clear()
}
// Check Version ***** with great thanks and acknowlegment to Cobra (github CobraVmax) for his original code **************
def version(){
updatecheck()
schedule("0 0 18 1/1 * ? *", updatecheck) // Cron schedule
// schedule("0 0/1 * 1/1 * ? *", updatecheck) // Test Cron schedule
}
def updatecheck(){
setVersion()
def paramsUD = [uri: "https://raw.githubusercontent.com/ShellyUSA/Hubitat-Drivers/master/resources/version.json", contentType: "application/json; charset=utf-8"]
try {
httpGet(paramsUD) { respUD ->
if (txtEnable) log.warn " Version Checking - Response Data: ${respUD.data}" // Troubleshooting Debug Code - Uncommenting this line should show the JSON response from your webserver
def copyrightRead = (respUD.data.copyright)
state.Copyright = copyrightRead
def newVerRaw = (respUD.data.versions.Driver.(state.InternalName))
def newVer = (respUD.data.versions.Driver.(state.InternalName).replace(".", ""))
def currentVer = state.Version.replace(".", "")
state.UpdateInfo = (respUD.data.versions.UpdateInfo.Driver.(state.InternalName))
state.author = (respUD.data.author)
state.icon = (respUD.data.icon)
if(newVer == "NLS"){
state.DriverStatus = "<b>** This driver is no longer supported by $state.author **</b>"
log.warn "** This driver is no longer supported by $state.author **"
}
else if(currentVer < newVer){
state.DriverStatus = "<b>New Version Available (Version: $newVerRaw)</b>"
log.warn "** There is a newer version of this driver available (Version: $newVerRaw) **"
log.warn "** $state.UpdateInfo **"
}
else if(currentVer > newVer){
state.DriverStatus = "<b>You are using a Test version of this Driver (Version: $newVerRaw)</b>"
}
else{
state.DriverStatus = "Current"
log.info "You are using the current version of this driver"
}
} // httpGet
} // try
catch (e) {
log.error "Something went wrong: CHECK THE JSON FILE AND IT'S URI - $e"
}
if(state.DriverStatus == "Current"){
state.UpdateInfo = "Up to date"
sendEvent(name: "DriverUpdate", value: state.UpdateInfo)
sendEvent(name: "DriverStatus", value: state.DriverStatus)
}
else {
sendEvent(name: "DriverUpdate", value: state.UpdateInfo)
sendEvent(name: "DriverStatus", value: state.DriverStatus)
}
sendEvent(name: "DriverAuthor", value: "sgrayban")
sendEvent(name: "DriverVersion", value: state.Version)
}