-
Notifications
You must be signed in to change notification settings - Fork 10
/
whole-house-fan.sa.groovy
95 lines (78 loc) · 2.85 KB
/
whole-house-fan.sa.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
/**
* Whole House Fan
*
* Copyright 2014 Brian Steere
*
* 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.
*
*/
definition(
name: "Whole House Fan",
namespace: "dianoga",
author: "Brian Steere",
description: "Toggle a whole house fan (switch) when: Outside is cooler than inside, Inside is above x temp, Thermostat is off",
category: "Green Living",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/whole-house-fan.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/whole-house-fan%402x.png"
)
preferences {
section("Outdoor") {
input "outTemp", "capability.temperatureMeasurement", title: "Outdoor Thermometer"
}
section("Indoor") {
input "inTemp", "capability.temperatureMeasurement", title: "Indoor Thermometer"
input "minTemp", "number", title: "Minimum Indoor Temperature"
input "fans", "capability.switch", title: "Vent Fan", multiple: true
}
section("Thermostat") {
input "thermostat", "capability.thermostat", title: "Thermostat"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
state.fanRunning = false;
subscribe(outTemp, "temperature", "checkThings");
subscribe(inTemp, "temperature", "checkThings");
subscribe(thermostat, "thermostatMode", "checkThings");
}
def checkThings(evt) {
def outsideTemp = settings.outTemp.currentValue('temperature')
def insideTemp = settings.inTemp.currentValue('temperature')
def thermostatMode = settings.thermostat.currentValue('thermostatMode')
log.debug "Inside: $insideTemp, Outside: $outsideTemp, Thermostat: $thermostatMode"
def shouldRun = true;
if(thermostatMode != 'off') {
log.debug "Not running due to thermostat mode"
shouldRun = false;
}
if(insideTemp < outsideTemp) {
log.debug "Not running due to insideTemp > outdoorTemp"
shouldRun = false;
}
if(insideTemp < settings.minTemp) {
log.debug "Not running due to insideTemp < minTemp"
shouldRun = false;
}
if(shouldRun && !state.fanRunning) {
fans.on();
state.fanRunning = true;
} else if(!shouldRun && state.fanRunning) {
fans.off();
state.fanRunning = false;
}
}