[Resolved] Life360 presence 1st home, Last Home, etc


#1

1) Give a description of the problem
I have added Life360 presence in Smarthings IDE and configured it with the Life360 Circle, Life360 Places and Life360 Users. Our names now show up correctly in Webcore to be used in a condition.

The presence indicator from Life360 into Webcor is working correctly for each individual as I can setup pistons to change a variable based on when each person comes and goes. This is working correctly as I have tested it.

I am trying to create three pistons that execute based on:

  1. First Family Member to Arrive at home (we both arrive together or if no one is already home)
  2. Last Family Member to Leave at home (If the other member has already left)
  3. Last Family Member to Arrive at home (Even if the other member is already home.)

With these I wanted to change the value of a Global Variable, that I would use to execute pistons when the change occurs. I was going to use a Boolean Variable for each.

However I a not quite clear on the best logical approach to use. I would appreciate some guidance please.

2) What is the expected behaviour?
As a test I wrote the piston below, for #1 First Family Member to Arrive at home. Unfortunately, it did not work correctly. As I was home and then later the second member came home but the message still appeared.

3) What is happening/not happening?
The message still appeared but should not have.

**4) Post a Green Snapshot of the piston![image|45x37](

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

You might try using an Integer count of how many people are present instead of booleans. (If @PresenceCount is 0, no oneā€™s at home. ā€œFirst Family Member is Homeā€ PUSHes when @PresenceCount=1.)
You can set this by counting whenever a presence change occurs.
Something like this:


#3

Thank you I will give this a Try.


#4

Hi @qoheleth
Thanks for your help.

Can you please confirm the global variable type for @PresenceCount should it be Dynamic or Number (integer).

When I set it to Number (integer), with only myself at home and press the piston TEST button I get the ā€œLast Family Member has left homeā€ message. But my thinking is I should not get any message. When I switch to Dynamic this is the case No Message.

Have I got this correct?


#5

Just so you know, with the structure above, if there are two people home, and one leaves, you will get the ā€œFirst Family member is Homeā€ message.

For what itā€™s worth, I would change the global variable to a local variable. (integer) My logic is, globals are not written until the piston has completed every line of code, while locals are written nearly instantly.

Also, for testing this piston, someone has to leave or return home, since pushing the TEST button does not activate the trigger.


#6

Thatā€™s true. It would be more appropriate to either say ā€œOne Family member is homeā€ or to test to see if the change is a presence sensor changing to ā€œawayā€.
The reason for using a global was that he specified that in his first post. However, if this is the only place itā€™s used, a local would definitely be more appropriate.


#7

Good catch, I did not notice that earlier.

In that case, I would still use local variables for the math and reset, but in the section where the PUSH is, that is the spot where I would update the global variable to match.

This gives you the best of both worldsā€¦


#8

One other thing to keep in mind with your original goal:

If both family members are in the same car, there is a 99% chance that they will register arriving or leaving at slightly different times. This means without some kind of conditional delay or loop that you will get two PUSH notifications back to back. (First & Last member)

Not using a WAIT is good if you want the global updating quickly, but bad if you have a bunch of complex programming happening when the first and last person arrives home.


#9

I like the idea of using a local and updating the global at the end. Iā€™ll add it to my toolbox.
In truth, Iā€™ve rarely used globals for anything other than static values that I need (or thought I would) in multiple pistons, so I hadnā€™t seen or run into the ā€œupdate upon completionā€ thing yet.
I had thought of incrementing and decrementing the count based on leaving and arriving and decided that the slight more time it takes to tally it each time will save us from all manner of people arriving/leaving simultaneously issues.


#10

It is usually noticed when changing the global midway thru the piston, and then doing another conversion or math in the same piston.


#11

Thank you @WCmore for the suggestion to make PresenceCount a local variable and explaining that the test button will not replicate the required outcome correctly. Also thank you @qoheleth ror your additional comments and insight.

I think I may have caused some confusion with my explanation of what I am trying to accomplish, apologies. The use of a Message was only for placeholders for testing. I later planned to replace each Message with a task that would update a Global Variable(s). Those Global Variable(s) when changed would execute other Pistons or be used as a condition in other Pistons.

For example, these Pistons would depending on presence turn on or off, lights or music, double check doors are locked etc.

I currently have accomplish this by using a combination of IFTTT Applets that use the Life360 triggers called ā€œFirst family member arrives at a specific placeā€ and ā€œLast family member leaves a specific placeā€ respectively, then each are connected to a Webhooks action that makes a request to a WebCoRE Piston to run when the condition is met. Each individual IFTTT applets executes an individual Piston. (Itā€™s a method I used in Stringify and it work for the most part.)
For example:

If
IFTTT executes ā€˜First_family_member_arrivesā€™
then
etc. etc.

If
IFTTT executes ā€œLast_family_member_leaves
then
etc. etc.

The issue I am having with this is sometimes IFTTT can have some latency and the applets run late, therefore the Piston runs late. My goal was to take out the two middlemen so to speak (IFTTT and Webhooks) hoping to run more efficiently. So, I attempted to build a test Piston in WebCoRE to take these functions over. I tried a number of different ways, but they failed. Hence my posting of the last Piston I attempted that failed also.

@qoheleth suggested Piston is much slicker than any of my attempts, I donā€™t use ā€œCASEā€ enough and this example demonstrates for me a great use thereof. Again, thank you.

@webcore I am definitely looking for a method that will take into consideration ā€œIf both family members are in the same carā€ or arrive simultaneouslyā€¦in other words if one phone geolocation updates before another phone updates and causes, as you have stated ā€œFirst & Last memberā€ to trigger. This is the issue I am struggling with as you can see by me trying to compensate in the first (above) posted Piston. I tried using:
If
Presence Sensor 2ā€™s presence changes to present
followed within 3 minutes by
Presence Sensor 2ā€™s presence changes to present

I have updated the Piston and posted it below based on how I was hoping it would run with each of your suggested changes. I have left the Message part in just for testing.

If someone could post a suggested alteration to this Piston that takes into consideration ā€œalmost simultaneously arrivalā€ so that only the First to arrive is the triggered, I would greatly appreciate it.


#12

Taking both of WCmoreā€™s comments hereā€™s a slight revision:
The PriorCount variable is added to take care of the situation where 1 person remains at home so it doesnā€™t send you the message that theyā€™ve just arrived.
The wait at the end should take care of the race condition where two folks arrive or leave simultaneously.


#13

Thank you qoheleth I will give it a try.


#14

I finally got a bit of freetime to test this properly. Here is an update that uses a local variable for processing, distinguishes between FirstArrived and OneRemaining, and updates the global variable on the last line.

It is important to note that this piston (as well as everything else on this page) will not prevent a double trigger if you are both in the same car. (this piston is designed to update the global as swiftly as possible)

What this means for your household:
Since you only have two Presence sensors, any time you both leave or arrive in the same car there will be two updates to the global in a very short period of time.

This means that your other piston(s) monitoring the global variable for changes, will have to be programmed with that in mind. To clarify, you will have to program the FirstArrived & LastArrived piston to be compatible with each other, since they will often fire within seconds of each other. It also means that you will have to program your OneRemaining and LastDeparted with the same carefulness.

One easy way to do this is to make the piston for FirstArrived & OneRemaining to be ultra quick (no WAITS), and on the LastArrived & LastDeparted, start them off with a 5 second WAIT. This insures that the first piston completes itā€™s execution before the other one begins.


#15

@WCmore thank you, this method is quite interesting. Let me test it a bit and I will let you know the outcome. FYI it might take a week or two as I am traveling.


#16

I confessā€¦ It is extremely rare that I help someone publicly with anything to do with presence sensors. To achieve rock-solid reliability, I always program at least two checks (using diferent methods) and only take action when both are true. (If you rely 100% on your GPS sensor, itā€™s important to remember that GPS pings can jump a half mile a couple times a day, thereby triggering lights on when you are asleep etc)

I have programmed many SmartHomes for Presence, but since no two households are alike, they are all customized, quite complex and unique to that household. There is no such thing as a ā€œuniversalā€ piston that solves all presence issues.

This is why I usually bite my tongue here when it comes to Presence Sensorsā€¦
100% reliability is never as easy as we think it will beā€¦


For a point of reference, a professional can expect to spend 5-10 hours setting it up right.
(much less than that, and you can expect false alarms within 48 hours)


#17

Do you have some examples of what you use for checks other than GPS?


#18

There are other ways, but my favorite way is when my phone arrives at home, and connects to my Router, my phone sends a command to webCoRE alerting it to my presence. When my phone disconnects, it has to be disconnected for 4 minutes (two consecutive pings) for my SmartHome to be alerted to me leaving.

I also place blocks at certain times or events so the GPS is not checked when I do not want it to be. (IE: when I am asleep)

I funnel both my GPS location and Router presence into a single Simulated Switch, and have rules in place as to when that SimSwitch gets toggled in either direction. In other words, both methods can control the SimSwitch, and I use the SimSwitch as a condition in many pistons to determine if I am home or not.

This way, when my GPS location briefly jumps a mile, my SimSwitch is not changed, and no false alarms are created.


The only downside to this method is when I leave for real, the SimSwitch is not flipped until 4 minutes after I pull out of the driveway. But I have coded around this logic, so it is all good.


Using Life360 for two people
#19

How do you achieve the phone+router business?

I currently use Tasker to determine if Iā€™m connected to home wifi.


#20

You can either:

  1. Tell Tasker, if your phone connect to your Router, then send a ā€œHTTP Getā€ command to directly execute a pistonā€¦ When you are no longer near that Router, then execute another piston. or
  2. Make a piston to ping your Routerā€™s config page every couple of minutes. When it finds your Phone in the list, it execute a piston. When it does not find the phone, it executes another piston.

I generally prefer the second method. Itā€™s a bit more logic and programming, but it has zero battery drain on my phone, and does not require Tasker at all. Plus, it is easier to expand for all household members, without programming each phone independently. (similar example can be found here)

Itā€™s also important to note that kids cannot bypass the 2nd method aboveā€¦ unless they leave their phone at home when they sneak out, LOL

No matter what path you decide to take, the real key is the receiving piston for arrivals happens instantly (turns on SimSwitch), but the exit has extra code in place so it has to happen twice in a row before deciding that I am no longer home. (and turns off the SimSwitch)

A slight variation of this is the Exit piston will only turn off the SimSwitch if both GPS and Router both say that I am away.