Mode changes with nest support

Hello All,

I am new to smartthings and will be asking plenty of questions soon. I am diving in head first and trying to learn as much as i can. I have been using the smartapps documentation to try to learn as much as i can, but they dont really go down to the basics as much as a newbie like me requires.

Anyway, that is beside the point. Currently I have the smartthings hub and a nest thermostat. I realize that they are not really working together, i just havent gotten any devices to connect with the hub yet. I have created 2 locations in my smartthings account 1) Home 2) Work. I have activated geofences around both of those and have set up mine and my fiance’s phones as presenceSensor. My questions comes up here, when i leave the house if i set my home location to “away” or any other mode, I can have smartthings set my Nest to “away” also so the AC wont run any more (if i can figure out how to program a smartapp to change the presence status of a thermostat).

I would like to set the Nest to “home” when i leave work (working on an app that will set presence on nest to “home” when I leave the “work” geofence after a set time of day during the week). The one way i have thought of to do this so far is to install the nest device in both home and work locations and to install the smart app i am slowly working on at work.

The way I would prefer to do it is to trigger a mode change at home when i leave work. I am not sure if this is possible or not. Is there a way that i can subscribe to presence at a different location?

1 Like

Right now there isn’t a way to subscribe to events at other locations. It’s a good idea though.

Your idea of adding the Nest to both devices is a good one. I hadn’t thought of that approach. The code to change the thermostat to away has been done a couple of different ways.

Change based on mode

2 Likes

can’t you do something like is shown in this video released by ST? http://youtu.be/ztipde2oR_E

use a virtual location geofence around your work to trigger the mode change? Or maybe the life 360 or IFTTT location services.

That is basically what I had in mind, i guess i can have it send a notification to IFTTT and have IFTTT set the mode


but ifttt cannot change modes currently, unless someone has written a smart app
 search time

I want to include here what i found for my solution. Through a quick search of “ifttt mode” I found a way to use Ifttt to change modes. The solution I found was to have ifttt trigger a dummy on/off button tile and to have a smart app monitor that tile, when it is on trigger the mode change and then turn the switch back off.

Originally the app was specifically to trigger from away to home. I wanted to make it a bit more customizeable because i can see myself using a few of these, so i added preferences to specify 2 modes. mode 1 is the mode you are changing from (in my case i am changing from “At Work”), mode 2 is the mode you are changing to (in my case “coming home”).

Here is the code

1 Like

Dianoga,

Thanks for the nest mode change code. It was very helpful. I used that code to make my own smart app which will let me select a smartthings mode that will trigger changes to Nest and switches (potentially other things later). Have a look if you want.

Here is the code

If anyone can help me out with this, the above code is not working correctly. It seems to be delayed by one mode change. For example.

I leave the house, it switches to “Out for a Bit” mode which should trigger nest to turn off (it does not). I come back home, it switches to “Home” mode which should trigger nest to turn on (nest gets turned off). if i switche the mode to any things else then nest will get turned on.

The desired command seems to be delayed by one mode change, can anyone spot the reason why in my code from the past 2 posts???

Here is some debug log from a test i just did.

4:38:01 PM: debug No changes
4:38:01 PM: debug Mode changed to Home //see the attached screenshot. I actually switched it to Out for a Bit mode at this time

4:37:20 PM: trace Replied with ‘switch:on’
4:37:20 PM: trace Received command ‘on’ for device ‘Switch Capability offSwitches’ //turned on the off switch
4:37:14 PM: trace Mode Changes, Settings Change was provided
creating subscription
4:37:14 PM: trace Home was provided
creating subscription
4:37:14 PM: debug Current mode: Home
4:37:14 PM: debug Installed with settings: [newMode:Out for a bit, thermostats:[Nest], thermode:Away, onSwitches:[onSwitches], offSwitches:[offSwitches]] //I set my actual nest as the thermostat, the virtual thermos dont support home and away mode i dont think. I also set up one onSwitch and one offSwitch

side note, how do we chose what picture shows up in hello home, because that is not my picture
 small things i know


Try using evt.value instead of location.mode. It’s possible the location mode hasn’t been updated when your subscription triggers. evt.value should contain the name of the mode you’re switching to.

Yes, you have to use evt.value
 location.mode doesn’t seem to update until AFTER it calls your event handler. I found that out by trial and error when I wrote an app very similar to @Dianoga’s

Alright so i just did a simple replace of all the location.mode with evt.value. I think i am missing something and i want to understand what i am doing so i am going to ask a couple questions.

i subscribe to location for my process of changeMode. when i call out changeMode(evt) im telling it to listen for an event in the location, and evt.value is supposed to take that event and spit out what it is, right?

I have changed my subscription to subscribe(location , “location.mode”,changeMode) to try to specify that i am looking for mode changes in the location. I also added a $evt.value to a debug code and it is returning the word “touch” and not a mode at all.

All help is much appreciated
 I’ve been coding for about 4-5 days total in my life so i am trying to learn as much as i can from viewing code and from the help of people in the forums.

Update: i changed my subscription back to remove the “location.mode” and the app works beautifully, but if anyone can explain to me what i did wrong i would appreciate it.

Location is a strange thing and not like other events. When you subscribe to location, it really means subscribing to mode change.

You were seeing the touch event because you’re also subscribing to app. I believe that allows you to trigger actions when you tap on the app icon on your device.

gotcha, thanks for the explanation, and thanks for your Nest device type.

After updating my 2 smartapps last night (mode change based on switch, and settings change based on mode) they worked perfectly this morning. Hopefully the trend continues and when i leave work today the nest will come on to cool the house before i get home.

2 days later and the apps are working great.

I would like to add some additional awareness to the mode change app however to keep it from changing modes if someone is home. Should be easy enough just need to add preferences for presence sensors to be monitored, subscribe to them for a new process and hook that in to the app via an if else.

I’ll post what I find

1 Like

@CCSturgis This whole idea is a good one, nicely done! I’ve installed your SmartApps and setup the IFTTT trigger, so we’ll see how this goes. I love the idea of the A/C turning on when I leave work.

Thanks! This is the first coding I have ever done (bar a FORTRAN class in college), please let me know if it gives you trouble. I will let you know when I get around to the bit about not changing mode if someone is home.

So I used the codes provided by @dianoga and created a new Away/Home mode on the Nest Thermostat based on the Presence Sensor.

I didn’t like the away Mode so I decided to let Nest change its modes based on my presence. It has worked well so far, and I wanted to share with all of you in case you guys didn’t like away modes.

I even created a little icon for it :smiley:

/**
 *  Nest Auto Away
 *
 *  Copyright 2014 Samuel Wang
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "Nest Auto Away",
    namespace: "",
    author: "Samuel Wang",
    description: "Nest changes Home/Away status based on Presence.",
    category: "My Apps",
    iconUrl: "https://dl.dropboxusercontent.com/u/2421186/nestaway.png",
    iconX2Url: "https://dl.dropboxusercontent.com/u/2421186/nestaway%402x.png")


preferences {
  section("When I arrive and leave..."){
		input "presence1", "capability.presenceSensor", title: "Who?", multiple: true
	}

  section("Change these thermostats modes...") {
    input "thermostats", "capability.thermostat", multiple: true
  }
}

def installed()
{
	subscribe(presence1, "presence", presenceHandler)
}

def updated()
{
	unsubscribe()
	subscribe(presence1, "presence", presenceHandler)
}

def presenceHandler(evt)
{
	log.debug "presenceHandler $evt.name: $evt.value"
	def current = presence1.currentValue("presence")
	log.debug current
	def presenceValue = presence1.find{it.currentPresence == "present"}
	log.debug presenceValue
	if(presenceValue){
		thermostats?.present()
		log.debug "Nest is set to Home."
	}
	else{
		thermostats?.away()
		log.debug "Nest is set to Away."
	}
}
4 Likes

Hi, sorry but for use you cose?
i need to create a new device in my hub page or waht??
can you help me?

Hi @silviodaliana

You just need to create a new Smartapp. You can keep your new Nest Device.

Thanks,