Keep Me Kozy2 change needed


(Joel W) #1

I have a smart thermostat and the SmartThings Temperature/Humidity sensor and would like the ability in the Kozy2 to have a specific time range set for the sensor to change the thermostat if it goes to a certain degree. Example: My Thermostat is set back at night in the winter at 11:00PM to 64 degrees, and my bedroom with the SmartThings sensor is reading 4 degrees cooler so I want the heat in that room to go to 64 degrees so a signal is sent to my thermostat to increase temp to compensate during the hours of 11:00PM to 7:00Am when I am home.


(Craig) #2

I just wrote this the other day. This works similar to Keep my cozy except it uses the temperature set on the thermostat as the starting point.

This means you can use other apps / modes / hello, home commands to switch temperatures at different times / events and this application automatically adjusts.

I’ve only written this to work for heating but I’ll make an update over the next few months for AC as well.

definition(
    name: "Climate Control",
    namespace: "",
    author: "Craig Lyons",
    description: "Uses external themostat to run HVAC",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo@2x.png"
)

preferences() {
	section("Choose Thermostat... ") {
		input "thermostat", "capability.thermostat"
        
	}
	
    section("Choose Sensor... " ) {
		input "sensor", "capability.temperatureMeasurement", multiple: false
	}
    
    section("Set threshold " ) {
		input "tempThreshold", "decimal"
	}
    
}


def installed()
{
	log.debug "enter installed, state: $state"
	subscribeToEvents()
}

def updated()
{
	log.debug "enter updated, state: $state"
	unsubscribe()
	subscribeToEvents()
}

def subscribeToEvents()
{
	subscribe(sensor, "Temperature", sensorHandler)
	subscribe(thermostat, "temperature", heatingSetpointHandler)
	subscribe(thermostat, "thermostatMode", heatingSetpointHandler)
    subscribe(thermostat, "heatingSetpoint", heatingSetpointHandler)
    
    state.realHeatSetPoint = thermostat.currentHeatingSetpoint
    state.tempHeatSetPoint = thermostat.currentHeatingSetpoint + 2
    
    runIn(30,checkTemp)
}

def heatingSetpointHandler(evt)
{
	log.trace "heatingSetPoint"
	log.info "thermoSetPoint: '${thermostat.currentHeatingSetpoint}' / tempSetPoint: '${state.tempHeatSetPoint}'"
    
    if (state.tempHeatSetPoint != thermostat.currentHeatingSetpoint)
    {
    	log.trace "Setting realHeatSetPoint: '${thermostat.currentHeatingSetpoint}'"
        state.realHeatSetPoint = thermostat.currentHeatingSetpoint
    }
    
    checkTemp()
    
}

def sensorHandler(evt)
{
	checkTemp()
}

def checkTemp()
{
		def tm = thermostat.currentThermostatMode
		def ctThermo = thermostat.currentTemperature
		def ctSensor = sensor.currentTemperature
        def sp = state.realHeatSetPoint
        
    if (needHeat())
    {
    	if (incrHeatSetPoint())
        {
        	state.tempHeatSetPoint = ctThermo + 2
            log.info "Changing Thermostat from '${sp}' to '${state.tempHeatSetPoint}' because sensor is '${ctSensor}'"
            thermostat.setHeatingSetpoint(state.tempHeatSetPoint)
        }
        else
        {
        	log.info "Thermostat set to '${sp}' and current themostat temp is '${ctThermo}'. Not changing anything."
        }
    }
    else 
    {
    	if (heatGood() && thermoNotRight()) 
    	{
    		log.info "Changing Thermostat to '${sp}' because Thermostat is '${ctThermo}' and Sensor is '${ctSensor}'"
        	thermostat.setHeatingSetpoint(sp)
        	state.tempHeatSetPoint = -99
    	}
    	else
    	{
    		log.info "Everything is correct"
    	}
    }
}

private heatGood()
{
	def ctSensor = sensor.currentTemperature
    def sp = state.realHeatSetPoint
    def result=false
     
    if (((ctSensor - tempThreshold) >= sp))
    {
     	result = true
    }
        
    log.trace "checking if heat is Good"
    log.info "[ RETURN: '${result}' ] -- ${ctSensor} - ${tempThreshold} ('${ctSensor - tempThreshold}') >= ${sp}"
        
    return result
}

private thermoNotRight()
{
	def sp = state.realHeatSetPoint
	def csp = thermostat.currentHeatingSetpoint
    def result = false
    
    if (sp != csp)
    {
    	result = true
    }
    
    log.trace "thermoNotRight"
    log.info "[ RETURN: '${result}' ] -- ${sp} != ${csp}"
    
    return result
}

private needHeat()
{
		def tm = thermostat.currentThermostatMode
		def ctSensor = sensor.currentTemperature
        def sp = state.realHeatSetPoint
        def result=false
        
        if (((ctSensor + tempThreshold) < sp) && (tm in ["heat","emergency heat","auto"]))
        {
        	result = true
        }
        
        log.trace "checking if we Need Heat"
        log.info "[ RETURN: '${result}' ] -- ${ctSensor} + ${tempThreshold} ('${ctSensor + tempThreshold}')< ${sp} && ${tm} in ['heat', 'emergency heat', 'auto']"
        
        return result
}

private incrHeatSetPoint()
{

	def sp = state.realHeatSetPoint
	def ctThermo = thermostat.currentTemperature
    def result = false
    
    
		
    if (ctThermo >= sp)
    {
    	result = true
    }


	log.trace "checking if we Need to increase heat"
    log.info "[ RETURN: '${result}' ] -- ${ctThermo} >= ${sp}"
    
    
	return result

}

Help making most basic app ever: select thermostat setpoints for both above and below a specific sensor's reading
(Joel W) #3

It would be great except I need actual times not hello home, night, day etc.


(Craig) #4

Hello, Home can run at a time. So I use hello home based on motion but you could do the same thing based on time and change the temperature by triggering the hello, home. There are other apps that will change temp based on times and my application will run the HVAC based on an external sensor and will change as the temperature is changed either by an app or manually.