[RELEASE] OwnTracks Presence

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.

It's not too bad - you just need to open the app once, by clicking on the notification, after reboot/power on. Then it's fine till your phone next goes completely flat!

1 Like

If you're familiar with the app called Tasker, you can set up an automation to automatically restart Owntracks after each reboot. I do that so never have an interruption of service after I reboot.

It's an Android security thing so no way to get around it You just have to find a way to get the app restarted after every reboot. Either manually or via an automation using something like Tasker.

Yeah, I used Tasker many, many years ago. That way seems a little hacky when we already know other app use location in the background just fine. There are two flavors of OwnTracks on GitHub (one uses Google Play Services, one doesn't), so I might try both while it's already broken. I'll do a little exploration and get mine working before I inconvenience the wife. WAF is important, you know!

1 Like

I just installed Tasker on my wife's phone and it runs and she doesn't even know it's there. :astonished::joy:

But fewer moving parts is usually better, if you find a way to make it work without task or I'll be interested.

I'm surprised they can't fix this. I have Life360 installed on my son's phone and it starts up after a reboot.

There's a discussion about it here: Owntracks - Doesn't automatically start tracking after reboot · owntracks/android · Discussion #1095 · GitHub

EDIT: I'm not sure what the "OSM" version is but if it's the one available via github then maybe this works now?

[OSS] Allow the user to request background location permission ("All the time") in the device settings (#1255)

OpenStreetMap in lieu of Google Maps. I uninstalled the Google Play version and installed the OSS apk from GitHub. After giving it the permissions it asked for, I went to the app permissions in settings and changed the Location permission to "Allow all the time". We'll see if it works...

Edited (again to add): The first thing I noticed that is different is a persistent notification. That looks to me like it's running.

1 Like

From the discussion it suggests that you loses some stuff while gaining the no longer need to start the app. How has it been since you have swapped?

@brianwilson with this driver am I correct in saying I need multiple devices per person if I want to track different locations?

I would like to get rid of life 360 as the only reason I use that is to gain another location. I have my home as two geo fences. One is very close and the other is the whole town.

I use it so when we leave everything shuts down but if we leave the town and come back that starts the heating but leaves everything secured.

So in a ideal world I want present when we are home and region of "home". However when I'm in town it would be not present but region of "local" then the same for "work", "parents" etc. So I only need one present but multiple regions. Is this possible using the HTTP?

Yes.