Plugin Request: Geofence

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

Re: Plugin Request: Geofence

ok I'll hold off for a bit and let you mess around

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

Re: Plugin Request: Geofence

A couple things off hand...
I think the places radius is off. Example, my daughters work is set (on the app) as 744 feet. The plugin is pulling in .069144..... km or roughly 227 feet.

Then I have something buggy going on that I can't really put my finger on. Debug is running through names showing 6 at home, but the "home" geofence says 0 and each member geofence within = none.

But it's not consistent. Almost like only one geofence can work at a time? I edited my Home geofence, changed nothing, saved.... Home is now showing all 6, but the HEB one (where my daughter is, just went to 0.... but the debug log on her device says she is still in that geofence. I did the same in reverse... HEB changed to 1 (correct) and Home went to 0. Straight line, it's about 2.5 KM between those two points so a 0.5 km radius on each shouldn't be an issue.

Side question... how will the plugin handle a member inside of two circles at the same time?

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

Hmm, that's strange. Here are the two functions I'm using for feet to km conversion and to determine if a point is within the fence:

Code: Select all
def convertFeetToKm(self, radius_feet):
      feet_per_kilometer = 3280.84  # 1 kilometer = 3280.84 feet
      return radius_feet / feet_per_kilometer


   def isInsideGeoFence(self, device, memberLat, memberLong):
      fenceLat = device.pluginProps['geofence_lat']
      fenceLong =  device.pluginProps['geofence_long']
      fenceRadius =  device.pluginProps['geofence_radius']
      
      center = Point(fenceLat, fenceLong)
      
      memberPoint = Point(memberLat, memberLong)

      distance = great_circle(center, memberPoint).km
      
      return distance <= float(fenceRadius)


To answer your other question, are you asking about fences or Circles (which are Life360 specific) . If a person is inside 2 fences , the last fence checked by the plugin will show as positive.

I think what I need to do is remove the fence from the person, since there can only be 1. And check each person from the fence

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

Re: Plugin Request: Geofence

ryanbuckner wrote:
Hmm, that's strange. Here are the two functions I'm using for feet to km conversion and to determine if a point is within the fence:
I was just looking at the code in the plugin.py file and saw the same thing. To double check, I adjusted the radius of HEB (on the app) to 1005 feet. On the plugin, I re-pulled the places data for HEB... it was converted to 0.09332....
Between the two. 744 feet convert to .06914... and 1005 feet to 0.09332, looks like they were divided by approximately 10,750 feet to get the km. From your code, I can't figure out how it's doing that math.[/quote]

ryanbuckner wrote:
To answer your other question, are you asking about fences or Circles (which are Life360 specific) . If a person is inside 2 fences , the last fence checked by the plugin will show as positive.

I think what I need to do is remove the fence from the person, since there can only be 1. And check each person from the fence
I was talking about fences. Gets confusing since a fence is physically a circle, but the term Circle is your group of members. Since the "Place" is already contained on the person, I agree, adding the geofence to the person is redundant. I like the list of people in the geofence. That's handy.

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

I set a test case Geofence equal to my Home Place parameters and this seems to be working ok :

IMG_961E8D4A335E-1.jpeg
IMG_961E8D4A335E-1.jpeg (301.23 KiB) Viewed 4528 times

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

Re: Plugin Request: Geofence

You may have to kick someone out of the house to see it. :lol: Whenever I start/stop a geofence (make a small change to the device) then that geofence will turn on and show person(s) in it correctly and the other geofence shuts off and shows zero people (incorrect). Now make a small change to that geofence, save, and it turns on with people and the other shuts off. I've done it about a half dozen times now just to be sure.

As for the radius... I've done a couple more changes, like setting my house to exactly 1000 feet in the app and I get 0.09290303....... in the plugin. That works out to about 10763.9 feet pr KM. I'm still playing with the numbers to figure out how or where it's doing the math. The app shows feet on the GUI, are you sure that's what's pulled over? Maybe the backend is already in meters, just the app is in feet because it's a US app?

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

whmoorejr wrote:
You may have to kick someone out of the house to see it. :lol: Whenever I start/stop a geofence (make a small change to the device) then that geofence will turn on and show person(s) in it correctly and the other geofence shuts off and shows zero people (incorrect). Now make a small change to that geofence, save, and it turns on with people and the other shuts off. I've done it about a half dozen times now just to be sure.

As for the radius... I've done a couple more changes, like setting my house to exactly 1000 feet in the app and I get 0.09290303....... in the plugin. That works out to about 10763.9 feet pr KM. I'm still playing with the numbers to figure out how or where it's doing the math. The app shows feet on the GUI, are you sure that's what's pulled over? Maybe the backend is already in meters, just the app is in feet because it's a US app?


Yep, that's it. 1000 feet = 304.8 meters. 304.8 meters / 3280.84 = 0.0929030.... (what the plugin shows).

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

whmoorejr wrote:
The app shows feet on the GUI, are you sure that's what's pulled over? Maybe the backend is already in meters, just the app is in feet because it's a US app?


That was it. I changed the calculation. I've also made a change to how the fences are populated and now a person can be in more than 1 fence and the numbers should be more accurate. Ignore the state on the member, that lists the fence name. I'll prob kill that one.

Try installing this...

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

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

Re: Plugin Request: Geofence

ryanbuckner wrote:
Try installing this... v2022.1.8...

Working great. Both geofences are now running and for fun I added a 2nd home geofence with a wider radius for arrival actions (and to verify the plugin would populate both Home geofences). The radius now looks correct. I didn't notice arrival and departure time/date stamps before... which version added that?

I'm about to head to HEB to pick up my daughter from work, so I'll be able to check functionality of the arrival / departure states as well.

I really hope I'm not the only one in the indigo-verse that is excited about this change to your plugin. IMO, these are features everyone should have and be excited about.

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

ok. The enter / exit timestamps probably need some logic updates. Currently it only tracks the timestamp of the first person to enter a fence, and the timestamp where the last person left. Unlike FindMyFriends, I won't know when someone entered a geofence or how long they've been there. without somehow keeping track in the plugin.

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

Re: Plugin Request: Geofence

ryanbuckner wrote:
ok. The enter / exit timestamps probably need some logic updates. Currently it only tracks the timestamp of the first person to enter a fence, and the timestamp where the last person left. Unlike FindMyFriends, I won't know when someone entered a geofence or how long they've been there. without somehow keeping track in the plugin.
For myself, those are the only two I think I'd need or use. Since school is getting ready to start next week, I'm sure I'll have plenty of time to troubleshoot, tweak, etc. The good thing about having a bunch of kids, they will find the flaw in any system.

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

Here's the logic. I'm sure it can be improved

Code: Select all
if (memberCount > 0):
   if (prevMemberCount == 0):
      firstEnteredTimestamp = cur_date_time
      device_states.append({'key': 'first_entered_timestamp','value': firstEnteredTimestamp })
elif (memberCount == 0):
   if (prevMemberCount > 0):
      lastExitedTimestamp = cur_date_time
      device_states.append({'key': 'last_existed_timestamp','value': lastExitedTimestamp })

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

Re: Plugin Request: Geofence

ryanbuckner wrote:
I think what I need to do is remove the fence from the person, since there can only be 1. And check each person from the fence

Maybe?
Something I found beneficial to it.... I can trigger off when I enter a geofence. This might be useful when I use a wider radius home geofence for pre-arrival stuff.
I started setting up a trigger for it.... to get a notification that I can use when I'm heading home.
Device" Life360 - Bill
Member Within Geofence
Becomes Equal to "Home - Wide"

Sounds good in theory, except every time the device updates, it thinks it's "becoming equal to home-wide" and the trigger kept firing. To work around it, I'll might have to use a different approach for the trigger and use a condition or something.... I'm still thinking and poking through it. Downside, with all the data points now between people and places, there are tons of triggering options.... now to figure out what triggers can do what.

edit: Triggering off of the Places name in the MemberLocation field is solid. So if I trigger with member_360_location becomes equal to (name of place)... no problem. It just "becomes" the one time. Switching the trigger to a geofence is where it got hinky.

Your logic for time-stamping looks pretty solid to me.

what about adding
Code: Select all
if (memberCount > prevMemberCount):
  lastEnteredTimestamp = cur_date_time
      device_states.append({'key': 'last_entered_timestamp','value': lastEnteredTimestamp })
To get the time stamp of your most recent arrival.
Everything else can be computed outside the plugin if anyone wanted it. cur_date_time - firstEnteredTimestamp = how long occupied <- I think. cur_date_time - last_existed_Timestamp = how long vacant

Bill
My Plugin: My People

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

Re: Plugin Request: Geofence

ok I'll leave it for now. Anything else you can think of before I log off for the night?

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

Re: Plugin Request: Geofence

ryanbuckner wrote:
ok I'll leave it for now. Anything else you can think of before I log off for the night?


Take a break. You have been awesome with it. Next week all my kids go back to school so I’ll have tons of geofence enters and exits daily for me to play with, try out different triggers or scripts. I’d say we are good for awhile.

Bill
My Plugin: My People

Who is online

Users browsing this forum: No registered users and 6 guests