forked from SmartThingsCommunity/SmartThingsPublic
/
stelpro-ki-zigbee-thermostat.groovy
645 lines (558 loc) · 22.3 KB
/
stelpro-ki-zigbee-thermostat.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
/**
* Copyright 2017 - 2018 Stelpro
*
* 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.
*
* Stelpro Ki ZigBee Thermostat
*
* Author: Stelpro
*
* Date: 2018-04-04
*/
import physicalgraph.zigbee.zcl.DataType
metadata {
definition (name: "Stelpro Ki ZigBee Thermostat", namespace: "stelpro", author: "Stelpro", ocfDeviceType: "oic.d.thermostat") {
capability "Actuator"
capability "Temperature Measurement"
capability "Temperature Alarm"
capability "Thermostat"
capability "Thermostat Mode"
capability "Thermostat Operating State"
capability "Thermostat Heating Setpoint"
capability "Configuration"
capability "Sensor"
capability "Refresh"
capability "Health Check"
attribute "outsideTemp", "number"
command "setOutdoorTemperature"
command "quickSetOutTemp" // Maintain backward compatibility with self published versions of the "Stelpro Get Remote Temperature" SmartApp
command "increaseHeatSetpoint"
command "decreaseHeatSetpoint"
command "parameterSetting"
command "eco" // Command does not exist in "Thermostat Mode"
command "updateWeather"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0201, 0204", outClusters: "0402", manufacturer: "Stelpro", model: "STZB402+", deviceJoinName: "Stelpro Ki ZigBee Thermostat"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0201, 0204", outClusters: "0402", manufacturer: "Stelpro", model: "ST218", deviceJoinName: "Stelpro Orleans Convector"
}
// simulator metadata
simulator { }
preferences {
input("lock", "enum", title: "Do you want to lock your thermostat's physical keypad?", options: ["No", "Yes"], defaultValue: "No", required: false, displayDuringSetup: false)
input("heatdetails", "enum", title: "Do you want a detailed operating state notification?", options: ["No", "Yes"], defaultValue: "No", required: false, displayDuringSetup: true)
input("zipcode", "text", title: "ZipCode (Outdoor Temperature)", description: "[Do not use space](Blank = No Forecast)")
}
tiles(scale : 2) {
multiAttributeTile(name:"thermostatMulti", type:"thermostat", width:6, height:4, canChangeIcon: true) {
tileAttribute("device.temperature", key: "PRIMARY_CONTROL") {
attributeState("temperature", label:'${currentValue}°', icon: "st.alarm.temperature.normal")
}
tileAttribute("device.heatingSetpoint", key: "VALUE_CONTROL") {
attributeState("VALUE_UP", action: "increaseHeatSetpoint")
attributeState("VALUE_DOWN", action: "decreaseHeatSetpoint")
}
tileAttribute("device.thermostatOperatingState", key: "OPERATING_STATE") {
attributeState("idle", backgroundColor:"#44b621")
attributeState("heating", backgroundColor:"#ffa81e")
}
tileAttribute("device.thermostatMode", key: "THERMOSTAT_MODE") {
attributeState("off", label:'${name}')
attributeState("heat", label:'${name}')
attributeState("eco", label:'${name}')
}
tileAttribute("device.heatingSetpoint", key: "HEATING_SETPOINT") {
attributeState("heatingSetpoint", label:'${currentValue}°')
}
}
standardTile("mode", "device.thermostatMode", width: 2, height: 2) {
state "off", label:'${name}', action:"heat", nextState:"heat", icon:"st.Home.home29"
state "heat", label:'${name}', action:"eco", nextState:"eco", icon:"st.Outdoor.outdoor3"
state "eco", label:'${name}', action:"off", nextState:"off", icon:"st.Outdoor.outdoor3"
}
valueTile("heatingSetpoint", "device.heatingSetpoint", width: 2, height: 2) {
state "heatingSetpoint", label:'Setpoint ${currentValue}°', backgroundColors:[
// Celsius
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 28, color: "#f1d801"],
[value: 35, color: "#d04e00"],
[value: 37, color: "#bc2323"],
// Fahrenheit
[value: 40, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
}
standardTile("temperatureAlarm", "device.temperatureAlarm", decoration: "flat", width: 2, height: 2) {
state "default", label: 'No Alarm', icon: "st.alarm.temperature.normal", backgroundColor: "#ffffff"
state "cleared", label: 'No Alarm', icon: "st.alarm.temperature.normal", backgroundColor: "#ffffff"
state "freeze", label: 'Freeze', icon: "st.alarm.temperature.freeze", backgroundColor: "#bc2323"
state "heat", label: 'Overheat', icon: "st.alarm.temperature.overheat", backgroundColor: "#bc2323"
}
standardTile("refresh", "device.refresh", decoration: "flat", width: 2, height: 2) {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
}
main ("thermostatMulti")
details(["thermostatMulti", "mode", "heatingSetpoint", "temperatureAlarm", "refresh", "configure"])
}
}
def getTHERMOSTAT_CLUSTER() { 0x0201 }
def getATTRIBUTE_LOCAL_TEMP() { 0x0000 }
def getATTRIBUTE_PI_HEATING_STATE() { 0x0008 }
def getATTRIBUTE_HEAT_SETPOINT() { 0x0012 }
def getATTRIBUTE_SYSTEM_MODE() { 0x001C }
def getATTRIBUTE_MFR_SPEC_SETPOINT_MODE() { 0x401C }
def getATTRIBUTE_MFR_SPEC_OUT_TEMP() { 0x4001 }
def getTHERMOSTAT_UI_CONFIG_CLUSTER() { 0x0204 }
def getATTRIBUTE_TEMP_DISP_MODE() { 0x0000 }
def getATTRIBUTE_KEYPAD_LOCKOUT() { 0x0001 }
def getSupportedThermostatModes() {
["heat", "eco", "off"]
}
def getMinSetpointIndex() {
0
}
def getMaxSetpointIndex() {
1
}
def getThermostatSetpointRange() {
(getTemperatureScale() == "C") ? [5, 30] : [41, 86]
}
def getHeatingSetpointRange() {
thermostatSetpointRange
}
def getSetpointStep() {
(getTemperatureScale() == "C") ? 0.5 : 1.0
}
def getModeMap() {[
"00":"off",
"04":"heat",
"05":"eco"
]}
def getDutyCyclePeriod() {
15 // seconds
}
def setupHealthCheck() {
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
}
def configureSupportedRanges() {
sendEvent(name: "supportedThermostatModes", value: supportedThermostatModes, displayed: false)
// These are part of the deprecated Thermostat capability. Remove these when that capability is removed.
sendEvent(name: "thermostatSetpointRange", value: thermostatSetpointRange, displayed: false)
sendEvent(name: "heatingSetpointRange", value: heatingSetpointRange, displayed: false)
}
def installed() {
sendEvent(name: "temperatureAlarm", value: "cleared", displayed: false)
setupHealthCheck()
configureSupportedRanges()
}
def updated() {
def requests = []
setupHealthCheck()
configureSupportedRanges()
unschedule(scheduledUpdateWeather)
if (settings.zipcode) {
requests += updateWeather()
runEvery1Hour(scheduledUpdateWeather)
}
requests += parameterSetting()
response(requests)
}
def parameterSetting() {
def lockmode = null
def valid_lock = false
log.debug "lock : $settings.lock"
if (settings.lock == "Yes") {
lockmode = 0x01
valid_lock = true
} else if (settings.lock == "No") {
lockmode = 0x00
valid_lock = true
}
if (valid_lock) {
log.debug "lock valid"
zigbee.writeAttribute(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_KEYPAD_LOCKOUT, DataType.ENUM8, lockmode) +
poll()
} else {
log.debug "nothing valid"
}
}
def parse(String description) {
log.debug "Parse description $description"
def map = [:]
// If the user installed with an old DTH version, update so that the new mobile client will work
if (!device.currentValue("supportedThermostatModes")) {
configureSupportedRanges()
}
// Existing installations need the temperatureAlarm state initialized
if (device.currentValue("temperatureAlarm") == null) {
sendEvent(name: "temperatureAlarm", value: "cleared", displayed: false)
}
if (description?.startsWith("read attr -")) {
def descMap = zigbee.parseDescriptionAsMap(description)
log.debug "Desc Map: $descMap"
if (descMap.clusterInt == THERMOSTAT_CLUSTER) {
if (descMap.attrInt == ATTRIBUTE_LOCAL_TEMP) {
map = handleTemperature(descMap)
} else if (descMap.attrInt == ATTRIBUTE_HEAT_SETPOINT) {
def intVal = Integer.parseInt(descMap.value, 16)
// We receive 0x8000 when the thermostat is off
if (intVal != 0x8000) {
log.debug "HEATING SETPOINT"
map.name = "heatingSetpoint"
map.value = getTemperature(descMap.value)
map.unit = getTemperatureScale()
map.data = [heatingSetpointRange: heatingSetpointRange]
// Sometimes we don't get an updated operating state when going from heating -> idle with a setpoint just below ambient;
// so ask for the operating state, but wait 1.5 times the duty cycle period.
def ambientTemp = device.currentValue("temperature")
if (ambientTemp != null && map.value < ambientTemp) {
runIn((dutyCyclePeriod * 3) / 2 as int, updateOperatingState, [overwrite: true])
}
}
} else if (descMap.attrInt == ATTRIBUTE_SYSTEM_MODE) {
log.debug "MODE - ${descMap.value}"
def value = modeMap[descMap.value]
// If we receive an off here then we are off
// Else we will determine the real mode in the mfg specific packet so store this
if (value == "off") {
map.name = "thermostatMode"
map.value = value
map.data = [supportedThermostatModes: supportedThermostatModes]
} else {
state.storedSystemMode = value
// Sometimes we don't get the final decision, so ask for it just in case
sendHubCommand(zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_SETPOINT_MODE, ["mfgCode": "0x1185"]))
}
// Right now this doesn't seem to happen -- regardless of the size field the value seems to be two bytes
/*if (descMap.size == "08") {
log.debug "MODE"
map.name = "thermostatMode"
map.value = modeMap[descMap.value]
map.data = [supportedThermostatModes: supportedThermostatModes]
} else if (descMap.size == "0A") {
log.debug "MODE & SETPOINT MODE"
def twoModesAttributes = descMap.value[0..-9]
map.name = "thermostatMode"
map.value = modeMap[twoModesAttributes]
map.data = [supportedThermostatModes: supportedThermostatModes]
}*/
} else if (descMap.attrInt == ATTRIBUTE_MFR_SPEC_SETPOINT_MODE) {
log.debug "SETPOINT MODE - ${descMap.value}"
// If the storedSystemMode is heat, then we set the real mode here
// Otherwise, we just ignore this
if (!state.storedSystemMode || state.storedSystemMode == "heat") {
log.debug "USING SETPOINT MODE - ${descMap.value}"
map.name = "thermostatMode"
map.value = modeMap[descMap.value]
map.data = [supportedThermostatModes: supportedThermostatModes]
}
} else if (descMap.attrInt == ATTRIBUTE_PI_HEATING_STATE) {
def intVal = Integer.parseInt(descMap.value, 16)
log.debug "HEAT DEMAND"
map.name = "thermostatOperatingState"
if (intVal < 10) {
map.value = "idle"
} else {
map.value = "heating"
}
// If the user does not want to see the Idle and Heating events in the event history,
// don't show them. Otherwise, don't show them more frequently than 30 seconds.
if (settings.heatdetails == "No" ||
!secondsPast(device.currentState("thermostatOperatingState")?.getLastUpdated(), 30)) {
map.displayed = false
}
}
}
}
def result = null
if (map) {
result = createEvent(map)
}
log.debug "Parse returned $map"
return result
}
def handleTemperature(descMap) {
def map = [:]
def intVal = Integer.parseInt(descMap.value, 16)
// Handle special temperature flags where we need to change the event type
if (intVal == 0x7ffd) { // Freeze Alarm
map.name = "temperatureAlarm"
map.value = "freeze"
} else if (intVal == 0x7fff) { // Overheat Alarm
map.name = "temperatureAlarm"
map.value = "heat"
} else if (intVal == 0x8000) { // Temperature Sensor Error
map.descriptionText = "Received a temperature error"
} else {
if (intVal > 0x8000) { // Handle negative C (< 32F) readings
intVal = -(Math.round(2 * (65536 - intVal)) / 2)
}
map.name = "temperature"
map.value = getTemperature(intVal)
map.unit = getTemperatureScale()
// Handle cases where we need to update the temperature alarm state given certain temperatures
// Account for a f/w bug where the freeze alarm doesn't trigger at 0C
if (map.value < (map.unit == "C" ? 0 : 32)) {
log.debug "EARLY FREEZE ALARM @ $map.value $map.unit (raw $intVal)"
sendEvent(name: "temperatureAlarm", value: "freeze")
}
// Overheat alarm doesn't trigger until 80C, but we'll start sending at 50C to match thermostat display
else if (map.value >= (map.unit == "C" ? 50 : 122)) {
log.debug "EARLY HEAT ALARM @ $map.value $map.unit (raw $intVal)"
sendEvent(name: "temperatureAlarm", value: "heat")
} else if (device.currentValue("temperatureAlarm") != "cleared") {
log.debug "CLEAR ALARM @ $map.value $map.unit (raw $intVal)"
sendEvent(name: "temperatureAlarm", value: "cleared")
}
}
map
}
def updateWeather() {
log.debug "updating weather"
def weather
// If there is a zipcode defined, weather forecast will be sent. Otherwise, no weather forecast.
if (settings.zipcode) {
log.debug "ZipCode: ${settings.zipcode}"
weather = getWeatherFeature("conditions", settings.zipcode)
// Check if the variable is populated, otherwise return.
if (!weather) {
log.debug("Something went wrong, no data found.")
return false
}
def locationScale = getTemperatureScale()
def tempToSend = (locationScale == "C") ? weather.current_observation.temp_c : weather.current_observation.temp_f
log.debug("Outdoor Temperature: ${tempToSend} ${locationScale}")
// Right now this can disrupt device health if the device is
// currently offline -- it would be erroneously marked online.
//sendEvent( name: 'outsideTemp', value: tempToSend )
setOutdoorTemperature(tempToSend)
}
}
def scheduledUpdateWeather() {
def actions = updateWeather()
if (actions) {
sendHubCommand(actions)
}
}
def updateOperatingState() {
sendHubCommand(zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_PI_HEATING_STATE))
}
/**
* PING is used by Device-Watch in attempt to reach the Device
**/
def ping() {
log.debug "ping()"
zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_LOCAL_TEMP)
}
def poll() {
def requests = []
log.debug "poll()"
requests += updateWeather()
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_LOCAL_TEMP)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_PI_HEATING_STATE)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_HEAT_SETPOINT)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_SYSTEM_MODE)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_SETPOINT_MODE, ["mfgCode": "0x1185"])
requests += zigbee.readAttribute(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_TEMP_DISP_MODE)
requests += zigbee.readAttribute(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_KEYPAD_LOCKOUT)
requests
}
/**
* Given a raw temperature reading in Celsius return a converted temperature.
*
* @param value The temperature in Celsius, treated based on the following:
* If value instanceof String, treat as a raw hex string and divide by 100
* Otherwise treat value as a number and divide by 100
*
* @return A Celsius or Farenheit value
*/
def getTemperature(value) {
if (value != null) {
log.debug("value $value")
def celsius = (value instanceof String ? Integer.parseInt(value, 16) : value) / 100
if (getTemperatureScale() == "C") {
return celsius
} else {
def rounded = new BigDecimal(celsiusToFahrenheit(celsius)).setScale(0, BigDecimal.ROUND_HALF_UP)
return rounded
}
}
}
def refresh() {
poll()
}
def setHeatingSetpoint(preciseDegrees) {
if (preciseDegrees != null) {
def temperatureScale = getTemperatureScale()
float minSetpoint = thermostatSetpointRange[minSetpointIndex]
float maxSetpoint = thermostatSetpointRange[maxSetpointIndex]
if (preciseDegrees >= minSetpoint && preciseDegrees <= maxSetpoint) {
def degrees = new BigDecimal(preciseDegrees).setScale(1, BigDecimal.ROUND_HALF_UP)
def celsius = (getTemperatureScale() == "C") ? degrees : (fahrenheitToCelsius(degrees) as Float).round(2)
log.debug "setHeatingSetpoint({$degrees} ${temperatureScale})"
zigbee.writeAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_HEAT_SETPOINT, DataType.INT16, zigbee.convertToHexString(celsius * 100, 4)) +
zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_HEAT_SETPOINT) +
zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_PI_HEATING_STATE)
} else {
log.debug "heatingSetpoint $preciseDegrees out of range! (supported: $minSetpoint - $maxSetpoint ${getTemperatureScale()})"
}
}
}
// Maintain backward compatibility with self published versions of the "Stelpro Get Remote Temperature" SmartApp
def quickSetOutTemp(outsideTemp) {
setOutdoorTemperature(outsideTemp)
}
def setOutdoorTemperature(outsideTemp) {
def degrees = outsideTemp as Double
Integer tempToSend
def celsius = (getTemperatureScale() == "C") ? degrees : (fahrenheitToCelsius(degrees) as Float).round(2)
if (celsius < 0) {
tempToSend = (celsius*100) + 65536
} else {
tempToSend = (celsius*100)
}
// The thermostat expects the byte order to be a little different than we send usually
zigbee.writeAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_OUT_TEMP, DataType.INT16, zigbee.swapEndianHex(zigbee.convertToHexString(tempToSend, 4)), ["mfgCode": "0x1185"])
}
def increaseHeatSetpoint() {
def currentMode = device.currentState("thermostatMode")?.value
if (currentMode != "off") {
float currentSetpoint = device.currentValue("heatingSetpoint")
currentSetpoint = currentSetpoint + setpointStep
setHeatingSetpoint(currentSetpoint)
}
}
def decreaseHeatSetpoint() {
def currentMode = device.currentState("thermostatMode")?.value
if (currentMode != "off") {
float currentSetpoint = device.currentValue("heatingSetpoint")
currentSetpoint = currentSetpoint - setpointStep
setHeatingSetpoint(currentSetpoint)
}
}
def setThermostatMode(value) {
log.debug "setThermostatMode({$value})"
if (supportedThermostatModes.contains(value)) {
def currentMode = device.currentState("thermostatMode")?.value
def modeNumber;
Integer setpointModeNumber;
if (value == "heat") {
modeNumber = 04
setpointModeNumber = 04
} else if (value == "eco") {
modeNumber = 04
setpointModeNumber = 05
} else {
modeNumber = 00
setpointModeNumber = 00
}
zigbee.writeAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_SYSTEM_MODE, DataType.ENUM8, modeNumber) +
zigbee.writeAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_SETPOINT_MODE, DataType.ENUM8, setpointModeNumber, ["mfgCode": "0x1185"]) +
poll()
} else {
log.debug "Invalid thermostat mode $value"
}
}
def off() {
log.debug "off"
setThermostatMode("off")
}
def heat() {
log.debug "heat"
setThermostatMode("heat")
}
def eco() {
log.debug "eco"
setThermostatMode("eco")
}
def configure() {
def requests = []
log.debug "binding to Thermostat cluster"
unschedule(scheduledUpdateWeather)
if (settings.zipcode) {
requests += updateWeather()
runEvery1Hour(scheduledUpdateWeather)
}
requests += zigbee.addBinding(THERMOSTAT_CLUSTER)
// Configure Thermostat Cluster
requests += zigbee.configureReporting(THERMOSTAT_CLUSTER, ATTRIBUTE_LOCAL_TEMP, DataType.INT16, 10, 60, 50)
requests += zigbee.configureReporting(THERMOSTAT_CLUSTER, ATTRIBUTE_HEAT_SETPOINT, DataType.INT16, 1, 0, 50)
requests += zigbee.configureReporting(THERMOSTAT_CLUSTER, ATTRIBUTE_SYSTEM_MODE, DataType.ENUM8, 1, 0, 1)
requests += zigbee.configureReporting(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_SETPOINT_MODE, DataType.ENUM8, 1, 0, 1)
requests += zigbee.configureReporting(THERMOSTAT_CLUSTER, ATTRIBUTE_PI_HEATING_STATE, DataType.UINT8, 1, 900, 1)
// Configure Thermostat Ui Conf Cluster
requests += zigbee.configureReporting(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_TEMP_DISP_MODE, DataType.ENUM8, 1, 0, 1)
requests += zigbee.configureReporting(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_KEYPAD_LOCKOUT, DataType.ENUM8, 1, 0, 1)
// Read the configured variables
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_LOCAL_TEMP)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_HEAT_SETPOINT)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_SYSTEM_MODE)
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_MFR_SPEC_SETPOINT_MODE, ["mfgCode": "0x1185"])
requests += zigbee.readAttribute(THERMOSTAT_CLUSTER, ATTRIBUTE_PI_HEATING_STATE)
requests += zigbee.readAttribute(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_TEMP_DISP_MODE)
requests += zigbee.readAttribute(THERMOSTAT_UI_CONFIG_CLUSTER, ATTRIBUTE_KEYPAD_LOCKOUT)
requests
}
// Unused Thermostat Capability commands
def emergencyHeat() {
log.debug "${device.displayName} does not support emergency heat mode"
}
def cool() {
log.debug "${device.displayName} does not support cool mode"
}
def setCoolingSetpoint(degrees) {
log.debug "${device.displayName} does not support cool setpoint"
}
def on() {
heat()
}
def setThermostatFanMode(value) {
log.debug "${device.displayName} does not support $value"
}
def fanOn() {
log.debug "${device.displayName} does not support fan on"
}
def auto() {
fanAuto()
}
def fanAuto() {
log.debug "${device.displayName} does not support fan auto"
}
/**
* Checks if the time elapsed from the provided timestamp is greater than the number of senconds provided
*
* @param timestamp: The timestamp
*
* @param seconds: The number of seconds
*
* @returns true if elapsed time is greater than number of seconds provided, else false
*/
private Boolean secondsPast(timestamp, seconds) {
if (!(timestamp instanceof Number)) {
if (timestamp instanceof Date) {
timestamp = timestamp.time
} else if ((timestamp instanceof String) && timestamp.isNumber()) {
timestamp = timestamp.toLong()
} else {
return true
}
}
return (now() - timestamp) > (seconds * 1000)
}