4 * Author: dianoga7@3dgo.net
8 // Automatically generated. Make future change here.
10 name: "Thermostat Auto Off",
12 author: "dianoga7@3dgo.net",
13 description: "Automatically turn off thermostat when windows/doors open. Turn it back on when everything is closed up.",
14 category: "Green Living",
15 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
16 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png",
22 input("thermostat", "capability.thermostat", title: "Thermostat")
25 section("Open/Close") {
26 input("sensors", "capability.contactSensor", title: "Sensors", multiple: true)
27 input("delay", "number", title: "Delay (seconds) before turning thermostat off")
32 log.debug "Installed with settings: ${settings}"
38 log.debug "Updated with settings: ${settings}"
47 //subscribe(sensors, 'contact', "sensorChange")
48 subscribe(sensors, "contact", sensorChange)
51 def sensorChange(evt) {
52 log.debug "Desc: $evt.value , $state"
53 if(evt.value == 'open' && !state.changed) {
54 log.debug "Scheduling turn off in $delay seconds"
55 state.scheduled = true;
56 runIn(delay, 'turnOff')
57 } else if(evt.value == 'closed' && (state.changed || state.scheduled)) {
59 log.debug "Everything is closed, restoring thermostat"
60 state.scheduled = false;
64 log.debug "Something is still open."
70 def result = sensors.find() { it.currentValue('contact') == 'open'; }
71 log.debug "isOpen results: $result"
77 log.debug "Preparing to turn off thermostat due to contact open"
79 log.debug "It's safe. Turning it off."
80 state.thermostatMode = thermostat.currentValue("thermostatMode")
83 log.debug "State: $state"
85 log.debug "Just kidding. The platform did something bad."
90 log.debug "Setting thermostat to $state.thermostatMode"
91 thermostat.setThermostatMode(state.thermostatMode)