Rule Machine: set state of virtual presence sensor?

Can the state of a virtual presence sensor be changed in Rule Machine? I have a few sources of presence information (sensors and HomeKit, each of which toggle a virtual switch) and I want to aggregate these into a single virtual presence sensor. However, I can’t find any way to set the state of a virtual presence sensor in rule machine. Am I missing something?

If your virtual presence sensor supports the Switch Capability, it would be as easy as turning it on or off to change the state of presence. On = present, Off = not present

The code is trivial, assuming you’re using a custom driver.

Not a custom driver... I used the built in “virtual presence sensor” driver. It doesn’t seem to expose a switch. I’m thinking I might have to just code this up myself.

Is there any documentation on what attributes and/or methods are required for each of the device “capabilities”?

Here you go! It is a very simple driver.

/**
 *  Virtual Presence with Switch
 *
 *  Copyright 2018 Daniel Ogorchock
 *
 *  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.
 *
 *  Change History:
 *
 *    Date        Who            What
 *    ----        ---            ----
 *    2018-08-04  Dan Ogorchock  Original Creation
 * 
 */

metadata {
	definition (name: "Virtual Presence with Switch", namespace: "ogiewon", author: "Daniel Ogorchock") {
		capability "Sensor"
		capability "Presence Sensor"
        capability "Switch"
	}   
}

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

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

def installed() {
}
1 Like

This is the best Capabilities documentation that I know of...

https://docs.smartthings.com/en/latest/capabilities-reference.html

1 Like

Well that's easy. Thanks!

2 Likes

The built in virtual presense does have a command to set presence, so you could use it with rm custom commands.

1 Like

Resurrecting this post, as I would like to be able to set virtual presence from Rule Machine without using custom commands (ugh, trying to set that up now) or a non-built-in virtual presence driver :sunglasses:

For myself and hubby, we both have a key fob presence and a phone presence. I am able to combine these in Rule Machine to try to set a virtual presence, but not finding an option for presence in the actions. I will set up custom commands but it's messy.

@bravenel, would this be feasible to add to Rule Machine?

One thing you can do tonight to solve this is use @Cobra Virtual Presence driver. It's a hybrid driver that does Presence and switch in one. You can add the switch into your RM and that will set Presence to be used.. wherever you find you need it.

As it turned out, I was confused when I first tried to set up a custom command...it was actually really easy and I got my rules all set up with those.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.