Thermostat events?


(Im Brian) #1

I have a Nest thermostat I have hooked up to SmartThings. What I’d like to create is an app to send me a notification if the thermostat turns on (either heat or cool) and any window with a contact sensor is open. It doesn’t look like I’m able to subscribe to an event:

  subscribe(thermostat, "thermostat.heat", turnedOn)
  subscribe(thermostat, "thermostat.cool", turnedOn)

I’ve played around with other events, such as “on”, “thermostat.on”, etc. Any thoughts? I’m also not able to get these to fire using virtual devices.


(Ethan Ferrell) #2

If you’re using Dianoga’s Smart Nest (http://build.smartthings.com/projects/smartnest/) device type, then you should be able to poll the device to get all the info. I’m still a noob myself so I don’t want to give you broken code, but take a look at the device type code.


(Im Brian) #3

Yeah, it just seems rather crude to set up an interval to query a value instead of having ST abstract it to fire the event when it sees a change. Perhaps wishful thinking.


(Ethan Ferrell) #4

That’s the best we have for now until Nest gives us some documentation on their ZigBee protocol. For now we’re stuck using their web API which obviously doesn’t communicate directly with ST API. You’ll need to setup a schedule using a cron expression to poll the Nest via the web API then act on the data.

You could set the Nest to away mode when a window is opened and change it back when the window closes. This way you subscribe to the contact sensor.


(Im Brian) #5

Thanks, @ethanferrell - I’d hoped (and I guess expected) since my Nest was polling to update the tiles, it’d trigger events (even if they were delayed a fair bit). I can set up a cron for this, probably every half hour to check sensors.


(Brian Steere) #6

@ImBrian Have you tried subscribing to thermostatMode — [“off”, “emergency heat”, “heat”, “cool”]?


(Im Brian) #7

@dianoga - Yeah, I’d tried “on”, “heat” and “cool” without luck.


(Ethan Ferrell) #8

How often does the device get polled from ST?


(Brian Steere) #9

@ImBrian subscribe to thermostat.thermostatMode


(Ethan Ferrell) #10

@Dianoga
Good catch, I forgot about the inherited attributes. Like I said, I’m still new.

@ImBrian
Subscribe like Dianoga suggested and then in your mode handler you’ll need to check its value.

I.e.

def thermostatModeHandler(evt)
{
	log.debug "evt.name: $evt.value"
	if (evt.value == "cool") {
                //send cool msg
	}
	elseif (evt.value == "heat") {
		//send heat msg
	}
}

Could use a case statement too for all the other possibilities.


(Im Brian) #11

Awesome - events firing. Will post an app soon :slight_smile:

Thanks, all!


(Im Brian) #12

Probably still needs polish, but it’s now published under “Green Living” under the name “thermostat_window_check”. It’s also available here: https://github.com/imbrianj/thermostat_window_check/blob/master/thermostat_window_check.groovy

Thanks again for your help, @ethanferrell @dianoga