Update thermostat-mode-director.groovy
[smartapps.git] / official / keep-me-cozy.groovy
1 /**
2  *  Copyright 2015 SmartThings
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  *  in compliance with the License. You may obtain a copy of the License at:
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11  *  for the specific language governing permissions and limitations under the License.
12  *
13  *  Keep Me Cozy
14  *
15  *  Author: SmartThings
16  */
17 definition(
18     name: "Keep Me Cozy",
19     namespace: "smartthings",
20     author: "SmartThings",
21     description: "Changes your thermostat settings automatically in response to a mode change.  Often used with Bon Voyage, Rise and Shine, and other Mode Magic SmartApps to automatically keep you comfortable while you're present and save you energy and money while you are away.",
22     category: "Green Living",
23     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo.png",
24     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo@2x.png"
25 )
26
27 preferences {
28         section("Choose thermostat... ") {
29                 input "thermostat", "capability.thermostat"
30         }
31         section("Heat setting...") {
32                 input "heatingSetpoint", "number", title: "Degrees?"
33         }
34         section("Air conditioning setting..."){
35                 input "coolingSetpoint", "number", title: "Degrees?"
36         }
37 }
38
39 def installed()
40 {
41         subscribe(thermostat, "heatingSetpoint", heatingSetpointHandler)
42         subscribe(thermostat, "coolingSetpoint", coolingSetpointHandler)
43         subscribe(thermostat, "temperature", temperatureHandler)
44         subscribe(location, changedLocationMode)
45         subscribe(app, appTouch)
46 }
47
48 def updated()
49 {
50         unsubscribe()
51         subscribe(thermostat, "heatingSetpoint", heatingSetpointHandler)
52         subscribe(thermostat, "coolingSetpoint", coolingSetpointHandler)
53         subscribe(thermostat, "temperature", temperatureHandler)
54         subscribe(location, changedLocationMode)
55         subscribe(app, appTouch)
56 }
57
58 def heatingSetpointHandler(evt)
59 {
60         log.debug "heatingSetpoint: $evt, $settings"
61 }
62
63 def coolingSetpointHandler(evt)
64 {
65         log.debug "coolingSetpoint: $evt, $settings"
66 }
67
68 def temperatureHandler(evt)
69 {
70         log.debug "currentTemperature: $evt, $settings"
71 }
72
73 def changedLocationMode(evt)
74 {
75         log.debug "changedLocationMode: $evt, $settings"
76
77         thermostat.setHeatingSetpoint(heatingSetpoint)
78         thermostat.setCoolingSetpoint(coolingSetpoint)
79         //thermostat.poll()
80 }
81
82 def appTouch(evt)
83 {
84         log.debug "appTouch: $evt, $settings"
85
86         thermostat.setHeatingSetpoint(heatingSetpoint)
87         thermostat.setCoolingSetpoint(coolingSetpoint)
88         //thermostat.poll()
89 }
90
91 // catchall
92 def event(evt)
93 {
94         log.debug "value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}"
95 }