Presence Polling


(Shangpo) #1

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, "contact.open", contactOpenHandler)
    subscribe(presence1, "presence", presenceHandler)
}

def updated()
{
	unsubscribe()
	subscribe(contact1, "contact.open", 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"
    //presence1.poll()
    
	sendSms(phone1, "Your ${contact1.label ?: contact1.name} 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.


(Im Brian) #2

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.


(Shangpo) #3

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.


(Shangpo) #4

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


(Andrew Urman) #5

@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.