Presence Polling

I have slight modification to the Text Me When It Opens App.

 *  Text Me When It Opens and Tell me who is home. (Adapted from Text Me When It Opens @author Smart things)
 *  Author: 
preferences {
	section("When the door opens...") {
		input "contact1", "capability.contactSensor", title: "Where?"
	section("Text me at...") {
		input "phone1", "phone", title: "Phone number?"
    section("Who is home?") {
    	input "presence1", "capability.presenceSensor", title: "Who?", multiple: true

def installed()
	subscribe(contact1, "", contactOpenHandler)
    subscribe(presence1, "presence", presenceHandler)

def updated()
	subscribe(contact1, "", contactOpenHandler)
    subscribe(presence1, "presence", presenceHandler)

def contactOpenHandler(evt) {
	log.trace "$evt.value: $evt, $settings"
	log.debug "$contact1 was opened, texting $phone1"
    log.debug "$presence1.label"
	sendSms(phone1, "Your ${contact1.label ?:} was opened ${presence1.label}")

As you can see I want to poll the presence sensors prior to the sms being sent so I can get an accurate idea who is in the house.

Yes, I have teenagers…

I am struggling trying to find examples of how polling works via the different sensors.

If you have teenagerS (plural), you can have it send along all the things opened and all their labels.

You can see how it’s done by adding “multiple: true” to each device preference, then doing a join like so:

For devices like presence and contact - you don’t need to poll. They’ll fire the event when their actions are executed.

The polling is done at intervals.

What I am trying to do is before the door is opened, the presence fobs are polled to see who is in the house right before the door is opened.

If I dont do that the poll might have missed the new presence of one of my kids. I am trying to “force” an update to the hub to see if they are near as they open the door.

I am pretty new to all of this so I might not understand the event handlers. :slight_smile:

@fremenusul you don’t actually have to poll the presence tag. The tag sends events as they happen and SmartApps subscribe to the event. So if the tag is present the state changes to “present” and your SmartApp would only have to check the last state, rather than poll the device.