Code to Set a Simulated Presence Sensor?

Hi Everyone,

I’ve tried the presence sensors and they’re just not reliable. My iPhone works great for my presence sensor, but my wife’s phone does not. So I’ve decided to write a SmartApp that polls our Wi-Fi router log to set a Simulated Presence Sensor for my wife when her phone connects/disconnects from our home Wi-Fi network. I’ve mocked up the logic outside of SmartThings and it works great. The part I haven’t been able to determine, is how I actually code setting the Simulated Presence Sensor. I’ve written some other apps that set switches, so I suspect the syntax is similar, but I can’t find any examples in the ST templates. Can anyone point me to relevant documentation that explains how to programmatically control the Simulated Presence Sensor, or just shoot me a code snippet that shows how it’s done? Thanks in advance!

Is there an iOS equivalent of Tasker? I ditched iOS years ago so I’m not familiar with the options available.

With Android I’m using SharpTools and Tasker to set a simulated presence sensor to “arrived” or “departed” depending on my location.

I’m sure you can also do this with IFTTT but the delay might make it unreasonable.

1 Like

Thanks for the reply. No there’s no Tasker equiv on iOS. But it shouldn’t be necessary to do this in a phone app. If I can change the status of the Simulated Presence Sensor from the SmartThings app by tapping it, then I should also be able to set it in Groovy running on the hub. The simulated version behaves just like a switch, so I expect to be able to control it with code like a switch. Also, if they can do it from Tasker…

If you already have your desired Simulated Presence Sensor as an object in your SmartApp, just call device.arrived() or device.departed()

Also note that custom SmartApps do not run locally on the hub (today). Custom SmartApps run in the SmartThings cloud and can trigger actions on the hub.

Excellent! Thanks Joshua.

I’ve been making pretty good progress on my Simulated Presence SmartApp project until I got to the heart of the matter: determining whether or not the presence should be arrived() or departed(). I set up a web page that reports a device’s Wi-Fi connection status in the router log. It’s just a single word, either “On” or “Off.” I’m using the following code to get the status, and then attempting to evaluate the response. I thought it would be a simple string comparison, but the logic below always goes to the “arrived()” branch, even when the response is “Off.” Obviously I need a fresh set of eyes. Can anyone see what I’m doing wrong? I can’t. Thanks.

httpGet(params) { resp ->
    log.debug " ${}"
    String status =
    log.debug "status: ${status}"
    if( status.equals("Off") ) {
        log.debug "${the_presence}.departed()"
    } else {
        log.debug "${the_presence}.arrived()"

Can you print the status messages that you are string comparing with? Maybe you’re not getting the response you think you are or are expecting …

Hi Mike,

The log.debug statement,

log.debug " ${}"

returns, On

When the status page is “Off,” it returns, Off

The hashcodes are different, so I thought it was a String vs. GString thing, but no matter what kind of data type manipulation I try on either value, I can’t get them to match. I’ve since worked around the problem by ignoring the strings altogether and just looking for the “Off” hashcode value. It works fine now, but I sure would like to know why the String matching is so problematic in Groovy. Seems like String matching should be one of the simplest implementations.