Keep My Cozy with Interlock


#1

Can someone help me with the code for Keep Me Cozy? I want to be able to only let the program run if a switch is on. ie: “Thermostat Override” -A virtual switch I created. I want to get rid of the mode feature and replace it with the ability to app a switch to enable/disable.

when it is extremely hot out “keep me cozy II” works great since the thermostat is on the 1st floor and I use the sensor on the 2nd floor. when the temperatures are a little nice I want to use the normal thermostat. I find myself constantly deleting and adding Keep Me Cozy II. when in reality I just want to disable it with a simple switch. Here is the code. or GitHub Mcodding / CoddingSmartApps (KeepMeCozyInterlock)

preferences() {

section("Choose thermostat...") {

	input "thermostat", "capability.thermostat"

}

section("Heat setting..." ) {

	input "heatingSetpoint", "decimal", title: "Degrees"

}

section("Air conditioning setting...") {

	input "coolingSetpoint", "decimal", title: "Degrees"

}

section("Optionally choose temperature sensor to use instead of the thermostat's...") {

	input "sensor", "capability.temperatureMeasurement", title: "Temp Sensors", required: false

}

}

def installed()

{

log.debug "enter installed, state: $state"

subscribeToEvents()

}

def updated()

{

log.debug "enter updated, state: $state"

unsubscribe()

subscribeToEvents()

}

def subscribeToEvents()

{

subscribe(location, changedLocationMode)

if (sensor) {

	subscribe(sensor, "temperature", temperatureHandler)

	subscribe(thermostat, "temperature", temperatureHandler)

	subscribe(thermostat, "thermostatMode", temperatureHandler)

}

evaluate()

}

def changedLocationMode(evt)

{

log.debug "changedLocationMode mode: $evt.value, heat: $heat, cool: $cool"

evaluate()

}

def temperatureHandler(evt)

{

evaluate()

}

private evaluate()

{

if (sensor) {

	def threshold = 1.0

	def tm = thermostat.currentThermostatMode

	def ct = thermostat.currentTemperature

	def currentTemp = sensor.currentTemperature

	log.trace("evaluate:, mode: $tm -- temp: $ct, heat: $thermostat.currentHeatingSetpoint, cool: $thermostat.currentCoolingSetpoint -- "  +

		"sensor: $currentTemp, heat: $heatingSetpoint, cool: $coolingSetpoint")

	if (tm in ["cool","auto"]) {

		// air conditioner

		if (currentTemp - coolingSetpoint >= threshold) {

			thermostat.setCoolingSetpoint(ct - 2)

			log.debug "thermostat.setCoolingSetpoint(${ct - 2}), ON"

		}

		else if (coolingSetpoint - currentTemp >= threshold && ct - thermostat.currentCoolingSetpoint >= threshold) {

			thermostat.setCoolingSetpoint(ct + 2)

			log.debug "thermostat.setCoolingSetpoint(${ct + 2}), OFF"

		}

	}

	if (tm in ["heat","emergency heat","auto"]) {

		// heater

		if (heatingSetpoint - currentTemp >= threshold) {

			thermostat.setHeatingSetpoint(ct + 2)

			log.debug "thermostat.setHeatingSetpoint(${ct + 2}), ON"

		}

		else if (currentTemp - heatingSetpoint >= threshold && thermostat.currentHeatingSetpoint - ct >= threshold) {

			thermostat.setHeatingSetpoint(ct - 2)

			log.debug "thermostat.setHeatingSetpoint(${ct - 2}), OFF"

		}

	}

}

else {

	thermostat.setHeatingSetpoint(heatingSetpoint)

	thermostat.setCoolingSetpoint(coolingSetpoint)

	thermostat.poll()

}

}

// for backward compatibility with existing subscriptions

def coolingSetpointHandler(evt) {

log.debug "coolingSetpointHandler()"

}

def heatingSetpointHandler (evt) {

log.debug "heatingSetpointHandler ()"

}