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)
50 def sensorChange(evt) {
51 log.debug "Desc: $evt.value , $state"
52 if(evt.value == 'open' && !state.changed) {
53 log.debug "Scheduling turn off in $delay seconds"
54 state.scheduled = true;
55 runIn(delay, 'turnOff')
56 } else if(evt.value == 'closed' && (state.changed || state.scheduled)) {
58 log.debug "Everything is closed, restoring thermostat"
59 state.scheduled = false;
63 log.debug "Something is still open."
69 def result = sensors.find() { it.currentValue('contact') == 'open'; }
70 log.debug "isOpen results: $result"
76 log.debug "Preparing to turn off thermostat due to contact open"
78 log.debug "It's safe. Turning it off."
79 state.thermostatMode = thermostat.currentValue("thermostatMode")
82 log.debug "State: $state"
84 log.debug "Just kidding. The platform did something bad."
89 log.debug "Setting thermostat to $state.thermostatMode"
90 thermostat.setThermostatMode(state.thermostatMode)