2 * Copyright 2015 SmartThings
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 name: "Keep Me Cozy II",
20 namespace: "smartthings",
21 author: "SmartThings",
22 description: "Works the same as Keep Me Cozy, but enables you to pick an alternative temperature sensor in a separate space from the thermostat. Focuses on making you comfortable where you are spending your time rather than where the thermostat is located.",
23 category: "Green Living",
24 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo.png",
25 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo@2x.png"
29 section("Choose thermostat... ") {
30 input "thermostat", "capability.thermostat"
32 section("Heat setting..." ) {
33 input "heatingSetpoint", "decimal", title: "Degrees"
35 section("Air conditioning setting...") {
36 input "coolingSetpoint", "decimal", title: "Degrees"
38 section("Optionally choose temperature sensor to use instead of the thermostat's... ") {
39 input "sensor", "capability.temperatureMeasurement", title: "Temp Sensors", required: false
45 log.debug "enter installed, state: $state"
51 log.debug "enter updated, state: $state"
56 def subscribeToEvents()
58 subscribe(location, changedLocationMode)
60 subscribe(sensor, "temperature", temperatureHandler)
61 subscribe(thermostat, "temperature", temperatureHandler)
62 subscribe(thermostat, "thermostatMode", temperatureHandler)
67 def changedLocationMode(evt)
69 log.debug "changedLocationMode mode: $evt.value, heat: $heatingSetpoint, cool: $coolingSetpoint"
73 def temperatureHandler(evt)
82 def tm = thermostat.currentThermostatMode
83 def ct = thermostat.currentTemperature
84 def currentTemp = sensor.currentTemperature
85 log.trace("evaluate:, mode: $tm -- temp: $ct, heat: $thermostat.currentHeatingSetpoint, cool: $thermostat.currentCoolingSetpoint -- " +
86 "sensor: $currentTemp, heat: $heatingSetpoint, cool: $coolingSetpoint")
87 if (tm in ["cool","auto"]) {
89 if (currentTemp - coolingSetpoint >= threshold) {
90 thermostat.setCoolingSetpoint(ct - 2)
91 log.debug "thermostat.setCoolingSetpoint(${ct - 2}), ON"
93 else if (coolingSetpoint - currentTemp >= threshold && ct - thermostat.currentCoolingSetpoint >= threshold) {
94 thermostat.setCoolingSetpoint(ct + 2)
95 log.debug "thermostat.setCoolingSetpoint(${ct + 2}), OFF"
98 if (tm in ["heat","emergency heat","auto"]) {
100 if (heatingSetpoint - currentTemp >= threshold) {
101 thermostat.setHeatingSetpoint(ct + 2)
102 log.debug "thermostat.setHeatingSetpoint(${ct + 2}), ON"
104 else if (currentTemp - heatingSetpoint >= threshold && thermostat.currentHeatingSetpoint - ct >= threshold) {
105 thermostat.setHeatingSetpoint(ct - 2)
106 log.debug "thermostat.setHeatingSetpoint(${ct - 2}), OFF"
111 thermostat.setHeatingSetpoint(heatingSetpoint)
112 thermostat.setCoolingSetpoint(coolingSetpoint)
117 // for backward compatibility with existing subscriptions
118 def coolingSetpointHandler(evt) {
119 log.debug "coolingSetpointHandler()"
121 def heatingSetpointHandler (evt) {
122 log.debug "heatingSetpointHandler ()"