-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDTH version 1.0
755 lines (616 loc) · 24 KB
/
DTH version 1.0
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
preferences {
input("username", "text", title: "Username", description: "Your neviweb username (usually an email address)")
input("password", "password", title: "Password", description: "Your neviweb password")
input("devicid", "text", title: "Device Id:", description: "Device number for the thermostat (from 1 to 255)")
input("temperatureUnit", "enum", title: "Temperature Unit:", options: ["fahrenheit", "celsius"])
input("temperatureAdj", "enum", title: "Temperature adjustment:", description: "Device number for the thermostat (from -10 to +10)",
options: ["-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])
}
metadata {
definition (name: "Sinope Thermostat with Mode", namespace: "infofiend", author: "anthony pastor") {
capability "Polling"
capability "Thermostat"
capability "Thermostat Heating Setpoint"
capability "Thermostat Mode"
capability "Thermostat Operating State"
capability "Temperature Measurement"
capability "Actuator"
capability "Sensor"
command "presenceHome"
command "presenceAway"
command "setPresence", ["string"]
command "heatingSetpointUp"
command "heatingSetpointDown"
command "setHeatingSetpoint" //, ["number"]
command "getTempUnit"
command "setFahrenheit"
command "setCelsius"
command "auto"
command "off"
command "poll"
command "logout"
command "login"
command "selTempSetpoint" //, ["number", "number"]
command "getBackgroundColor" //, ["number"]
attribute "thermMode", "string"
attribute "thermPresence", "string"
attribute "thermLoad", "string"
attribute "temperatureUnit", "string"
attribute "realname", "string"
}
simulator {
// TODO: define status and reply messages here
}
tiles (scale: 2) {
multiAttributeTile(name:"thermostatFull", type:"thermostat", width:6, height:4) {
tileAttribute("device.temperature", key: "PRIMARY_CONTROL") {
attributeState("temperature", label:'${currentValue}°') //, unit:"dF")
}
tileAttribute("device.temperature", key: "VALUE_CONTROL") {
attributeState("VALUE_UP", action: "heatingSetpointUp")
attributeState("VALUE_DOWN", action: "heatingSetpointDown")
}
tileAttribute("device.thermostatOperatingState", key: "OPERATING_STATE") {
attributeState("idle", label: "${name}", backgroundColor:"#44b621")
attributeState("heating", label: "${name}", backgroundColor:"#ffa81e")
}
tileAttribute("device.thermMode", key: "THERMOSTAT_MODE") {
attributeState("Auto", label:'Auto', nextState:"Updating", defaultState: true)
attributeState("Away", label:'Away', nextState:"Updating")
attributeState("Standby", label:'Standby', nextState:"Updating")
attributeState("Manual", label:'Manual', nextState:"Updating")
attributeState("X-Bypass", label:'Manual', nextState:"Updating")
attributeState("Updating", label:'Updating')
}
tileAttribute("device.heatingSetpoint", key: "HEATING_SETPOINT") {
attributeState("--", label:'${name}', backgroundColor: "#C6C7CC", defaultState: true) //, unit:"dF"
attributeState("heatingSetpoint", label:'${currentValue}°') //, unit:"dF")
/** backgroundColors: [
// Celsius Color Range
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 33, color: "#d04e00"],
[value: 36, color: "#bc2323"],
// Fahrenheit Color Range
[value: 40, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 92, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
**/
}
}
valueTile("temperature", "device.temperature", width: 2, height: 2) {
state("temperature", label:'${currentValue}°', unit:"dF",
backgroundColors: [
// Celsius Color Range
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 33, color: "#d04e00"],
[value: 36, color: "#bc2323"],
// Fahrenheit Color Range
[value: 40, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 92, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
valueTile("heatingSetpoint", "device.heatingSetpoint", width: 3, height: 2, inactiveLabel: false, decoration: "flat") {
state "heat", label:'SP: ${currentValue}°', backgroundColor:"#ffffff"
} // , unit: "dF"
standardTile("thermostatOperatingState", "device.thermostatOperatingState", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "idle", label:'${name}', backgroundColor:"#44b621"
state "heating", label:'${name}', backgroundColor:"#ffa81e"
}
standardTile("thermLoad", "device.thermLoad", width: 2, height: 2) { // ,canChangeIcon: true
state "idle", label:'Load: 0% '
state "load", label:'Load:${currentValue}% ', defaultState: true, backgroundColors: [
// Celsius Color Range
[value: 0, color: "#ffffff"],
[value: 1, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 33, color: "#d04e00"],
[value: 36, color: "#bc2323"],
// Fahrenheit Color Range
[value: 40, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 92, color: "#d04e00"],
[value: 100, color: "#bc2323"]
]
}
standardTile("thermPresence", "device.thermPresence", inactiveLabel: false, width: 3, height: 3) { //, decoration: "flat"
state "Home", label:'Present', action:'presenceAway', backgroundColor: "#ADD8E6", icon: "st.Home.home2", nextState:"Updating"
state "Away", label:'Away', action:'presenceHome', backgroundColor: "#44b621", icon: "st.Transportation.transportation2", nextState:"Updating"
state "Updating", label:"Updating", backgroundColor: "#ffffff", icon: "st.secondary.secondary", defaultState: true
}
standardTile("thermMode", "device.thermMode", inactiveLabel: false, width: 3, height: 3, decoration: "flat" ) { //
state "Auto", label:'', action:'thermostat.off', backgroundColor: "#ADD8E7", icon: "st.thermostat.auto", nextState:"Updating"
state "Standby", label:'', action:'thermostat.auto', backgroundColor:"#C6C7CC", icon: "st.thermostat.heating-cooling-off", nextState:"Updating"
state "Manual", label:'Manual Mode', action:'thermostat.auto', backgroundColor: "#90d2a7", icon: "st.Office.office12", nextState:"Updating"
state "X-Bypass", label:'Manual Mode', action:'thermostat.auto', backgroundColor: "#90d2a7", icon: "st.Office.office12", nextState:"Updating"
state "Away", label:' Mode N/A ', backgroundColor: "#ffffff", nextState:"Updating" // icon: "st.secondary.secondary",
state "Updating", label:"Updating", action:'thermostat.auto', backgroundColor: "#ffffff", icon: "st.secondary.secondary", defaultState: true
}
standardTile("realdeviceName", "device.realname", height: 2, width:4, inactiveLabel: false, decoration: "flat") {
state "realname", label:'${currentValue} ' , defaultState: true //, backgroundColor: "#359115"
}
standardTile("refresh", "device.refresh", inactiveLabel: false, width: 2, height: 2, decoration: "flat") {
state "refresh", action:"polling.poll", icon:"st.secondary.refresh", defaultState: true
}
valueTile("temperatureUnit", "device.temperatureUnit", width: 2, height: 2, canChangeIcon: false) {
state "fahrenheit", label: "°F"
state "celsius", label: "°C"
}
controlTile("heatSliderControl", "device.heatingSetpoint", "slider", width: 3, height: 2, inactiveLabel: false) {
state "setHeatingSetpoint", label:'Setpoint is ', action:"thermostat.setHeatingSetpoint", range: "(60..86)"
}
standardTile("heatingSetpointUp", "device.heatingSetpoint", width: 2, height: 1, inactiveLabel: false, decoration: "flat") {
state "heatingSetpointUp", label:' ', action:"heatingSetpointUp", icon:"st.thermostat.thermostat-up", backgroundColor:"#bc2323"
}
standardTile("heatingSetpointDown", "device.heatingSetpoint", width: 2, height: 1, inactiveLabel: false, decoration: "flat") {
state "heatingSetpointDown", label:' ', action:"heatingSetpointDown", icon:"st.thermostat.thermostat-down", backgroundColor:"#bc2323"
}
main(["thermostatFull"])
details(["thermostatFull","thermPresence","thermMode", "heatSliderControl", "heatingSetpoint", "thermostatOperatingState","thermLoad","refresh"])
}
// details(["thermPresence","thermMode", "thermostatOperatingState", "heatSliderControl", "heatingSetpoint", "temperature","temperatureUnit", "refresh"]) // "heatingSetpointDown", "heatingSetpointUp",
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
initialize()
}
def initialize() {
// getTempUnit()
poll()
schedule("0 0 7 1/1 * ? *", poll)
}
// handle commands
def parse(String description) {
log.debug "parse: description = ${description}"
}
// PRESENCE FUNCTIONS
def presenceAway() {
log.trace "presenceAway: "
unschedule(logout)
setPresence('Away')
}
def presenceHome() {
log.trace "presenceHome: "
unschedule(logout)
setPresence('Home')
}
private setPresence(status) {
log.trace "setPresence(${status}: "
sendEvent(name: "thermMode", value: "Updating", isStateChange:true)
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
}
def thermostatID=data.devices.id [settings.devicid.toInteger()-1]
switch (status) {
case "Home":
log.trace "setPresence: Home"
log.debug "Switching Presence to Home / data.status.mode = 3"
def putParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/mode",
headers: ['Session-Id' : data.auth.session],
body: "mode=3"
]
httpPut(putParams) {resp ->
log.debug resp.data
}
break;
case "Away":
log.trace "setPresence: Away "
state.lastPresence = device.currentValue("thermPresence")
log.debug "Switching Presence to Away / data.status.mode = 5"
def putParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/mode",
headers: ['Session-Id' : data.auth.session],
body: "mode=5"
]
httpPut(putParams) {resp ->
log.debug resp.data
}
break;
}
schedule (now() + 2500, poll )
}
// MANUAL SETPOINT FUNCTIONS
def setHeatingSetpoint(temp) {
log.trace "heatingSetpoint( ${temp} ):"
unschedule(logout)
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
}
if ( device.latestState('thermMode') == 'Away' ) {
def putParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/mode",
headers: ['Session-Id' : data.auth.session],
body: "mode=3"
]
httpPut(putParams) {resp ->
log.debug resp.data
}
sendEvent(name: 'thermPresence', value: "Home", display: false, isStateChange: true )
sendEvent(name: 'thermMode', value: "Manual", display: false, isStateChange: true)
}
log.debug "setHeatingSetpoint: temperatureUnit = ${temperatureUnit}"
def thermostatID=data.devices.id [settings.devicid.toInteger()-1]
if ( temperatureUnit == "celsius" ) {
temp=temp
} else {
temp=fToC(Math.round(temp))
}
if (temp) {
if (temp < 1) {
temp = 1
}
if (temp > 36) {
temp = 36
}
}
def params = [
uri: "https://neviweb.com/api/device/${thermostatID}/setpoint",
headers: ['Session-Id' : data.auth.session],
body: "temperature=${temp}"
]
httpPut(params){resp ->
log.debug resp.data
}
schedule (now() + 2500, poll )
}
def heatingSetpointUp() {
def newSetpoint
if (device.currentValue("heatingSetpoint") != "--" && device.currentValue("heatingSetpoint") != "Off: No Setpoint" ) {
newSetpoint = device.currentValue("heatingSetpoint") as Number
}
log.trace "heatingSetpointUp: Last setpoint was (${newSetpoint}) degrees ${temperatureUnit}."
if (temperatureUnit == "celsius" ) {
newSetpoint = newSetpoint + 0.5
} else {
newSetpoint = Math.round(newSetpoint + 1)
}
log.debug "Setting heat set point up to: ${newSetpoint} degrees ${temperatureUnit}."
setHeatingSetpoint(newSetpoint)
}
def heatingSetpointDown() {
def newSetpoint = device.currentValue("heatingSetpoint")
log.trace "heatingSetpointDown: Last setpoint was (${newSetpoint}) degrees ${temperatureUnit}."
if (temperatureUnit == "celsius" ) {
newSetpoint = newSetpoint - 0.5
} else {
newSetpoint = Math.round(newSetpoint - 1)
}
log.debug "Setting heat set point down to: ${newSetpoint} degrees ${temperatureUnit}."
setHeatingSetpoint(newSetpoint)
}
// TEMPERATURE UNIT FUNCTIONS
def getTempUnit() {
state.tempUnit = device.currentValue("temperatureUnit")
}
def setFahrenheit() {
def temperatureUnit = "fahrenheit"
log.debug "Setting temperatureUnit to: ${temperatureUnit}"
sendEvent(name: "temperatureUnit", value: temperatureUnit, isStateChange: true, display: false)
}
def setCelsius() {
def temperatureUnit = "celsius"
log.debug "Setting temperatureUnit to: ${temperatureUnit}"
sendEvent(name: "temperatureUnit", value: temperatureUnit, isStateChange: true, display: false)
}
// AUTO & OFF FUNCTIONS
def off() {
log.trace "off():"
unschedule(logout)
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
}
state.lastSetpoint = device.currentValue('heatingSetpoint')
def thermostatID=data.devices.id [settings.devicid.toInteger()-1]
def putParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/mode",
headers: ['Session-Id' : data.auth.session],
body: ['mode': 0]
]
httpPut(putParams) { resp ->
log.debug resp.data
}
schedule (now() + 2500, poll )
}
def auto() {
log.trace "auto():"
unschedule(logout)
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
}
def thermostatID=data.devices.id [settings.devicid.toInteger()-1]
def putParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/mode",
headers: ['Session-Id' : data.auth.session],
body: ['mode': 3]
]
httpPut(putParams) { resp ->
log.debug resp.data
}
schedule (now() + 2500, poll )
}
// POLL
def poll() {
log.trace "poll():"
unschedule(logout)
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
}
def myPresence = ""
def myMode = ""
def thermostatID=data.devices.id [settings.devicid.toInteger()-1]
def getParams = [
uri: "https://neviweb.com/api/device/${thermostatID}/data",
requestContentType: "application/x-www-form-urlencoded; charset=UTF-8",
headers: ['Session-Id' : data.auth.session]
]
httpGet(getParams) { resp ->
data.status = resp.data
}
log.debug "data == ${data}"
log.debug "data.device == ${data.device}"
log.debug "data.gateway == ${data.gateway}"
log.debug "data.gatewayId == ${data.gateway.id}"
log.debug "data.status == ${data.status}"
switch (data.status.mode) {
case 0:
myPresence = "Home"
myMode = "Standby"
break;
case 2:
myPresence = "Home"
myMode = "Manual"
break;
case 3:
myPresence = "Home"
myMode = "Auto"
break;
case 5:
myPresence = "Away"
myMode = "Away"
break;
case 131:
myPresence = "Home"
myMode = "X-Bypass"
break;
}
def mySetpoint
def myTemp
def spLabel
def myColor
def correctSPT = [:]
if (data.status.mode != 0) {
correctSPT = selTempSetpoint(data.status.setpoint, data.status.temperature)
mySetpoint = correctSPT.sp
spLabel = "${correctSPT.sp}°"
myColor = getBackgroundColor(correctSPT.sp)
myTemp = correctSPT.t
} else {
correctSPT = selTempSetpoint(null, data.status.temperature)
mySetpoint = null
spLabel = "Off: No Setpoint"
myColor = "#C6C7CC"
myTemp = correctSPT.t
}
def myLoad = data.status.heatLevel as Number
log.debug " myLoad == ${myLoad}"
def myState = "idle"
if (myLoad > 0) { myState = "heating" }
sendEvent(name: 'thermPresence', value: myPresence, display: false) //isStateChange: true,
sendEvent(name: 'thermMode', value: myMode, display: false) //isStateChange: true,
sendEvent(name: 'heatingSetpoint', value: mySetpoint, label: spLabel, backgroundColor: "${myColor}", display: false) //isStateChange: true,
sendEvent(name: 'temperature', value: myTemp, display: false) //isStateChange: true,
sendEvent(name: 'thermLoad', value: myLoad, display: false) //isStateChange: true,
sendEvent(name: 'thermostatOperatingState', value: myState, isStateChange: true, display: false)
log.debug "My Presence is .....${myPresence}"
log.debug "My Mode is .....${myMode}"
log.debug "My setpoint is .....${mySetpoint}"
log.debug "My temperature is .....${myTemp}"
log.debug "My power load is .....${myLoad}"
log.debug "My operating state is .....${myState}"
def mydevice=data.devices.name[settings.devicid.toInteger() - 1]
sendEvent(name: 'realname', value: "${mydevice}", isStateChange: true)
schedule(now() + 300000, logout)
}
// LOGIN && UTILITY FUNCTIONS
def logout(method = null, args = [], success = {}) {
def getParams = [
uri: "https://neviweb.com",
path: "/api/logout",
requestContentType: "application/x-www-form-urlencoded; charset=UTF-8",
headers: ['Session-Id' : data.auth.session]
]
httpGet(getParams) {resp ->
data.auth = resp.data
}
log.debug "logout... "
}
def login(method = null, args = [], success = {}) {
def postParams = [
uri: "https://neviweb.com",
path: "/api/login",
body: "email=${settings.username}&password=${settings.password}&stayConnected=0",
requestContentType: "application/x-www-form-urlencoded; charset=UTF-8"
]
httpPost(postParams) {response ->
data.auth = response.data
}
if(!data.auth) {
log.debug "Problem in Login, unable to get data auth."
return
}
def getParams = [
uri: "https://neviweb.com",
path: "/api/gateway",
requestContentType: "application/json, text/javascript, */*; q=0.01",
headers: ['Session-Id' : data.auth.session]
]
httpGet(getParams) {resp ->
data.gateway = resp.data
}
log.debug "*************** data.gateway from httpGet() = ${data.gateway}"
getParams = [
uri: "https://neviweb.com",
path: "/api/device",
query: ['gatewayId' : data.gateway.id],
requestContentType: "application/json, text/javascript, */*; q=0.01",
headers: ['Session-Id' : data.auth.session]
]
httpGet(getParams) {resp ->
data.devices = resp.data
}
log.debug "Logged in.."
}
def isLoggedIn() {
log.debug "Is it login?..."
try{
def getParams = [
uri: "https://neviweb.com",
path: "/api/gateway",
requestContentType: "application/json, text/javascript, */*; q=0.01",
headers: ['Session-Id' : data.auth.session]
]
httpGet(getParams) {resp ->
if (resp.data.sessionExpired==true){
log.debug "No session Expired"
data.auth=""
}
}
if(!data.auth) {
log.debug "No, data auth. missing "
return false
} else {
log.debug "Yes.."
return true
}
}catch (e){
log.debug "No.."
return false
}
}
def cToF(temp) {
log.trace "cToF:"
def newTemp
if (temp) {
newTemp = (temp * 1.8 + 32).toDouble()
log.debug "old temp = ${temp}; new temp = ${newTemp}"
} else {
newTemp = null
log.debug "temp null (standby?)"
}
return newTemp
}
def fToC(temp) {
log.trace "cToF:"
def newTemp
if (temp) {
newTemp = ((temp - 32) / 1.8).toDouble()
log.debug "old temp = ${temp}; new temp = ${newTemp}"
} else {
newTemp = null
log.debug "temp null (standby?)"
}
return newTemp
}
def selTempSetpoint(setpoint, temp) {
log.trace "selTempSetpoint( ${setpoint}, ${temp} ): "
log.debug "temperatureUnit = ${temperatureUnit}"
def mySP = setpoint as Double
def myT = temp as Double
switch (temperatureUnit) {
case "celsius":
if (setpoint) {
mySP = mySP
}
myT = myT
break;
default:
if (setpoint) {
mySP = Math.round(cToF(mySP)) as Double
}
myT = Math.round(cToF(myT))
break;
}
log.debug "In ${temperatureUnit}, setpoint is ${mySP} and temperature is ${myT}."
return [sp: mySP, t: myT]
}
private getBackgroundColor(tempValue){
log.trace "getBackgroundColor(${tempValue})"
def backgroundColor
if (tempValue < 7 ){
backgroundColor = "#153591"
}
else if (tempValue>=7 && tempValue <15 ){
backgroundColor = "#1e9cbb"
}
else if (tempValue>=15 && tempValue <23 ){
backgroundColor = "#90d2a7"
}
else if (tempValue>=23 && tempValue <29 ){
backgroundColor = "44b621"
}
else if (tempValue>=29 && tempValue <33 ){
backgroundColor = "#f1d801"
}
else if (tempValue>=33 && tempValue <36 ){
backgroundColor = "#d04e00"
}
else if (tempValue>=36 && tempValue <40 ){
backgroundColor = "#bc2323"
}
else if (tempValue>=40 && tempValue <44 ){
backgroundColor = "#153591"
}
else if (tempValue>=44 && tempValue <59 ){
backgroundColor = "#1e9cbb"
}
else if (tempValue>=59 && tempValue <74 ){
backgroundColor = "#90d2a7"
}
else if (tempValue>=74 && tempValue <84 ){
backgroundColor = "44b621"
}
else if (tempValue>=84 && tempValue <92 ){
backgroundColor = "#f1d801"
}
else if (tempValue>=92 && tempValue <96 ){
backgroundColor = "#d04e00"
}
else if (tempValue>=96 ){
backgroundColor = "#bc2323"
}
return backgroundColor
}