Made a Mobile Presence Solution That Works (Android/Root)


(Cory S) #1

I have been bugging SmartThings for awhile about Mobile Presence. I go through a lot of devices, and I’ve noticed on some it works flawlessly, but on others it is absolutely horrible. I have no idea why, as they all work great with other geofencing apps that just use Google Play Services (same as ST), But, rather than keep complaining I decided to use those other apps that do work fine to fix the issue. This solution also utilizes WiFi presence as a backup method.

This solution utilizes the following

Trigger

Tasker Note: The only thign I am using Tasker for is to send a trigger SMS to IFTTTT because the method the Trigger app uses only compose sit, it doesn’t automatically send it. It may work differently on other phones.

IFTTT

Now arguably, this can actually all be done with just Tasker. I am using Trigger because it has a much more user friendlier UI and is easier to set the rules up in, it also supports Play Services Geofencing, where as Tasker does, as far as I can tell not. Also, Trigger is not a root app, and if we can find a way to use it to replace tasker then we wouldn’t need root.

Tasker could also be setup to trigger Smartthings instead of IFTTT, and would arguably be more reliable at it. I am just using IFTTTT because I had never used it before and wanted to try it out, and it is also again much more user friendly than Tasker. Also, utilizing IFTTTT would make it possible for this to work on more restricted platforms.

First you want to go into the IDE and create a virtual on/off button. Simply do the following:

*Go to ide.smartthings.com
*Go to Devices
*click “New Device”
*name it anything you like mines “Cory Mobile Presence”
*Device Network ID: N/A
*Type: On/Off Button Tile
*Location: Home
*Create

Go into your app and create rules that change the mode to away or home based on if this switch is on, or off.

Next configure the following IFTTT recipes

Configure the following IFTTT recipe to turn on your virtual switch when it receives a message that you chose to signify your home. It needs to have no spaces (hashtag)

Configure the following to turn the switch off when it receives an SMS signifying that you have left (again no spaces)

Next install Tasker (it is important you install it before Trigger)

next open Tasker, go to menu, Preferences, MISC, and click “Allow External Access” (This allows Trigger to run Tasker tasks)

Back out of that and go to the “Tasks” pane on the Tasker Home screen.

*Click “+” to create a new Task
*name what ever, mine is “Cory is Home”
*Click “+” on the next page
*Click “Phone” and “Send SMS”
*Fill it out to send an SMS to your IFTTT number with the hashtag you chose to signify your home (The IFTTT phone number is shown to you when you configure the recipe)

Then do the same thing for the exit presence recipe

Finally, we setup Trigger with 3 tasks.

First setup a new trigger for “Geofence” pick pick a large circle around your house.
Click next and click “+” scroll down to tasker, and pick your entry task.

Now complete the above again for your exit task.

Finally, Create a new task in Trigger that also flips the virtual mobile presence switch on when you connect to your home wifi as a final fail safe in case the above method flakes out. You could do the same to trigger you as not present when you disconnect from wifi, but this could cause issues with phones that have weak wifi, or phones that turn off wifi to save power when the screen is off…feel free to experiment with this.


Mobile presence using wifi only
(Cory S) #2

Looks like my links for the IFTTT recipes didn’t work…and now I can’t edit it. Here they are below

Is Present

Is not Present


(Steve S) #3

I did a very similar thing for iOS using the IFTTT app - same as you - the rest of the geofencing apps seem to work fine, but ST doesn’t.

So, I installed a virtual switch that gets triggered by the IFTTT rule from the IFTTT app (using the IFTTT geofencing feature). The bummer is that it can’t get the mobile presence state to actually fix itself, but it can switch ST from Away to Home to avoid the alarm going off.

@coryds - how do you “bug” them? via support? here? email? When I contact support (for almost 6 months now) I’m told they are aware… highest priority… Fix is in QA testing… etc.


(Cory S) #4

@stevesell Sometime back I wrote an email to a member on the ST team which ended up getting forwarded to Alex Hawkinson with a list of issues that had been going on for an extended period of time. He and several members of his team asked me to participate in a conference call with them which was very enlightening.

Recently, @emilyallen and members of the Android Beta Team met with me with some problems I was having with the app, and it was also a positive experience.

However, both times they blame either Google, or the phone for presence issues, and in my experience that just doesn’t seem to be the case being other apps work fine using the same APIs.


(Impliciter) #5

A cleaner way to do this (as you alluded to) would be to have Trigger/Tasker send a HTTP Get request to an endpoint that you have mapped in a Smartapp.

mappings {

	path("/home/") {
		action: [
			GET: "changeModeHome"
		]
	}
	path("/away/") {
		action: [
			GET: "changeModeAway"
		]
	}
    
}

//mode
def changeModeHome() {
    setLocationMode("Home")
}
def changeModeAway() {
    setLocationMode("Away")
}

I use this with a script running on my server to monitor wifi devices. It is really easy to setup if you follow the endpoints example.


(Cory S) #6

I like that.

Currently I am trying to figure out how to make it behave more like an actual presence device so I can just set it up in my current mode apps.

The way I have it setup now turns the house off even if other people are still home.


(Cory S) #7

@impliciter I just noticed Trigger has a SMS plugin which removes the requirement for Tasker. You can now use Trigger for the geofencing and the actual text triggers.

I also tested using endpoints in Trigger, and that also works very well. So, you can clean this up a lot by removing Tasker & IFTTT from the mix. Still working on a more “presence” method of handling this rather than mode based.


(Impliciter) #8

@coryds

I agree that the virtual presence approach would be better. I started a thread not too long ago about that but didn’t get too far. It seems like it should be trivial to setup a virtual presence device type and have a smartapp set the state.

http://build.smartthings.com/forums/topic/virtual-presence-device/


(Cory S) #9

@impliciter It seems like there should be a way to modify the on/off device type into a toggle for presence. I have been messing around with it…but haven’t got it yet.


(Impliciter) #10
// Set Present/Not Present
def setPresent() {
    presence.presence = "present"
}
def setNotPresent() {
    presence.presence = "not present"
}

I think that is the command… it sure would be nice to get some documentation :slight_smile:

I initially tried to enable OAuth in the device but I believe you need to use a smartapp as a proxy. The on off tile would work and I would like the added benefit of being able to override the presence detection.


(Joe Geiger) #11

Could you modify one of the mode change smartapps that changes a mode based on detecting motion to change the mode based on a virtual switch being activated? Then you could set the IFTTT recipe to trigger the switch and change the mode when you enter/leave a location. This would bypass ST mobile presence all together. Has anyone tried this before?


(Brock) #12

Just to clarify for everyone – Tasker does not need root access to do any of the functionality that’s needed here. Tasker can run fine without root access.


(Cory S) #13

@impliciter I couldn’t figure it out so I just bugged @urman. He worked tirelessly for 15 minutes after I had spent the last 4 hours on it and came up with the below. My mistake was i was trying to combine the presence and switch into the same tile, his solution below is perfect for my needs.

metadata {
	// simulator metadata
	simulator {
		// status messages
		status "on": "on/off: 1"
		status "off": "on/off: 0"

		// reply messages
		reply "zcl on-off on": "on/off: 1"
		reply "zcl on-off off": "on/off: 0"
	}

	// UI tile definitions
	tiles {
		standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
			state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
			state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
		}
        standardTile("presence", "device.presence", width: 2, height: 2, canChangeBackground: true) {
			state "present", labelIcon:"st.presence.tile.present", backgroundColor:"#53a7c0"
			state "not present", labelIcon:"st.presence.tile.not-present", backgroundColor:"#ffffff"
		}

		main(["switch"])
		details(["switch", "presence"])
	}
}

// Parse incoming device messages to generate events
def parse(String description) {
	def name = description?.startsWith("on/off: ") ? "switch" : null
	def value = name == "switch" ? (description?.endsWith(" 1") ? "on" : "off") : null
	def result = createEvent(name: name, value: value)
	log.debug "Parse returned ${result?.descriptionText}"
	return result
}

// Commands to device
def on() {
	sendEvent(name: "switch", value: "on")
    sendEvent(name: "presence", value: "present")
}

def off() {
	sendEvent(name: "switch", value: "off")
    sendEvent(name: "presence", value: "not present")
}

(Mike T) #14

I’m not a software expert so let me ask if the following is possible… I’d like to create a virtual tile for Smartthings and then use Tasker to toggle it on and off on my Android device without requiring the use of an independently running server or IFTTT. I guess I’d need to set up the virtual tile using the online IDE for Smartthings and then Tasker would http POST commands to control it.

Reading thru the previous posts I’m not sure if that’s whats been done or not since an earlier post mentions using a server.


(Cory S) #15

@miket That’s fairly easy to do. If you want to toggle a presence device add a custom device type with the above code. If you just wan an on/off virtual button create a new device with that that device type.

Then authorize the following app to access the new device https://labs.smartthings.com/exampleOauth.php

After thats finished the app will display it in your browser, copy the links for the on/off and have Tasker/Trigger activate them.


(Csader) #16

@coryds, is this the virtual presence device we were discussing that you will use for your garage door setup? I can’t seem to get the oAuth list to show this newly-created device…ideas?


(Cory S) #17

@csader Yes it is, and hmm it should. When you created it did you select the presence and switch attributes?


(Art Longoria) #18

Couldn’t you just use IFTTT to trigger a device? Like If you enter Android Location (enter your home address) than switch on your device (like my garage door to open Evolve LFM-20). Wouldn’t that work? Because the ST Presence doesn’t update accurately.


Delay in presence detection after android app update?
(Jake) #19

I was following this thread, thinking about implementing this solution because my wife and I had constant issues with mobile presence. It may have something to do with us living in the middle of nowhere. Anyways, I found that using Life360 integration with smartthings rather than phone presence has been working flawlessly for my wife and I so far (knock on wood).

I was having an issue where hers worked but mine didn’t and I think it was because I setup the life360 smartapp twice, once for my life360 account and once for hers. Since I installed the life360 smartapp just once and imported all users under that one account, it has been working fine. Also, I have wi-fi, gps, and location services turned on for both phones (Android). I’m passing this along in case it helps someone else! :smile:


The Android App
Android App Version Woes