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 def windowChange(evt) {
75 def heating = thermostats.findAll { it?.latestValue("thermostatMode") == "heat" }
76 def cooling = thermostats.findAll { it?.latestValue("thermostatMode") == "cool" }
78 if(heating || cooling) {
79 def open = sensors.findAll { it?.latestValue("contact") == "open" }
80 def tempDirection = heating ? "heating" : "cooling"
81 def plural = open.size() > 1 ? "were" : "was"
82 send("${open.join(', ')} ${plural} opened and the thermostat is still ${tempDirection}.")
84 thermoShutOffTrigger()
88 def thermoShutOffTrigger() {
89 if(turnOffTherm == "Yes") {
90 log.info("Starting timer to turn off thermostat")
91 def delay = (turnOffDelay != null && turnOffDelay != "") ? turnOffDelay * 60 : 60
92 state.turnOffTime = now()
94 runIn(delay, "thermoShutOff")
99 def open = sensors.findAll { it?.latestValue("contact") == "open" }
100 def tempDirection = heating ? "heating" : "cooling"
101 def plural = open.size() > 1 ? "are" : "is"
103 log.info("Checking if we need to turn thermostats off")
106 send("Thermostats turned off: ${open.join(', ')} ${plural} open and thermostats ${tempDirection}.")
107 log.info("Windows still open, turning thermostats off")
112 log.info("Looks like everything is shut now - no need to turn off thermostats")
117 if(sendPushMessage != "No") {
118 log.debug("Sending push message")
123 log.debug("Sending text message")