[RELEASE] OwnTracks Presence

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