Help making most basic app ever: select thermostat setpoints for both above and below a specific sensor's reading


(Dave Keil) #1

Hi.

I’ve been suspecting it for a while, but I’m starting to become convinced I’m actually a moron. I’ve been trying on and off for 3 years now to get an app to do something that I see as super basic but I can’t get anywhere with it. Everything I edit breaks. Nothing seems to work. I don’t get it.

I want to make a smartapp that:

  1. Asks you to select a temperature sensor
  2. Asks you for the temperature you want to keep that sensor below
  3. Asks you to select a thermostat
  4. Asks you to set the cooling setpoint when the temperature sensor is above the temp in 2.
  5. Asks you to set the cooling setpoint when the temperature sensor is below the temp in 2.

That’s it. That’s all. I’ve been trying for years and I can’t crack that nut. I suck.


(Bryan) #2

Do you contantly need to select the sensors and thermostats on the fly, or do you just need to select them once?

If you can hard code the sensors and thermostats, you can easily do that in webCore.


(Dave Keil) #3

Everything set once on setup, then it just sits there and runs until the hardware breaks.


#4

Sorry, I’m confused about the purpose of your points four and five.

Why do you need two different setpoints, one for when the sensor reading is higher than your target and one for when the sensor reading is lower?

Why don’t you just have a target temperature on the sensor and turn on the air-conditioner if the temperature is higher than that? That’s a classic thermostat.

I agree that it’s likely that webcore can do everything that you were asking for, I’m just not quite sure what you are asking for. :sunglasses:


(Dave Keil) #5

I’ve tried setting up and building it in webcore. Now I just need to figure out how to get the code out of webcore and into smartthings so it actually updates the setpoint on the t-stat. Feels like progress. I can’t find anything that shows me how to get the code out though.

The points for 4 and 5 is I don’t want to give cart blanche control to another temp device. Smartthings in my experience is a really unrobust platform. I don’t want to have a simple loss of internet connectivity putting the AC on full throttle full time and trying to make icecubes in my livingroom. The solution is basically the temp sensor saying it’s warm and putting the AC set point to some lower but still reasonable level either until it’s not warm or whatever it gets with the lower setpoint.


(Bob Kerr) #6

What have you tried and didn’t work? Post the code you have and people might be able to help. Or search the community for similar apps and follow their code. What you are asking has been done many times before.

[Thermosts app search](https://community.smartthings.com/search?context=topic&context_id=13599&q=Thermostat manager&skip_context=true)


(Dave Keil) #7

Send me a link to something that’s remotely close. I’ve searched the community and tried various code snippets for 8+ hours every 3-4 months. I’m finding a lot of things are broken now. Keep Me Cosy II doesn’t work anymore for example.


(Bob Kerr) #8

Don’t know why the link breaks, but search for thermostat manager. Those are all apps that change setpoints.


(Dave Keil) #9

I’ve made this in webcore. I don’t see how to get it to start executing and updating the tstat settings.


(Dave Keil) #10

jmarkwell : Thermostat Manager

doesn’t use any external temp sensors. I’m not actually sure what the use case of that app is.


(Dave Keil) #11

This one throws some kinda of “can’t subscribe to null events” error on line 50 that I don’t understand.


#12

Webcore has their own forum where most of the experts hang out. They should be able to help you. ( this is a clickable link)


(Dave Keil) #13

Thanks JDRoberts - I’ll follow up with the webcore thread over there. I would still like to have something in the smartthings IDE naively.


(Dave Keil) #14

I’ve tried editing 'It’s too cool" to be it’s too hot. I still get the null error on line 50 I don’t understand.

definition(
name: “Climate Control Cool II”,
namespace: “”,
author: “Dave Keil”,
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”, coolingSetpointHandler)
subscribe(thermostat, “thermostatMode”, coolingSetpointHandler)
subscribe(thermostat, “coolingSetpoint”, coolingSetpointHandler)

state.realCoolSetPoint = thermostat.currentCoolingSetpoint
state.tempCoolSetPoint = thermostat.currentCoolingSetpoint - 2

runIn(5,checkTemp)

}

def coolingSetpointHandler(evt)
{
log.trace “coolingSetPoint”
log.info “thermoSetPoint: ‘${thermostat.currentCoolingSetpoint}’ / tempSetPoint: ‘${state.tempCoolSetPoint}’”

if (state.tempCoolSetPoint != thermostat.currentCoolingSetpoint)
{
	log.trace "Setting realCoolSetPoint: '${thermostat.currentCoolingSetpoint}'"
    state.realCoolSetPoint = thermostat.currentCoolingSetpoint
}

checkTemp()

}

def sensorHandler(evt)
{
checkTemp()
}

def checkTemp()
{
def tm = thermostat.currentThermostatMode
def ctThermo = thermostat.currentTemperature
def ctSensor = sensor.currentTemperature
def sp = state.realCoolSetPoint

if (needCool())
{
	if (incrCoolSetPoint())
    {
    	state.tempCoolSetPoint = ctThermo - 2
        log.info "Changing Thermostat from '${sp}' to '${state.tempCoolSetPoint}' because sensor is '${ctSensor}'"
        thermostat.setCoolingSetpoint(state.tempCoolSetPoint)
    }
    else
    {
    	log.info "Thermostat set to '${sp}' and current themostat temp is '${ctThermo}'. Not changing anything."
    }
}
else 
{
	if (coolGood() && thermoNotRight()) 
	{
		log.info "Changing Thermostat to '${sp}' because Thermostat is '${ctThermo}' and Sensor is '${ctSensor}'"
    	thermostat.setCoolingSetpoint(sp)
    	state.tempCoolSetPoint = -99
	}
	else
	{
		log.info "Everything is correct"
	}
}

}

private coolGood()
{
def ctSensor = sensor.currentTemperature
def sp = state.realCoolSetPoint
def result=false

if (((ctSensor - tempThreshold) <= sp))
{
 	result = true
}
    
log.trace "checking if cool is Good"
log.info "[ RETURN: '${result}' ] -- ${ctSensor} - ${tempThreshold} ('${ctSensor - tempThreshold}') <= ${sp}"
    
return result

}

private thermoNotRight()
{
def sp = state.realCoolSetPoint
def csp = thermostat.currentCoolingSetpoint
def result = false

if (sp != csp)
{
	result = true
}

log.trace "thermoNotRight"
log.info "[ RETURN: '${result}' ] -- ${sp} != ${csp}"

return result

}

private needCool()
{
def tm = thermostat.currentThermostatMode
def ctSensor = sensor.currentTemperature
def sp = state.realCoolSetPoint
def result=false

    if (((ctSensor + tempThreshold) > sp) && (tm in ["cool","auto"]))
    {
    	result = true
    }
    
    log.trace "checking if we Need Cool"
    log.info "[ RETURN: '${result}' ] -- ${ctSensor} + ${tempThreshold} ('${ctSensor + tempThreshold}')> ${sp} && ${tm} in ['cool', 'auto']"
    
    return result

}

private incrCoolSetPoint()
{

def sp = state.realCoolSetPoint
def ctThermo = thermostat.currentTemperature
def result = false


	
if (ctThermo >= sp)
{
	result = true
}


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


return result

}


(Bob Kerr) #15

What is on line 50? Can you post that?


(Dave Keil) #16

30db269b-6d24-4858-a759-846c4b0ec4d8 12:32:56 PM: error java.lang.NullPointerException: Cannot invoke method minus() on null object @line 50 (subscribeToEvents)
30db269b-6d24-4858-a759-846c4b0ec4d8 12:32:56 PM: debug enter installed, state: [:]

state.tempCoolSetPoint = thermostat.currentCoolingSetpoint - 2


(Bob Kerr) #17

Try latestValue or currentValue followed by (“coolingSetPoint”)…


(www.rboyapps.com - Make your home your butler!) #18

Sounds like you’re looking for temperature management app that controls the thermostat using a remote temperature sensor. If you have access to RBoy Apps check out our range of temperature management SmartApps, most of them support remote temperature sensors to use with a thermostat and other heating/cooling devices as well.

Here are a few:


(Craig) #19

I see you are using some old code I wrote a million years ago. It’s been a long time since I looked at this code, but I Can tell you I had to re-write it several times (no idea where the latest version is) before it even remotely started working correctly. Many times I work up to the house being 80 degrees in the dead of winter because I got stuck in a loop.

I’d hate for you to spend a ton of time looking at some cut rate code I wrote 3-4 years ago!


(Dave Keil) #20

Thanks for following up craig.

I’ve got something working through WebCoRE, it took ages because some changes I made to the tstats DTH broke the setpoint setting function in apps.