Plugin Request: Geofence

Posted on
Thu Aug 10, 2023 9:51 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Plugin Request: Geofence

I'm new to your plugin., and I'm loving it.... The recent change to FindFriends bricked my ability to use indigo to location track my kids. That also forced me to figure out how to install Life360 on multiple older iPhones. For now, the app is working... even though I get a pop-up every now and then telling me the app version is no longer supported. (6 kids, I'm not forking out $$$ for 6 new phones).

Anyway... once I got all the phones set up, I was pleased with how quickly I could add L360 devices in Indigo and all the data you get from each device.

What I'd like to also do (on the indigo side) is leverage places or figure out a way to have a geofence device.

The closest I've come up with (untested) is using the Group Change Listener as a trigger to watch all the devices filtering "member_360_location" and save the triggering device to a variable. Then it gets a little tricky... A condition where any life 360 device "Life 360 Location Name" is equal to "Home" (one line per device)
Now I should have an action that will fire whenever anyone enters the "Home" location.

To use a non-place.... I think I'd have to use a condition python script to look at all plugin devices for the lat/long of a "geofence". So any L360 device moves, the trigger fires and looks at conditions to see if any of the devices have a matching lat/long. (or a partial match.... reduce the places after the decimal of the "geofence" to increase detection radius.

Anyway... other than a crazy python scripted trigger thing... any chance a geofence solution could be added to the plugin?

Bill
My Plugin: My People

Posted on
Fri Aug 11, 2023 6:20 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

I'm certainly open to it. Are you envisioning definition of the fence in Indigo (outside of the plugin), in the plugin (as a new device type), or within the Life360 app (places) ?

Posted on
Fri Aug 11, 2023 12:47 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Plugin Request: Geofence

My thought is within the plugin as a new device type, would be the most seamless. Then whenever the plugin updates (runconcurentthread?) it could bounce against the list of geofences and update those devices. Find friends is setup like that. The plugin looks at your account when you add family members, but geofence devices are indigo defined as a different device type in the plugin. I thought about looking under the hood of Glen's plugin to see how he did it. (I was also curious how he programed in radius by meter when each decimal place of a lat/long added shrinks the radius by a factor of 10.) in other words, if the user asks for a 50 meter radius... 4 decimal places is 11.1 meters, 3 decimal places is 111 meters... how do you do 3-1/2 decimal places to get a 50 meter ring?

On a plugin writing level... way above my head. Honestly I'm still surprised that the plugin I wrote works. Mostly thanks to the help I got from others on the forum while writing it.

Either way, I was going to open up the findfriendsmini plugin to see if there is some useful python tidbits or something so I could attempt a non-plugin (triggers/actions/variables) approach.

It may be more beneficial, however, to have a stand-alone geofence plugin. I know there already is one, sorta. https://www.indigodomo.com/pluginstore/121/ I believe it's currently abandoned, but it's in the indigo gethub repository. On the downside, it directly links to a couple different outside platforms (so you put in your Locative or Geofancy account information, etc., or maybe you have those accounts push a location to the plugin) Either way, it's still locked into a couple services. So, maybe the best answer would be a plugin that can leverage any plugin that spits out lat/long information? My thought is, out of the box, it would directly support Life 360 with the ability to add any device with Lat/Long. (Domopad, FindFriendsMini, maybe others).

If you could pull in Places from the app as a new device type, I'm unsure of what information it would have. Would it just turn on/off if a member entered or left or would it have a boat load of details (what members are currently at that place, when was the last time that place was occupied, who was first to enter, last to leave, etc.

Side note, I always try to think of how this is beneficial. I can pull up my phone and see where everyone is (school, work, gym, etc.) Indigo knows when they are "Home" which is good for a HOMEAutomation platform. So, if Indigo also knows where people are outside of home (in some random geofence... school, work, etc.) then what? For myself, I appreciate the granularity of it, like having better control of who gets what notification and in what format, etc. I also like having it in one place (versus toggling between Life360 app, FindFriends, etc.)

Anyway, I'm happy to help in anyway I can. Thanks for taking the time to consider this, and maybe one of the other geospatial plugin developers can assist if needed.

Bill
My Plugin: My People

Posted on
Sat Aug 12, 2023 12:24 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

I think the individual components are pretty straight forward.

1) define a circle or a polygon in a variable or a new device type
2) loop through all fences for each Life360 member and determine if it's inside a geofence

So, if the member is in a fence, then what? What if the member is in multiple fences? What's the desired state?
- update the geofence device to include the members that are in it ?
- update the member device. to include all the fences that it's currently in?

I'm thinking this through as how triggers would be used, because I think we might want to cap the number of matched fences at 1

Posted on
Sat Aug 12, 2023 12:28 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

Also, can you explain why you don't just add more Places in Life360 which would basically do all this natively?

It will show the Place (which is basically a geofence) in member_360_location state

Posted on
Sat Aug 12, 2023 2:28 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Plugin Request: Geofence

ryanbuckner wrote:
Also, can you explain why you don't just add more Places in Life360 which would basically do all this natively?

It will show the Place (which is basically a geofence) in member_360_location state


Honestly, I hadn't noticed that if a the member was in a "place" that is what populates the member_360_location state until a little while ago when my daughter got to work and her location changed from Home to H-E-B. Then, no, I don't see a need to be able to add separate locations. I still see a benefit to having the already created places as separate devices. (if it's possible to pull them into the plugin). As a bonus, it would be nice to see place specific information... like the last time that place was occupied, or how long it's been occupied (first occupant), when the last person arrived, etc.

Example use case: I would like notifications when the last person leaves "Home" for specific functions like checking all doors, the security system, etc. Likewise, I would like to have a notification when the first person gets home. With a geofence, that's 2 triggers? Without, that's a couple triggers per person with variables and such.... it would get a little messy. The occupatum plugin might work for this if I can add 360members as sensor devices to that plugin. Not sure yet.... I might give it a whirl.
Another benefit is a quick look at a "Place" to see who's there. Presently, I do this on a schedule with a script to ignore who is home, and create a list of who's not home with their current location. So I get a status of either "Everyone is home" or like now I get "Not everyone is home, Anna is at HEB"

If this helps anyone...
Code: Select all
phoneCheckMessage = ""
isHome = False

if indigo.devices[989791700].states['member_360_location'] == 'Home' \
and indigo.devices[1986325525].states['member_360_location'] == 'Home' \
and indigo.devices[1085655855].states['member_360_location'] == 'Home' \
and indigo.devices[1532170498].states['member_360_location'] == 'Home' \
and indigo.devices[315152659].states['member_360_location'] == 'Home' \
and indigo.devices[991425392].states['member_360_location'] == 'Home' :
   isHome = True


if indigo.devices[989791700].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Anna is at: " + indigo.devices[989791700].states['member_360_location'] + ", \n"

if indigo.devices[1986325525].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Bill is at: " + indigo.devices[1986325525].states['member_360_location'] + ", \n"

if indigo.devices[1085655855].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Harper is at: " + indigo.devices[1085655855].states['member_360_location'] + ", \n"

if indigo.devices[1532170498].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Mikey is at: " + indigo.devices[1532170498].states['member_360_location'] + ", \n"
   
if indigo.devices[315152659].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Rylee is at: " + indigo.devices[315152659].states['member_360_location'] + ", \n"

if indigo.devices[991425392].states['member_360_location'] != 'Home':
   phoneCheckMessage = phoneCheckMessage + "\t Vikki is at: " + indigo.devices[991425392].states['member_360_location'] + ", \n"
   
if isHome == True:
   phoneCheckMessage = "Everyone is Home."

if isHome == False:
   phoneCheckMessage = "Not Everyone is home, \n" + phoneCheckMessage

indigo.server.log(phoneCheckMessage)

Bill
My Plugin: My People

Posted on
Sat Aug 12, 2023 4:46 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

ok, I took the first cut at adding geofencing in https://github.com/ryanbuckner/life360-plugin/releases/tag/v2022.1.2

A few things to note:
1 - There is a new custom state on each member device called member_within_geofence which will show the geofence that this person is currently in
2 - Defines a new device type which is a circle geofence (lat, long, and radius (in km which I don't love but it's a first release ))
3 - I haven't added validation or exception handling so it might bomb on you

Posted on
Sat Aug 12, 2023 5:46 pm
GlennNZ offline
User avatar
Posts: 1573
Joined: Dec 07, 2014
Location: Central Coast, Australia

Plugin Request: Geofence

Hi Ryan

Well done.

You are going to have to think on accuracy as to how it plays out in Geofences, unless you have already.

Took me a while to figure out the best approach - and even in FindFriends have seperate logging only of Geofence events so could try to figure out what was happening. I recall it boiled down to a lot of entry/exits because of location inaccuracy periodically (often overnight, when phone has less GPS lock). Obviously exit triggers overnight are best avoided when false!

Basically Find data reports a horizontal accuracy in metres, and the issue was deciding whether was in a 500m Geofence, if accuracy only 400m?. Obviously the circles might overlap - but still a lot of uncertainty, and did try percentage of overlapping circles, but even this just reduces uncertainty, without removing it.

What I did was you aren’t in the Geofence unless accuracy good enough, and you can’t leave unless accuracy good enough. But for leaving if you are 2 km away, and accuracy 1km, and Geofence 500m - you are out.

Otherwise as accuracy changes will get exit, entry events regularly

Glenn


Sent from my iPad using Tapatalk

Posted on
Sat Aug 12, 2023 6:30 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

Yeah, I have a dedicated function that returns a boolean TRUE / FALSE if you're inside the fence. That way I can play with plenty of ways to calculate it.

I think @whmoorejr is looking for moire functionality for the geofence devices so I think we can come back to the accuracy later, including allowing a radius in feet instead of KM

Posted on
Sat Aug 12, 2023 10:54 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Plugin Request: Geofence

ryanbuckner wrote:
ok, I took the first cut at adding geofencing
Looks fun. I set up a fence for my house just to watch it populate all the devices. I'll add a few locations in the morning, go for a drive and see what happens. No errors thus far. Thanks for taking this on.

Bill
My Plugin: My People

Posted on
Sun Aug 13, 2023 8:56 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

ok. I know you mentioned you wanted the Fence devices to hold certain information. Let's talk about how that might work.

Posted on
Sun Aug 13, 2023 11:21 am
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Plugin Request: Geofence

ryanbuckner wrote:
ok. I know you mentioned you wanted the Fence devices to hold certain information. Let's talk about how that might work.

Attached image in reference to our private message.
Geofence-Home.png
Geofence-Home.png (45.18 KiB) Viewed 4517 times

Bill
My Plugin: My People

Posted on
Sun Aug 13, 2023 12:04 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

First step, this release allows you to define your Geofence by using the information defined in your Life360 Places

https://github.com/ryanbuckner/life360-plugin/releases/tag/v2022.1.5

Posted on
Sun Aug 13, 2023 1:40 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Request: Geofence

This release adds a few things for your testing:
1 - Adds number of members in the fence on the geofence device
2 - Adds comma delimited list of members in the fence
3 - Sets the devices state as the number of members in the fence
4 - Sets the icon to on if > 0

https://github.com/ryanbuckner/life360-plugin/releases/tag/v2022.1.6

Posted on
Sun Aug 13, 2023 1:54 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Plugin Request: Geofence

You're fast. Your updating faster than I can polk and comment. I'm checking out the latest version now.

Bill
My Plugin: My People

Who is online

Users browsing this forum: No registered users and 10 guests