[RELEASE] Life360 with States - Track all attributes with app and driver. Also supports RM4 and Dashboards!

When setting up a rule condition using the powersource custom attribute, the rule is expecting a battery state of "battery" but "Life360 with States" is returning value "BTRY" instead, so the rule condition is never true. Is this a bug? is there a way to query device attributes as arbitrary text values instead?

The weird thing is that according to an old post, powersource use to use the value of "battery".
From this post: [RELEASE] Life360 with States - Track all attributes with app and driver. Also supports RM4 and Dashboards! - #2 by bptworld
248be4261837fdb57838b7ab12a5bbe336f79d60_2_210x374

I was on 2.6.1 but it wasn't listed in Bundle Manager so I installed the latest anyway (2.6.4). Now Bundle Manager says version is at 2.6.4 but the "Life360 with States" interface says 2.6.3.

Update: my workaround:
On battery is "NOT powerSource: dc"

Update2: workaround only partially works because rules expect powerSource values to be lowercase (eg: DC vs dc). So real workaround is to set a local variable to the value of powerSource at the top of the rule. Then have condditions to compare the local variable to "DC" and "BTRY".

1 Like

Am I missing something here:

I've added Bundle manager
Installed Life360 with States
Entered Life360 username/password

All I get is:

Life360 with States

Announcement: I'll be taking an extended break from coding. I'm not going anywhere and all code will still be available. I just won't be updating anything for a while. Thanks!

No devices created so it's doing nothing - any ideas? Thanks

Edit: It looks as though Life 360 is down. I can't login and Down Detector showing a huge spike in reports.

Hi
Is there a way to refresh the SavedPlaces?

I've added new places into life360, but only the original 3 that were there when I first set this app up are showing on the device.

Thanks

Hmm...I think that two places is the maximum you got but "address1" in device attributes shows those other saved places too. So if you want to do some automation then you should use address1 attribute.

Hi @bptworld - I was looking at your Hubitat github repo.. I was going to fork it and make a few small changes to the life360 driver -- then submit a PR if you were interested. Anyway, I noticed everything is in .zip files.

How do you view changes to the source code this way? Do these bundle/package managers only accept .zip?

Anyway, I figured if I fork it then it'd be easier to see what changes I made.. mostly for myself so I can get any future updates too.

Here's what I was changing:

I know the driver polls every X (30) seconds and because of this every 30 seconds there's a bunch of updates made to the device, including the lastUpdated time, map, etc. But, what I'm really interested in is getting notified when actual changes occur -- either the device moved or the battery level changed.

I also wanted to add accuracy to the driver - which can be used on a map to show a radius around the PIN.. it indicates the user could actually be anywhere inside that circle. accuracy is passed from the device in Life360 - at least I saw it coming from both my kids devices (iOS and Android). The smaller the circle, the more accurate the location is.
image

Here's most of the changes I've been testing with on my hub.. it's working well so far. Obviously there might be some cases I'm not considering but I wanted to at least put it out there in case it benefits anyone else too.

    if(logEnable) log.trace "In generatePresenceEvent..."

    // JP: only interested in sending updates device when location or battery changes
    // -- current values --
    def latitude = member.location.latitude.toFloat()               // current latitude
    def longitude = member.location.longitude.toFloat()             // current longitude
    def accuracy = member.location.accuracy.toFloat()               // current accuracy
    def battery = Math.round(member.location.battery.toDouble())    // current battery level
    // -- previous values (could be null) --
    def prevLatitude = device.currentValue('latitude')
    def prevLongitude = device.currentValue('longitude')
    def prevAccuracy = device.currentValue('accuracy')
    def prevBattery = device.currentValue('battery')
    if (prevLatitude != null && prevLatitude.toFloat() == latitude && prevLongitude != null && prevLongitude.toFloat() == longitude 
        && prevAccuracy != null && prevAccuracy.toFloat() == accuracy 
        && prevBattery != null && Math.round(prevBattery.toDouble()) == battery) {
        if(logEnable) log.trace "No change: lat:$latitude, long:$longitude, accuracy:$accuracy, battery:$battery"
        return
    }
    log.debug "changed: lat:$latitude (was:$prevLatitude), long:$longitude (was:$prevLongitude), accuracy:$accuracy (was:$prevAccuracy), battery:$battery (was:$prevBattery)"

EDITED to handle null values better

3 Likes

pretty interesting! I was looking for that! Can you tell me how to install it? I see Life360 with States and Life360 Tracker in the bundle section. Do I just need to copy the raw code to hubitat apps for each and then desabled life360 tracker? Jus want to be sure before to proceed! Also, what is the refreshing rate and could it be changed?

Thanks!

Hi,
sorry but I try to install it in Hubitat apps and all I can install is the driver. As soon as I try to add (BPTWorld.Life360Tracker.groovy, BPTWorld.Life360TrackerChild.groovy,BPTWorld.Life360withStates.groovy) it tells me when I hit save : file not found #include BPTWorld.bpt-normalStuff

Do you know how to install it properly?
Thanks

BPT Worlds apps are found only in Hubitat Bundle Manager, so:

  • Search for Hubitat Bundle Manager (it's in Hubitat Package Manager) and install it
  • Open Hubitat Bundle Manager and first install 'Common Stuff Library'
  • Then in Bundle Manager install the Life 360 With States

ok..I must do something wrong... I found out Hubitat bundle manager in the github repo and installed it in hubitat. But as soon as I click on it it just open the app code... I should have done it the wrong way! I m new to hubitat so not sure to understand everything!
Thanks for your help!

Ok, I installed the bundle manager by importing zip inside hubitat bundle section... But for now I only have the Location tracker user driver that is installed... I cant figure out how to install 'common stuff library' just cant find it. I have BPTNormalstuff in library section but stuck there! :slight_smile: Thanks

You have the code there but it isn't installed yet...

Once you have the Bundle Manager in Bundles, in the menu go to:

Apps > Add User App (top right corner) > Select Bundle Manager from that list and install it

Once you've done that go back to Apps in the menu and you'll see Bundle Manager. Open the app and you can do everything from there (install Common Stuff then Life360 with States)

I already look inthere but the bundle manager is not there...I can see it in bundle section but nut in new app-> create user app... I only have hubithings there... Any refresh to perform? I ll try to exit and log in...

I'm not sure. I didn't import it the way you have, I installed it from Hubitat Package Manager. To be fair it's a bit confusing but but world removed his apps from Hubitat Package Manager and created Hubitat Bundle Manager and put them there.

here what I got in bundle manager


But nothing in the new app...

@jpage4500 Rule Machine can trigger based on attribute value changes, but as far as I know, it doesn't expose the previous values... which seems to be what your modification is adding to this app.

There was some discussion about exposing previous values but I'm not sure if anything came out from it.

I'm out of ideas unfortunately. I would start again and not bother with the GitHub for this. Make sure you have Hubitat Package Manager installed then install Bundle Manager from there, then install the Life360 app from Bundle Manager.

I install virtually all my apps through Hubitat Package manager as it keeps everything up to date.

1 Like

I deleted the bundle and library...then reinstalled it and it works... But I cant find common stuff... is it this one?
image

The code snippet here is what's called every 30 seconds as a result from an API call to life360 to get the device's location/state/etc. There's a lot of logic that happens after this point but the code here will compare the location passed in with the current device's location (+ battery). If they're the same it will skip all of the extra logic which sets a bunch of device attributes.

But, my goal was to prevent all of that work if the device hasn't moved or nothing else has changed. The end result for me at least is fewer device updates being sent to my dashboards which listen to changes via the /eventstream websocket.

3 Likes

Yes thats what you want first.

@jpage4500 Thanks for your work on this. I too, have been receiving excessive "spammyDevices" notifications for this driver. I like your approach, and I will also test the changes and report back.

In the meantime, I also wanted a way to change the polling schedule. Every 30 seconds is simply overkill for my uses. I needed something more like every 20 or 30 minutes. So I have made an option which will give a few selections for adjusting that polling interval.

This is in the BPTWorld.Life360withStates parent app.

Find this line (around 283):

input(name: "logEnable", type: "bool", defaultValue: "false", submitOnChange: "true", title: "Enable Debug Logging", description: "Enable extra logging for debugging.")

And insert the following line directly below it:

input "poll", "enum", multiple: false, required: false, title: "Poll Interval: ", defaultValue: "30 Seconds", options: ["30 Seconds", "1 Minute", "2 Minutes", "5 Minutes", "10 Minutes", "20 Minutes", "30 Minutes", "60 Minutes"], submitOnChange: false

Now, find this line (around 461):

schedule("0/30 * * * * ? *", updateMembers)

Comment it out; and add the following below. Final code block should look like:

//schedule("0/30 * * * * ? *", updateMembers)

if( poll == "30 Seconds" ) {
    schedule("0/30 * * * * ? *", updateMembers)
}
else if( poll == "60 Minutes" ) {
    schedule("0 0 0/1 * * ? *", updateMembers)
}
else {
    poll = poll.replace( " Minute", "" )
    poll = poll.replace( "s", "" )
    schedule("0 0/${poll} * * * ? *", updateMembers)
}

Now, go to the Life360withStates app; open it; scroll down to "Other Options" and there will be a new option for "Poll Interval".

It will default to the original "30 Seconds" value. But if you select a different option and save; the schedule will be updated to reflect the new value.

1 Like