-
Notifications
You must be signed in to change notification settings - Fork 4
/
Code
66 lines (53 loc) · 1.58 KB
/
Code
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
/**
* Even the temperature
*
* Author: [email protected]
* Date: 2014-01-11
*/
preferences {
section("When the temperature difference is too high") {
input "temperatureSensors", "capability.temperatureMeasurement ", title: "Where?", multiple: true, required: true
}
section("By a difference of") {
input "difference", "decimal", title: "Degrees", required: true
}
section("Turn the fan on") {
input "thermostat", "capability.thermostat", title: "Where?", multiple: false, required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(temperatureSensors, "temperature", executeCheck)
subscribe(thermostat, "temperature", executeCheck)
temperatureCheck()
}
def executeCheck(evt) {
temperatureCheck()
}
def temperatureCheck() {
def turnOffFan = "True"
def actualDifference
for (sensor in temperatureSensors) {
if ((sensor.currentTemperature - thermostat.currentTemperature) >= difference) {
log.debug "Turning on fan"
thermostat.setThermostatFanMode("on")
turnOffFan = "False"
} else if ((thermostat.currentTemperature - sensor.currentTemperature) >= difference) {
log.debug "Turning on fan"
thermostat.setThermostatFanMode("on")
turnOffFan = "False"
}
}
if (turnOffFan == "True") {
thermostat.setThermostatFanMode("auto")
log.debug "Turning off fan"
}
}