forked from iakoubtchik/Quirky-Connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuirky-Aros-Device.groovy
379 lines (326 loc) · 11.6 KB
/
Quirky-Aros-Device.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
/**
* Quirky-Aros
*
* Copyright 2014 Todd Wackford
*
* 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.
*
*****************************************************************
* Changes
*****************************************************************
*
* Change 1: 2014-05-19 (wackford)
* Initial Build
*
* Change 2: 2014-5-20 (twackford)
* Added functionality to have mode auto_eco upon up/down setpoint button press
*
* Change 3: 2014-6-5 (twackford)
* Multiple bug fixes after initial QA
*
*
*****************************************************************
* Code
*****************************************************************
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "Quirky Aros", namespace: "wackford", author: "[email protected]", oauth: true) {
capability "Switch"
capability "Temperature Measurement"
capability "Refresh"
capability "Thermostat"
capability "Configuration"
capability "Polling"
attribute "coolingSetpoint", "string"
attribute "mode", "string"
attribute "fanMode", "string"
command "coolLevelUp"
command "coolLevelDown"
command "switchMode"
command "switchFanMode"
command "auto_eco"
command "fan_only"
command "cool_only"
command "fanLow"
command "fanMed"
command "fanHigh"
}
// simulator metadata
simulator {
}
tiles {
valueTile("temperature", "device.temperature", width: 2, height: 2) {
state("temperature", label:'${currentValue}°', unit:'',
backgroundColors:[
[value: 31, 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("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "off", label: "Aros Off", action: "switch.on", icon: "st.custom.quirky.quirky-device", backgroundColor: "#ffffff"
state "on", label: "Aros On", action: "switch.off", icon: "st.custom.quirky.quirky-device", backgroundColor: "#79b821"
}
standardTile("mode", "device.mode", inactiveLabel: false, decoration: "flat") {
state "cool_only", label:"Cool", action:"switchMode", icon:"st.Weather.weather7"
state "auto_eco", label:"Eco", action:"switchMode", icon:"st.Weather.weather7"
state "fan_only", label:"Fan", action:"switchMode", icon:"st.Weather.weather7"
}
standardTile("fanMode", "device.fanMode", inactiveLabel: false, decoration: "flat") {
state "fanLow", label:"Low", action:"switchFanMode", icon:"st.Appliances.appliances11"
state "fanMed", label:"Med", action:"switchFanMode", icon:"st.Appliances.appliances11"
state "fanHigh", label:"High", action:"switchFanMode", icon:"st.Appliances.appliances11"
}
valueTile("coolingSetpoint", "device.coolingSetpoint", inactiveLabel: false, decoration: "flat") {
state "coolingSetpoint", label:'${currentValue}° Set', unit:"", backgroundColor:"#ffffff"
}
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, decoration: "flat") {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("coolLevelUp", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false, decoration: "flat") {
state "coolLevelUp", action:"coolLevelUp", backgroundColor:"#d04e00", icon:"st.thermostat.thermostat-up"
}
standardTile("coolLevelDown", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false, decoration: "flat") {
state "coolLevelDown", action:"coolLevelDown", backgroundColor: "#1e9cbb", icon:"st.thermostat.thermostat-down"
}
main "temperature"
details(["temperature", "mode", "fanMode", "coolLevelDown", "coolingSetpoint", "coolLevelUp", "switch", "refresh"])
}
}
def parse(description) {
log.debug "parse() - $description"
def results = []
if ( description == "updated" )
return //nothing here interesting
if (description?.name && description?.value)
{
results << sendEvent(name: "${description?.name}", value: "${description?.value}")
}
}
def coolLevelUp(){
if ( device.currentValue("switch") == "off" ) {
log.debug "user tapped a tile while aros was off, we'll turn it on for them"
delayBetween([
on(),
switchToMode("auto_eco")
])
}
if ( device.currentValue("mode") == "fan_only" ) { // wink doesn;'t let us change this in fan_only mode
log.debug "we're in fan_ony mode, ignoring coolingSetPoint adjustment"
return
}
def locationScale = getTemperatureScale()
def nextLevel = null
if ( locationScale == "F" ) {
state.setPoint = state.setPoint ?: 64 // this is kinda wierd the first time after install. then ok
nextLevel = state.setPoint + 1
if( nextLevel > 86){
nextLevel = 86 //Aros max value in F for set point
}
} else {
state.setPoint = state.setPoint ?: 17 // this is kinda wierd the first time after install. then ok
nextLevel = state.setPoint + 1
if( nextLevel > 30){
nextLevel = 30 //Aros max value in C for set point
}
}
state.setPoint = nextLevel
log.debug "Setting cool set point up to: ${nextLevel}"
coolingSetpoint(nextLevel)
}
def coolLevelDown(){
if ( device.currentValue("switch") == "off" ) {
log.debug "user tapped a tile while aros was off, we'll turn it on for them"
delayBetween([
on(), // user tapped a tile while aros was off, we'll turn iton for them
switchToMode("auto_eco")
])
}
if ( device.currentValue("mode") == "fan_only" ) { // wink doesn;'t let us change this in fan_only mode
log.debug "we're in fan_ony mode, ignoring coolingSetPoint adjustment"
return
}
def locationScale = getTemperatureScale()
def nextLevel = null
if ( locationScale == "F" ) {
state.setPoint = state.setPoint ?: 86 // this is kinda wierd the first time after install. then ok
nextLevel = state.setPoint - 1
if( nextLevel < 64){
nextLevel = 64 //Aros min value in F for set point
}
} else {
state.setPoint = state.setPoint ?: 30 // this is kinda wierd the first time after install. then ok
nextLevel = state.setPoint - 1
if( nextLevel < 17){
nextLevel = 17 //Aros min value in C for set point
}
}
state.setPoint = nextLevel
log.debug "Setting cool set point down to: ${nextLevel}"
coolingSetpoint(nextLevel)
}
def coolingSetpoint(degrees) {
log.debug "in method coolingSetpoint with degrees = ${degrees}"
def locationScale = getTemperatureScale()
degrees = degrees as double
def deviceValue = degrees
if (locationScale == "F")
deviceValue = fahrenheitToCelsius(degrees)
degrees = degrees.trunc(2)
sendEvent(name: coolingSetpoint, value: degrees)
parent.arosCoolingSetpoint(this, ["max_set_point": deviceValue])
}
def setCoolingSetpoint(degrees) {
coolingSetpoint(degrees)
}
def setHeatingSetpoint(degrees) {
log.debug "The Aros has no heater, but we have a dummy method to act like a thermostat"
}
def modes() {
["cool_only", "auto_eco", "fan_only"]
}
def fanModes() {
["fanLow", "fanMed", "fanHigh"]
}
def switchMode() {
if ( device.currentValue("switch") == "off" )
on() // user tapped a tile while aros was off, we'll turn iton for them
def currentMode = device.currentState("thermostatMode")?.value
def lastTriedMode = getDataByName("lastTriedMode") ?: currentMode ?: "off"
def supportedModes = getDataByName("supportedModes")
def modeOrder = modes()
def next = { modeOrder[modeOrder.indexOf(it) + 1] ?: modeOrder[0] }
def nextMode = next(lastTriedMode)
if (supportedModes?.contains(currentMode)) {
while (!supportedModes.contains(nextMode) && nextMode != "off") {
nextMode = next(nextMode)
}
}
log.debug "Switching to mode: ${nextMode}"
switchToMode(nextMode)
}
def switchToMode(nextMode) {
def supportedModes = getDataByName("supportedModes")
if(supportedModes && !supportedModes.contains(nextMode)) log.warn "thermostat mode '$nextMode' is not supported"
if (nextMode in modes()) {
updateState("lastTriedMode", nextMode)
return "$nextMode"()
} else {
log.debug("no mode method '$nextMode'")
}
}
def switchFanMode() {
if ( device.currentValue("switch") == "off" ) {
log.debug "user tapped a tile while aros was off, we'll turn it on for them"
on()
}
def currentMode = device.currentState("thermostatFanMode")?.value
def lastTriedMode = getDataByName("lastTriedFanMode") ?: currentMode ?: "off"
def supportedModes = getDataByName("supportedFanModes") ?: "fanLow fanMed fanHigh"
def modeOrder = fanModes()
def next = { modeOrder[modeOrder.indexOf(it) + 1] ?: modeOrder[0] }
def nextMode = next(lastTriedMode)
while (!supportedModes?.contains(nextMode) && nextMode != "fanAuto") {
nextMode = next(nextMode)
}
switchToFanMode(nextMode)
}
def switchToFanMode(nextMode) {
def supportedFanModes = getDataByName("supportedFanModes")
if(supportedFanModes && !supportedFanModes.contains(nextMode)) log.warn "thermostat mode '$nextMode' is not supported"
if (nextMode in fanModes()) {
updateState("lastTriedFanMode", nextMode)
return "$nextMode"()
} else {
log.debug("no fanMode method '$nextMode'")
}
}
def updateState(String name, String value) {
state[name] = value
device.updateDataValue(name, value)
}
def getDataByName(String name) {
state[name] ?: device.getDataValue(name)
}
def fanLow() {
log.debug "Executing ${[fan_speed: "Low"]}"
delayBetween([
parent.arosFanSpeed(this, [fan_speed: 0.333]),
sendEvent(name: "fanMode", value: "fanLow")
])
}
def fanMed() {
log.debug "Executing ${[fan_speed: "Med"]}"
delayBetween([
parent.arosFanSpeed(this, [fan_speed: 0.666]),
sendEvent(name: "fanMode", value: "fanMed")
])
}
def fanHigh() {
log.debug "Executing ${[fan_speed: "High"]}"
delayBetween([
parent.arosFanSpeed(this, [fan_speed: 0.999]),
sendEvent(name: "fanMode", value: "fanHigh")
])
}
def cool_only() {
log.debug "Executing ${[mode: cool_only]}"
delayBetween([
parent.arosMode(this, "cool_only"),
sendEvent(name: "mode", value: "cool_only")
])
}
def auto_eco() {
log.debug "Executing ${[mode: auto_eco]}"
delayBetween([
parent.arosMode(this, "auto_eco"),
sendEvent(name: "mode", value: "auto_eco")
])
}
def fan_only() {
log.debug "Executing ${[mode: fan_only]}"
delayBetween([
parent.arosMode(this, "fan_only"),
sendEvent(name: "mode", value: "fan_only")
])
}
def on() {
log.debug "Executing 'on'"
//log.debug this
delayBetween([
parent.arosOn(this),
sendEvent(name: "switch", value: "on")
])
}
def off() {
log.debug "Executing 'off'"
delayBetween([
parent.arosOff(this),
sendEvent(name: "switch", value: "off")
])
}
def uninstalled() {
log.debug "Executing 'uninstall' in child"
parent.uninstallChildDevice(this)
}
def poll() {
log.debug "Executing 'poll'"
parent.pollAros(this)
}
def refresh() {
log.debug "Executing 'refresh'"
parent.pollAros(this)
}