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


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


#21

Thank you for the extra information. I’m going to look into the second method - I currently use Tasker to indicate if I’m home/away but I like a better background process like a piston.

Seriously, your help around here is so awesome. Thank you!


#22

@WCmore,

I just wanted to say thank you. I used your presence monitoring solution yesterday 2auk with life360 presence monitors and it is flawless


#23

Thanks for the feedback! I appreciate that…
(I forgot I had even posted that)

… oh, and welcome to the club. :grin:


#24

I forget if I posted this here or over on ST, but is there anything that works well on Android for presence that isn’t Life360? I find it invasive and creepy.

I wish I could use wifi as a trigger here, but I have wifi in my car, so I can’t make Tasker work for that. I’ve also found AutoLocation to be completely unreliable. That isn’t it’s fault, but instead Android’s fault.

Anyone got any other ideas?


#25

AutoLocation with Tasker is awesome, but it takes extreme patience to set it up.
IE: The location level can be changed, depending on other factors.
For example, extreme scan when I am within 2 miles of my home, but relaxed scanning once I am home.

If you don’t take the extra time to designate special rules, then it stays generic.


This would still work when you arrive at home or at work. (assuming there is some kind of WiFi at work)

I use “WiFi Connect” to trigger I am home… and “WiFi (Not) Near” to trigger I have left.


#26

Wifi Near actually works? I tried it many years ago, but thought it either didn’t work very well or required a lot of battery. Is that wrong?


#27

I told my Android to not go to sleep, and to keep WiFi on, even when the device is not being used. These options prevents Android from trying to conserve battery by shutting down the WiFi when it is not in use.

Once I changed those settings, WiFi Near works very well… When my phone gets about 100 feet away from my router, the WiFi Near toggles, and the command is sent to my SmartHome.


Pro Tip:

Tasker has a bunch of other settings that can be tweaked… Two of the biggest ones (in this case) are how frequently you want Tasker to work behind the scenes. (checking WiFi, checking GPS etc)

There are two main sections. One is how frequent when the screen is on, and one is how frequent you want to poll when the screen is off. (Preferences > Monitor)

Both of these influences the response time, as well as the battery consumption.


All that being said, My Tasker typically uses about 1 - 1.5% of my daily battery.
(I am not 100% confident that that number includes the WiFi antenna though)