2 * Thermostat Window Check
4 * Author: brian@bevey.org
7 * If your heating or cooling system come on, it gives you notice if there are
8 * any windows or doors left open, preventing the system from working
13 name: "Thermostat Window Check",
14 namespace: "imbrianj",
15 author: "brian@bevey.org",
16 description: "If your heating or cooling system come on, it gives you notice if there are any windows or doors left open, preventing the system from working optimally.",
17 category: "Green Living",
18 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
19 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
23 section("Things to check?") {
24 input "sensors", "capability.contactSensor", multiple: true
27 section("Thermostats to monitor") {
28 input "thermostats", "capability.thermostat", multiple: true
31 section("Notifications") {
32 input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required: false
33 input "phone", "phone", title: "Send a Text Message?", required: false
36 section("Turn thermostat off automatically?") {
37 input "turnOffTherm", "enum", metadata: [values: ["Yes", "No"]], required: false
40 section("Delay to wait before turning thermostat off (defaults to 1 minute)") {
41 input "turnOffDelay", "decimal", title: "Number of minutes", required: false
46 subscribe(thermostats, "thermostatMode", thermoChange);
47 subscribe(sensors, "contact.open", windowChange);
52 subscribe(thermostats, "thermostatMode", thermoChange);
53 subscribe(sensors, "contact.open", windowChange);
56 def thermoChange(evt) {
57 if(evt.value == "heat" ||
58 evt.value == "cool") {
59 def open = sensors.findAll { it?.latestValue("contact") == "open" }
62 def plural = open.size() > 1 ? "are" : "is"
63 send("${open.join(', ')} ${plural} still open and the thermostat just came on.")
65 thermoShutOffTrigger()
69 log.info("Thermostat came on and nothing is open.");
74 // These should have been global variables
78 def windowChange(evt) {
79 heating = thermostats.findAll { it?.latestValue("thermostatMode") == "heat" }
80 cooling = thermostats.findAll { it?.latestValue("thermostatMode") == "cool" }
82 if(heating || cooling) {
83 def open = sensors.findAll { it?.latestValue("contact") == "open" }
84 def tempDirection = heating ? "heating" : "cooling"
85 def plural = open.size() > 1 ? "were" : "was"
86 send("${open.join(', ')} ${plural} opened and the thermostat is still ${tempDirection}.")
88 thermoShutOffTrigger()
92 def thermoShutOffTrigger() {
93 if(turnOffTherm == "Yes") {
94 log.info("Starting timer to turn off thermostat")
95 def delay = (turnOffDelay != null && turnOffDelay != "") ? turnOffDelay * 60 : 60
96 state.turnOffTime = now()
98 runIn(delay, "thermoShutOff")
102 def thermoShutOff() {
103 def open = sensors.findAll { it?.latestValue("contact") == "open" }
104 def tempDirection = heating ? "heating" : "cooling"
105 def plural = open.size() > 1 ? "are" : "is"
107 log.info("Checking if we need to turn thermostats off")
110 send("Thermostats turned off: ${open.join(', ')} ${plural} open and thermostats ${tempDirection}.")
111 log.info("Windows still open, turning thermostats off")
116 log.info("Looks like everything is shut now - no need to turn off thermostats")
121 if(sendPushMessage != "No") {
122 log.debug("Sending push message")
127 log.debug("Sending text message")