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?
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.
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â).
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.
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???
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
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.
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.
@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
/**
* 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."
}
}