Hey all - Like so many of you, I’ve been having issues with SmartThings and detecting presence using iPhones. I have had issues with both false positives and false negatives and when I tried to switch to tags, well, those were worse.
On the other hand, I’ve had great success using IFTTT to detect my presence and turn off the Hues when I leave, change the thermostat, make sure the doors are locked etc. Well this is all fine and dandy but the problem is that I need to control for the presence or absence of both me and my guy. I ran across @tslagle13’s fantastic Hello, Home Phrase Director app the other day and it can run certain hello, home phrases depending on house occupancy (i.e. presence/absence of several people/phones/tags), but it still relies on SmartThings crappy presence detecting. So, for the time being, I’m using Simulated Presence Sensors – Not exactly the ‘automated’ solution I was looking for.
So - I had an idea – Since IFTTT can’t control SmartThings’ presence devices, but can control the state of virtual switches, what if I just set a couple of virtual switches to indicate the presence of me and my guy and then tweak the Hello, Home Phrase Director to establish occupancy based on switch status instead of presence sensors?
Has anybody tried this already before I mess with it? My Smartthings/Groovy coding isn’t exactly phenomenal .
I have tried it and for some reason I got to a point where I decided that the virtual switch wasn’t going to provide the rich experience I was hoping form. I can’t remember what stopped me dead in my tracks, but in other news my iPhone presence sensing has been working very well lately.
Here was my code, no idea how it stands… Can’t remember how much is stolen either… Good luck!
No need to modify the Magic Home code. You can use simulated presence sensors tied to virtual switches. For each presence, create a presence and a switch in the IDE. You can use the code below to link them together. Then use IFTTT to trigger the switches.
This is for one switch and presence sensor.
/**
* Virtual Presence using switch
*
* Copyright 2015 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: "Virtual Presence using switch",
namespace: "baldeagle072",
author: "Eric Roberts",
description: "Use a switch to change state of a virtual presence sensor",
category: "Family",
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")
preferences {
section("Switch on = present, switch off = not present") {
input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
input "slavePresence", "device.simulatedPresenceSensor", title: "Virtual Presence", 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() {
subscribe(controlSwitch, "switch", "switchHandler")
}
def switchHandler(evt) {
if (evt.value == "on") {
slavePresence.arrived()
} else {
slavePresence.departed()
}
}
Will be interested in your results as this solves a similar issue I posted…Thanks!
::Edit::
Tried the code myself and it works rather well for turning the presence on and off based on the simulated switch settings.The android IFTTT is a bit wonky, but if I can get that to work I am golden!
Looks like it works just fine! When I got to work this morning it detected the house as being unoccupied and set the mode accordingly. So if you are looking for a presence workaround, I’d give this a try.
I’ll post back if I discover any issues, but for now all is well.
@baldeagle072, The code seems to work but for some reason the event value is reporting “0” or “1” at times. Which in return isn’t showing me present when I am or the inverse. The event values range from “present”, “not present”, “arrived”, “departed”, “0” and “1”. The virtual switch is reporting On and Off correctly. Thinking this has to be something with the “Virtual Presence using switch” code? Anyone else ever get this?
Is it the device or the SmartApp that is sending the values? What does it show in the logs?
My guess is it is the device. The SmartApp is extremely simple code and there is no reason for it to have a “1” or “0”. It must be the device. The device type is the one SmartThings published. I’m not sure what the code is in that device type.
@baldeagle072 The device is the “Simulated Presence Sensor” that is doing the reporting I think. Under current state its showing presence: 0 at the moment (see logs below). The only SmartApps that are being used are (New Person) and (Virtual Presence using switch). Virtual switch logs seem to be reporting correctly.
Simulated Presence Sensor Logs:
Date Name Value Units
2015-03-27 2:19 PM UTC - 29 minutes ago presence 0
2015-03-27 12:42 PM UTC - 2 hours ago presence not present
2015-03-27 12:42 PM UTC - 2 hours ago presence present
2015-03-27 11:35 AM UTC - 3 hours ago presence 0
2015-03-27 11:32 AM UTC - 3 hours ago presence not present
2015-03-27 11:23 AM UTC - 3 hours ago presence 1
2015-03-27 10:03 AM UTC - 5 hours ago presence present
2015-03-27 10:03 AM UTC - 5 hours ago presence not present
2015-03-27 10:02 AM UTC - 5 hours ago presence present
2015-03-27 10:02 AM UTC - 5 hours ago presence not present
Virtual Switch logs:
Date Name Value Units
2015-03-27 8:42 AM EDT - 2 hours ago switch off
2015-03-27 8:42 AM EDT - 2 hours ago switch on
2015-03-27 7:32 AM EDT - 3 hours ago switch off
2015-03-27 6:03 AM EDT - 5 hours ago switch on
2015-03-27 6:03 AM EDT - 5 hours ago switch off
2015-03-27 6:02 AM EDT - 5 hours ago switch on
2015-03-27 6:02 AM EDT - 5 hours ago switch off
2015-03-26 8:58 PM EDT - 14 hours ago switch on
2015-03-26 8:35 PM EDT - 14 hours ago switch off
2015-03-26 8:35 PM EDT - 14 hours ago switch on