[OBSOLETE] Virtual Presence Plus (presence controlled by a virtual switch)

In the spirit of enhancing the connected world, I decided to release an Improved version of my Switch-Controlled Virtual Presence. It’s a Virtual Device type that presence can be controlled by a virtual switch. So what’s different except for a better name?

  • Responds to “arrived” and “departed” commands.
  • Easily updatable on GitHub.
  • Generally better.

GitHub Integration Info:
Owner: ajpri
Name: VPresPlus
Branch: master

Manual Install Instructions:

  1. Go to the SmartThings IDE
  2. Click “Create new device handler”
  3. Click the “From Code” tab. Paste the GitHub code linked below. Click Create
  4. Click "Publish, then “For me”
  5. Go to “My Devices” and create a new device by clicking on “+ New Device”
  6. Chose any name you want (Will show as than on app & other ST tools.
  7. Choose any Device Network ID you want
  8. Important: Select “Virtual Presence+” for Type and click Create!

Please read!:
I am an undergrad College Student. Automating my house has been a passion of mine for awhile now. Everything I’ve automated was paid for with my part-time job. Please donate with the link below. Every little bit helps!
paypal.me/ajpri
Bitcoin Address: 1pb7oUxjJnh1W9ztxqkWvdeckvtxnQ2ER

10 Likes

What does “responds to arrived and departed commands” mean here?

In the SmartThings ecosystem, Device Type Handlers can define custom commands. This will allow more SmartApps to work with the DTH.

1 Like

Thank you, this is extremely helpful.

2 Likes

I have been using Life 360. What app (suggestions please) could I use to have Life 360 trigger the Away mode of your Virtual Presence Plus? Thanks

Anybody notice that the presence sometimes shows “Departed at…” as well as showing the “not present” icon, but it is using the on/present coloring, the switch status is on, and the current state in the IDE says present? I’m using Android, and using Smart Lights and IFTTT to turn the “switch” capability on/off.
It seems to fix the status if I toggle the switch from the tile, manually.

Thoughts on if this is this a issue with the DTH or ST?

Ok, nevermind, it looks like the ST app on Android isn’t very reliable for showing the of presence “things” in the “family” tab.
I’m seeing all different combinations of incorrect…color, icon, “departed” and “arrived” timestamps…and it changes sometimes when open and close the app…

Doesn’t seem to matter if it’s this device type, the ST device, or the ST simulated device…

I’m surprised other people haven’t noticed… But I guess I’m going to inform ST.

1 Like

I’ve noticed it. But I use SmartTiles to view my presences. The background information is good, the display is not.

When adding a device what do i put under the deviceID, i know its the phone, but where do i get that id for that phone?

You can put almost anything you want! However, just make sure it not in use on the “Devices” page of the IDE site. I usually name mine “VPRES##” with ## being a number to identify it. It’s just needed for ST.

Thanks, this is very useful (especially to use with IFTTT).

One comment: in the “family” view on the ST app, these virtual presences do not have their name under the icon… It would be useful to have it displayed (especially if you have more than once instance).

I’ll answer myself… I edited to this:

// UI tile definitions
tiles {
    standardTile("presence", "device.presence", width: 2, height: 2, canChangeBackground: true) {
		state("present", action: "departed", labelIcon:"st.presence.tile.mobile-present", backgroundColor:"#53a7c0", nextState: "not present")
		state("not present", action: "arrived", labelIcon:"st.presence.tile.mobile-not-present", backgroundColor:"#ffffff", nextState: "present")
	}
	standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
		state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
	}
    standardTile("button", "device.switch", width: 1, height: 1, canChangeIcon: false,  canChangeBackground: true) {
		state "off", label: 'Away', action: "switch.on", icon: "st.Kids.kid10", backgroundColor: "#ffffff", nextState: "on"
		state "on", label: 'Present', action: "switch.off", icon: "st.Kids.kid10", backgroundColor: "#53a7c0", nextState: "off"
	}

	main (["presence", "button"])
	details(["presence", "button", "refresh"])
}

}

…so that, by the way, you still a have control (to toggle present/away) from the main screen.

1 Like

Thanks for that steller work! I’ve been busy with getting ready for back to school lately.

May I go ahead and update the DTH with your code? Credit will be given.

Sure. I’m new to ST and don’t have a programming background, so I was actually editing this to learn a bit more about groovy.

In the meantime, I did a couple of additional changes: one - which you should then also do - is remove this bit from the button tile (since it’s not the main one anymore):

canChangeIcon: false,  canChangeBackground: true

The other change I made might not suit everyone, but in my set-up I rather prefer to have the ON of the switch associated to AWAY, and OFF to PRESENT (because I interpret the switch as an alarm status, so I want it OFF when someone is present). Maybe this could be defined as a preference (I haven’t looked into how to define those yet)…?

FYI, this is the resulting code I’m currently using:

metadata {
        definition (name: "Virtual Presence Plus", namespace: "ajpri", author: "Austin Pritchett") {
        capability "Switch"
        capability "Refresh"
        capability "Presence Sensor"
		capability "Sensor"
        
		command "arrived"
		command "departed"
    }

	// simulator metadata
	simulator {
	}

	// UI tile definitions
	tiles {
        standardTile("presence", "device.presence", width: 2, height: 2, canChangeBackground: true) {
			state("present", action: "departed", labelIcon:"st.presence.tile.mobile-present", backgroundColor:"#53a7c0", nextState: "not present")
			state("not present", action: "arrived", labelIcon:"st.presence.tile.mobile-not-present", backgroundColor:"#ffffff", nextState: "present")
		}
		standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		}
        standardTile("button", "device.switch", width: 1, height: 1) {
			state "off", label: 'OFF', action: "switch.on", icon: "st.Kids.kid10", backgroundColor: "#ffffff", nextState: "on"
			state "on", label: 'ON', action: "switch.off", icon: "st.Kids.kid10", backgroundColor: "#53a7c0", nextState: "off"
		}

		main (["presence", "button"])
		details(["presence", "button", "refresh"])
	}
}

def parse(String description) {
	def pair = description.split(":")
	createEvent(name: pair[0].trim(), value: pair[1].trim())
}

// handle commands
def arrived() {
	off()
}


def departed() {
    on()
}

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

}

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

}
1 Like

I’ve been using a few of your modifications (both @ajpri and @diodorus). I’m thinking of combining it with something else I’ve done into a single git repo with a writeup on how to do presence with wifi. I know such a writeup would have helped me when I first started with SmartThings. :slight_smile:
Can you add some sort of license to your code? Maybe MIT or Apache or something?
Thanks!

Can you explain how this virtual presence sensor could work in conjunction with a zwave motion detector (or three) to prevent my alarm from automatically arming when I leave the house but the babysitter or housekeeper is present?

I’m thinking that I should create a 10 minute timer that begins when the EVERYONE LEAVES- IF no motion is registered on any sensor during those 10 minutes THEN alarm the house.

Is that the correct approach, or perhaps someone can share a better solution?

So @ajpri, please correct me if I’m wrong, but this only utilizes a ST tile to detect presence, yes?

Still learning all the wonders of ST so forgive my newbie question.

Michael

I believe you are correct. The state of presence s tied to the tile, but it can be controlled just like an appliance plug.

1 Like

You can use IFTTT to switch a presence switch on when you connect to a specific wifi SSID.

Here’s a presence switch

@ajpri and for anyone else interested,

I made a WebCore piston that checks for motion activity every 180 seconds on any of the the motion detector once my wife and I are both away from the house on the presumption that we have people present in the home that wouldn’t want all the lights shut, HVAC set away, alarm armed, etc.

The piston triggers a virtual presence switch to indicate that someone is home (housekeeper, babysitter, etc) so as to prevent the security system from being armed which otherwise occurs 10 minutes after our departure. (The “I’m Back” routine toggles the virtual presence switch back off).

For those interested:

Since this is my first Piston, I’m nervous that I’m messing up the logic- can anyone confirm that this would work as I am imagining it would?

The only pitfall I can imagine is that no motion detectors are triggered in those 10 minutes and then all those “I’M AWAY” routines run…