You can actually do two in one. With the following driver, turning the switch on makes it Present and Off makes it not-present.
/*
* Virtual Presence with Switch and delay
*
*
*
*
*
*/
metadata {
definition (name: "Virtual Presence with Switch + Dealy", namespace: "ryancasler", author: "Ryan Casler") {
capability "Sensor"
capability "Presence Sensor"
capability "Switch"
}
}
preferences {
section() {
input name: "departDelay", type: "bool", title: "Enable Delay for Departed", defaultValue: false
input name: "delayDeparted", type: "integer", title: "Number of mins for departed delay.", defaultValue: "0"
input name: "arriveDelay", type: "bool", title: "Enable Delay for Arrival", defaultValue: false
input name: "delayArrival", type: "number", title: "Number of minutes to delay arrival", defaultValue: "0"
}
}
def arrived() {
sendEvent(name: "presence", value: "present")
}
def departed() {
sendEvent(name: "presence", value: "not present")
}
def on() {
unschedule()
sendEvent(name: "switch", value: "on")
if (arriveDelay){
def delay=(delayArrival.toInteger())*60
runIn (delay, arrived)
}
else{
sendEvent(name: "presence", value: "present")
}
}
def off() {
unschedule()
sendEvent(name: "switch", value: "off")
if (departDelay){
def delay=(delayDeparted.toInteger())*60
runIn (delay, departed)
}
else{
sendEvent(name: "presence", value: "not present")
}
}
def installed() {
}