I’m a big fan of the Google Maps Timeline feature. I think it’s really cool that I can just go back, let’s say, 2 years in the past and see exactly where I was at that time. Right now, the furthest I can go back in my timeline history is something like 5 years. But I believe the nostalgia factor is going to be much bigger when I’m older and I check back to see what I was doing 30 years ago. After all, they say nostalgia is a hell of a drug.
The Quantified Self
When you think about it, humanity is at a point where they can measure, record and analyze almost every part of a person’s life using technology, almost effortlessly. We have fitness bands which can track a person’s heart beat, their breath rate, the oxygen in their blood and much more 24/7. We carry around mobile phones which contain information about who we communicate with, where we go, what we watch, the music we listen to, and so much more. We’re also starting to use smart devices in our homes which contain information about what temperature the air conditioner is set to, how often a particular device is turned on and so on. All the data is available, right now. It’s just a matter of processing it and presenting it in a visually pleasing way.
Sure, you could have done the same 50 years ago too. You could buy a diary and write down every little thing that you do in your life. But it would be really impractical and it would take up too much time to measure and write down everything. So much time in fact that that might be the only thing the person has time for. But now, with computers, it’s significantly much easier to do the same.
I could go on for a lot more about this but I think that’s a topic for another blog post. But if you’re interested in learning more about this check out these links below:
The Quantified Self - Wikipedia
Moving away from Google
While I like the UI and design of Google Maps Timeline, it’s still Google. And me being a FOSS enthusiast (I try to make sure any software I use is FOSS), I wanted to move away from them. Since I already run a homelab at home, I knew almost half the work to setup an alternative to Google Maps Timeline was already done.
The rest of the steps assume that you already have some sort of server running somewhere, that you have complete control over. If not, do check out r/homelab or r/selfhosted on how to get started on running your own home server.
I decided to go through the r/selfhosted subreddit to check for self-hosted alternatives to Google Maps Timeline. I found a few different solutions, but the most promising ones were OwnTracks and Dawarich.
OwnTracks seems to be the more established of the two, and has companion apps for both Android and iOS. You setup the OwnTracks recorder on your server and configure the app on your mobile device to report back to your server. You can then view your location history and timeline on the web interface.
Dawarich is a relatively newer project and is designed to be a much more direct replacement for Google Maps Timeline. Dawarich depends on the OwnTracks mobile apps to report GPS data, but has its own beautiful user interface to display this data.
Both these projects are amazing and are really good options to setup your own self-hosted alternative to Google Maps Timeline. But I finally decided to go another route. This was because I’m already running a Home Assistant instance at home. I also have the Home Assistant android app installed on my phone and reporting my GPS data back to my server. The idea of running another app to collect and send my GPS data back once more seemed a bit redundant.
Configuring Home Assistant
To setup Home Assistant, you can go to this link. There are multiple way to setup Home Assistant. Choose whichever method best suits you.
The Home Assistant android app allows you configure sensors to collect and send data back to your server. A lot of these sensors are disabled by default, but you can go Settings -> Companion app -> Manage sensors to enable them.
Enable the ‘Background Location’ sensor and the ‘Single accurate location’ sensor. This should provide us with enough data to track our location.
Also, if possible, try to change the ‘Sensor update frequency’ setting to ‘Fast while charging’. You can find the setting under Settings -> Companion app. This will allow much more frequent location updates if you are a person who travels by car a lot, since you’ll be plugging in your phone via USB in your car (to use Android Auto or Apple Car Play).
With this setup, you should be able to see your device’s location in Home Assistant. Home Assistant has a built in UI for viewing location history. You can see this by creating a new ‘Map’ card in the Lovelace UI, setting the entity to your mobile device and setting the ‘Hours to show’ option under ‘Appearance’ to some value like ‘24’. This will show your location history almost like in Google Maps Timeline. But this UI lacks an option to choose a time period, and has almost no customization options.
To solve this issue of lack of customization and viewing options, I decided to utilize Grafana. I already have a TIG (Telegaf, InfluxDB and Grafana) stack running to monitor my home lab and a lot of other stuff. So I decided to leverage the same to visualize my location data. (In case you do not have InfluxDB or Grafana set up, skip to this section to set it up. Then return here to configure Home Asssitant.)
To do this, first we need to get the GPS data from Home Assistant to InfluxDB2. Fortunately, there is an InfluxDB integration for Home Assistant. Assuming you already have an InfluxDB2 instance running somewhere on your network, you will just need to create a new bucket, create a token for writing and reading from that bucket, and configure the InfluxDB integration in Home Assistant.
This is how the InfluxDB configuration looks like in the configuration.yaml
file in my Home Assistant instance.
influxdb:
api_version: 2
ssl: false
host: 192.168.18.41
port: 8086
token: <influxdb2-token-for-bucket>
organization: <influxdb2-organization>
bucket: <influxdb2-bucket-name>
include:
entity_globs: "*" # You could also just include the location sensor entity, but I personally track everything from Home Assistant
With this setup, you should now be able to see GPS data being populated in your InfluxDB2 instance.
Configuring Grafana
To setup InfluxDB along with Grafana, refer to this Docker Compose file below:
services:
influxdb:
image: influxdb:latest
restart: always
ports:
- "8086:8086"
volumes:
- ./influxdb2:/var/lib/influxdb2:rw
grafana:
image: grafana/grafana-oss
user: ":"
ports:
- 3000:3000
restart: unless-stopped
depends_on:
- influxdb
links:
- influxdb
volumes:
- ./grafana-etc/:/etc/grafana/
- ./grafana-data:/var/lib/grafana
- ./grafana/sqlite-sources:/home/grafana/sqlite-sources
Write this content to a file named docker-compose.yml
, then run docker compose up -d
and you should be golden. Also make sure to add the InfluxDB2 instance as a data source in Grafana. A quick Google search should tell you how to do this.
Once you have this setup, you now need to create a ‘visualization’ to view the GPS data. To do this, create a new dashboard and add a new visualization. Here, you’ll need to choose the ‘InfluxDB2’ instance you configured earlier as your data source. Next, change the type of visualization to ‘Geomap’.
Now copy this query and paste this in the query field:
from(bucket: "home-assistant")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "device_tracker.<your-device-entity-name>")
|> filter(fn: (r) => r["_field"] == "longitude" or r["_field"] == "latitude")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group()
|> drop(columns: ["_start", "_stop", "_time","_measurement"])
Now, you need to change the ‘Layer type’ to ‘Route’. This will allow us to see the GPS points as routes in the map panel.
You will also need to change the ‘Max data points’ option under ‘Query Options’. Change the value to something high like ‘100000’. This allows Grafana to render a large number of points (since we could potentially have a huge number of geo coordinates) in one visualization.
You’re almost done now! If you need to change the type of base map layer being displayed, you can change it under ‘Layer type’ in ‘Basemap Layer’. Once that’s setup, save and apply the visualization and you should be able to see your GPS location timeline.
I’ve also added a ‘Total Distance Travelled’ visualization in the dashboard. The Flux query for it is:
import "experimental/geo"
from(bucket: "home-assistant")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "device_tracker.<your-device-entity-name>")
|> filter(fn: (r) => r["_field"] == "longitude" or r["_field"] == "latitude")
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> rename(columns: {latitude: "lat", longitude: "lon"})
|> geo.totalDistance()
Conclusion
This new setup still lacks a few features like having the name of the actual location we travelled to. But that’s something we could probably write a script for. Since we have control over the data, the types of visualizations we could create is virtually endless. We could compute the speed from the GPS data and display them along the route to show traffic data. Or we could list individual ’trips’ by filtering through durations where the GPS location doesn’t vary over a threshold. But for now, we have a working FOSS alternative to Google Maps Timeline.