[RELEASE] OwnTracks Presence

I did some Googling. I didn't realize that the Wireguard iOS app allows you to specify Wireguard On Demand when connected to cellular or not connected to home Wifi. I wish the Android app had similar. I use Tasker for that logic on my phone.

1 Like

Yes, it does. I thought the Android app also supported that, but it has been so long that my memory must be wrong.

I thought OwnTracks didn't report location on android in the background any more unless you open the app at least once after a reboot - which my family won't do?

I know for a while some android users had tasker just open the OwnTracks app one time after a reboot, but that isn't an acceptable workaround for me.

That still seems to be case and, yes, easily resolved with Tasker.

Got it.

Yeah, that's when I stopped using OwnTracks. Not going to manage a bunch of tasker rules on 4 different phones.

Life360 works in the background just fine.

@brianwilson - I'm just looking at OwnTracks as a replacement for running Life360 for my kids phones. This app seems perfect as a way to use the Hub as the server.

I just wanted to ask a couple of questions while playing around with it..

  1. Can a 'lastUpdated' field be added so I know the last time a device checked-in?
  2. Is there any way to store some kind of location 'history' so I could build some kind of route-type UI? It wouldn't have to be anything special - just a list of the last X lat/lng/radius entries or something

For reference, I'm updating my dashboard app to treat these owntracks devices the same as Life360 - by displaying a google map

3 Likes

I’m up for suggestions on how to do the history. I suppose you could use event history? Would using MQTT be a better way to implement this, perhaps? I can add a lastUpdated should be trivial to add; I’ll see what I can do.

I'd kinda like that too, if you can do it that would be nice, Brian.

Both true...needs to be opened after reboot, and I use Tasker to do so. Not an issue for me, and Owntracks is still my preferred option on Android. I use Tasker for other things as well and adding the Owntracks restart was trivial.

2 Likes

And this is why you are loved by all. :smiley:

3 Likes

Yeah, I'm sure MQTT is the right/correct way to really deal with history since it's a database (I think).. I just discovered Owntracks yesterday so I'm not really clear on it. Do most people who use it have a separate server (ie: Raspberry Pi) running the Owntracks server software? I tried reading the guide but it was more involved than I was hoping for...

Anyway, my take on this Hubitat driver is that I could skip any kind of Owntracks server and just use the Hubitat. The fact that Hubitat can be reachable via the Internet with it's cloud token kind of makes the setup a lot easier in my mind.

The location history is probably overkill -- I was just thinking of what could be done if I had that info - displaying some kind of route/path map (see docs)

I could get the activity history from MakerAPI at at least be able to come up with a couple of previous locations. Otherwise, I was just thinking maybe a single device variable (ie: history) which just contained the last 5 or so locations maybe in JSON format.

This is what I get after a reboot.. is that what you see too? bummer.. I wonder if/how other apps like Life360 get around this restriction (if they even do)

Yup - that's the warning. As I noted, Tasker handles this easily and can open the app after a reboot, but it is using a second app to make the first one work the way you want, and some folks just don't care for that additional complication.

I'm not sure about Life360, I don't want to use any third-party tracking app, Google already knows too much about my life, don't want to add another"spy."

1 Like

This has been added in the latest version.

2 Likes

Much/many thanks, Brian! :smiley:

awesome - thanks!

FWIW I figured out a quick way to add the last 10 locations. I haven't used it yet but my hope is to show a route in a google map (on my dashboard app)

I just wanted to share it in case it seems worth adding to the official driver. I could create a PR too but to be honest I've never written groovy before so I'm guessing there could be better ways to write this. But, it does work!

just 1 change to the device driver code:

		attribute "history", "STRING"

Here's the app driver code changes (line 204)

...

                     // keep location history
                     def history = myDevice.currentValue("history")
                     // add current history to front of list
                     // format: lat,lng,date
                     def dt = new Date().format("yyyyMMddHHmmss")
                     history = "${lat},${lon},${dt}\n" + history
                     // only save last 10 locations
                     def historyArr = history.split('\n')
                     if (historyArr.length >= 10) {
                         history = ""
                         for(int i = 0; i < 10; i++) {
                             if (i > 0) history += "\n"
                             history += historyArr[i]
                         }                         
                     }
                     myDevice.sendEvent(name: "history", value: history)
                     
...

The end result is a history attribute which saves the last 10 locations reported. It's just a comma-separated list (lat,lng,date) and each entry is newline separated.. JSON would be prettier but this was faster to implement.

image

3 Likes

Looks good to me. I am certainly not a groovy guru, I just build on the backs of other devs and gotten really good at google-fu when I hit a roadblock. If it meets your needs, and adds to the value of your dashboard driver, I have no issues implementing it.

4 Likes

I added this to the latest version. The only issue I noticed was that the first location will be null, but that eventually gets overwritten. I don't use OwnTracks so my testing is limited, but my single location did appear to trigger a bunch of history entries. I'd like it if someone could test to see if this code is in the right place as it is in the "location change" section and not the "transition" section. My assumption is that you'd only want the location to trigger a history record if you entered a predefined location (i.e. _type=transition) but the code is currently in _type=location function (which I believe gets called when a significant movement is made - which depends on the mode OwnTracks is running in).

2 Likes

Just an FYI for others moving to C-8...I replaced the C-7 UID in the link in the mobile app (Preferences>Connection>Host) w/my new C-8 UID and things are working fine.

3 Likes

Ugh, my wife and I just got new phones and I just saw this notification this morning. She's at work and Hubitat thinks she's home.