Firing actions when leaving hub less locations?


(Daniel Consuegra) #1

Hey all!

Hope i put this in the right place, if not, mods are welcome to recategorise it!

I have three locations setup in my account. One with hub, the other two for now hub less.

What can I do (what app can I install at my main location) so that there is a mode change or an action takes place when i leave one of the hub less places?

I’m thinking specifically thermostat/AC.

Am I crazy? Is it doable?


(Eric R) #2

I looked into trying to do this a while ago. When I was trying, I couldn’t find a way to make it work. I ended up using IFTTT for a while, but it was not as quick as I hoped. I then ended up running a script on my work computer whenever it shut down to indicate I was heading home.


(Daniel Consuegra) #3

dang… one of the locations i have, has no computer where i could fire that script. But the other one… would you share the code and how to run it? Is it Mac or PC based?


(Eric R) #4

I don’t have the script itself that I used. That’s on my work computer and it is currently the weekend. I do have the SmartApp part. The SmartApp is very specific to my needs. The way it functions is when you install it, there will be a URL in the logs. If you GET the url, it will change from one specific mode to another specific mode (Away to On My Way Home). I also have it set up to do two sets of modes (Previous example except the dark versions). You could probably adapt this to meet your needs.

As for the script, you can use something like curl and have it run on shutdown. There are plenty of instructions on the web to make it work.

/**
 *  Change Mode from URL
 *
 *  Copyright 2014 Eric Roberts
 *
 *  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: "Change Mode from URL",
    namespace: "baldeagle072",
    author: "Eric Roberts",
    description: "This will allow you to change to the specified mode when you GET the url associated with the app.",
    category: "",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    oauth: true)


preferences {
	section("Mode") {
    	input "changeFromMode", "mode", title: "Mode to change from", multiple: false, required: true
		input "changeToMode", "mode", title: "Mode to change to", multiple: false, required: true
        input "changeFromModeDark", "mode", title: "Mode to change from - dark", multiple: false, required: true
		input "changeToModeDark", "mode", title: "Mode to change to - dark", multiple: false, required: true
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	initialize()
}

def initialize() {
	if (!state.accessToken) {
        createAccessToken()
    }
    getURL(null)
}

mappings {
    path("/change") {
    	action: [GET: "changeMode"]
    }
}

def getURL(e) {
    log.debug("getURL")
    def url = "https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/change?access_token=${state.accessToken}"
    log.debug " url: $url"
}

def changeMode() {
	def newMode
    if (settings.changeFromMode == location.mode) {
    	newMode = settings.changeToMode
    } else if (settings.changeFromModeDark == location.mode) {
    	newMode = settings.changeToModeDark
    } else {
    	newMode == location.mode
    }
	
	if (newMode && location.mode != newMode) {
		if (location.modes?.find{it.name == newMode}) {
			setLocationMode(newMode)
			log.debug("has changed the mode to '${newMode}'")
		}
		else {
			log.debug("tried to change to undefined mode '${newMode}'")
		}
	}
}

(Daniel Consuegra) #5

Thanks! Will give it a try!


#6

If this is a thermostat at the main location where your hub is physically present, it should be very doable with IFTTT. There could be a 15 or 20 minute delay, though, so its usefulness to you may depend on how long your trip from one location to another takes.

You just use the IFTTT app on your smart phone for presence detection as the “this” trigger, and the SmartThings channel as the " that."


(Daniel Consuegra) #7

Awesome! I’ll have to try that idea too then! Now, if only the Netatmo thermostat were integrated into the system, just like their weather station… sigh…