Code help. editing virtual thermostat


(Michael Sammon) #1

im trying to edit the ‘virtual thermostat’ app to turn on fans if within a certain degrees of the target temperature. not sure what i am doing wrong…a little help?

/**

preferences {
section("Choose a temperature sensor… "){
input “sensor”, “capability.temperatureMeasurement”, title: “Sensor”
}
section(“Select the fans…”){
input “outlets”, “capability.switch”, title: “Fans”, multiple: true
}
section(“Turn on if within so many degrees of target temperature…”){
input “number”, “decimal”, title: “Degrees”
}
}

def installed()
{
subscribe(sensor, “temperature”, temperatureHandler, setPoint)
}

def updated()
{
unsubscribe()
subscribe(sensor, “temperature”, temperatureHandler, setPoint)
}

private evaluate(currentTemp, setpoint)
{
log.debug "EVALUATE($currentTemp, $setPoint)"
if (mode == “cool”) {
// air conditioner
if (setPoint - currentTemp <= number) {
outlets.on()
}
else if (setPoint - currentTemp >= number) {
outlets.off()
}
}
else {
// heater
if (setPoint - currentTemp >= number) {
outlets.on()
}
else if (setPoint - currentTemp <= number) {
outlets.off()
}
}
}