Testing for presence

I’m writing a smartapp that will notify me when someone knocks at the door. Now I want to add logic to not do so when I’m not home by testing for the presence of my phone. Currently, I have this:

section ("Presence") {
	input "presence", "capability.presenceSensor", title: "presence",
    required: true, multiple: false

if (presence.value == "not present") {

The last line gives an error. It donest like “.value”. I’ve tried it without it and it evalutes to false when the phone is not present. The documentation only shows how to test via a subscription. Do I need to subsribe and save the state to test when someone knocks at the door?

Try using .latestValue() instead.

1 Like

I tried it and it didn’t error out. It returns null, however when my phone is not present. I’m using a virtual phone in the simulator. I’ve also tried it with the actual device with the same results.


Nop, that’s errors out. Isn’t there documentation on this some where?


Fixed it. I wasn’t doing the test correctly. This worked:

if (presence.latestValue("presence") == "not present") {