Presence Detection with Arrays


#1

1) Give a description of the problem
I am trying to create a piston for presence that uses a array of global variables. However the problem is that I don’t thing that such an array type exists. I attempted to use an array of boolean’s set to the global variables, but that removes my trigger conditions if anything changes. I would be interested in any more elegant solutions (trying to make it simple for updates and such and robust such it does not fail to detect presence changes much).

2) What is the expected behaviour?
I am trying to create a piston that does the following:

  • Can use an array of global variables to track presence
  • I have independent pistons for each memeber that has a “debuffer” attached to ensure the phone is really away or home (makes sure the presence did not toggle within the last 3 minutes before setting to a new state) and sets the value to a global variable
  • I have an independent global variable for guests that is set via IFTTT
  • If someone arrives or leaves home I would like a SMS message sent out (I can do this from the independent pistons if needed
  • If someone arrives home first then a “return home” piston is called
  • If someone is the last to leave then a “leaving home” piston is called

3) What is happening/not happening?
N/A - I don’t have the piston fully coded due to lack of knowledge

4) Post a Green Snapshot of the pistonimage


#2

I accomplish this with a few pistons for various reasons (like greeting arrivals) but the simplest is to use the save matching devices into a variable when you check who is present. the logic is something like this:

device family=PS 1 and PS 2
device wasHome
device isHome

if family's presence changes then                <--trigger
  if family's presence is present then            <--condition
      save matching devices to isHome
     if count(wasHome)<1 then                      <--condition
       execute firstArrival
     end if
  else /* no one is home */
    if count(wasHome)>0 then                      <--condition
      execute lastDeparture
    endif
  end if
end if
set wasHome=isHome

You can make the wasHome a global if you want to use it elsewhere. Also, if you have separate pistons for determining presence, you could trigger this off a simulated switch that is set by each presence piston (that is what I do). I can share my pistons with you if you like. Hope this helps. Feel free to ask questions if my description above was not clear.


#3

Here’s a copy of my “presence” piston. tymi

  • The piston stores all the presence devices in an array as well as the time/date stamp of when their presence last changed.
  • The piston stores all the presence devices in an array as well as the time/date stamp of when their presence last changed.
  • The tile shows the number of people present, away, and whether one of them is connected to my guest net.
  • The tile footer shows whose state last changed and if you mouse-over the tile, the state shows the time of that event.
  • The number of “people” changes based on the number of people present up to 3+.

image image image

The bulk of this piston is dedicated to adding a little “personality” to arrivals and departures via Echo Speaks. If you don’t want that, lines 50-111 can just be deleted. I like it, the wife… not so much. :slight_smile:

You could easily change the sensors_at_home and sensors_away to global variables so you could use a count(sensors_home)==0 test to see if anyone was home in your other pistons. For my use, I just have this piston change the location mode to Home or Away as appropriate and track that in my other pistons.

Let me know if you have any questions.


#4

How would you handle that my Guest Presence sensor is not a device - it is a message from IFTTT (I have a fing box that detects my guests then turns on the guest network for them and sends a message to Webcore).

Also I am struggling at knowing WHICH sensor has arrived home or left home so I can send out a text message stating such. IS that what your $CurrentEventDevice is?

I like the way you debuffer at the bottom. That is what I was doing in a separate piston against my PS devices first than saving them to a global variable and having the global variable originally trigger my “home presence counter”


#5

I made some improvements - Do you see any issues? I have not tested the piston out yet.

Any simpler away to make two arrays equal instead of how I did it on line 82 through 85?

Is there any issues that my presence sensors will also trigger other pistons? I assume webcore can handle running two pistons at the same time?


#6

Yes, the $CurrentEventDevice variable is set to the presence sensor that triggered the event (aka, the last one to arrive or leave.

Line 35 sends out that message via a PUSH. You can just change that to an SMS message instead of a PUSH if that’s what you want. Each time someone arrives or leaves, the piston is triggered so you’ll get a notification (or SMS) each time.

As for the Fingbox, I’m not quite positive how to integrate that as I’m 100% Ubiquiti and use the SmartThings_UniFi-Presence-Sensor to track the presence of family and guests. It creates a single “Guest” device that becomes present one or more guests connect to the guest net. It really works well.

Perhaps you could use the Virtual Presence Sensor to create a virtual “Guest” device and update its presence via your piston based on the IFTTT message. I haven’t tested this (I don’t have a Fingbox) but it should work.


#7

I can’t really see if there are any issues with your update as I’m having a tough time following the logic. You have a lot there and I really can’t tell what all those counters are trying to do.

I have a single IF statement that updates to device lists each time a presence sensor changes state. I then use those to lists (sensors_at_home and sensors_away) to store the state. A simple Count() gives me what I think you’re trying to do with all those counters (e.g. how many people are present and how many are away).

I’m not saying what you have won’t work, it just seems more complicated than it needs to be to accomplish the same task.


#8

Thanks! I will play around with it and see if I can reduce the logic.