I used to use Google Maps location tracking, but recently, it looks like they changed something do with their authentication, and locationsharinglib stopped being able to get the required cookie file automatically. However, I recently found out about LlamaLab’s Automate and I set about creating a flow that could serve the same purpose.
Here’s my flow that will pick up a location change, when you join your home wi-fi, or just a 15-minute interval, and send a bit of JSON to your Home Assistant via a webhook.
When you import it into Automate, you’ll need to tweak the variables that are set in the blocks in the top-left corner of the flow:
- person - Some identifier for the person who will be tracked. I recommend their name
- homeSSID - The SSID of your home network. One of the triggers for a location update is joining your home network so that “arriving home” happens in a timely fashion.
- homeassistant_internal and homeassistant_external - My router doesn’t allow NAT loopback, so I can’t access my external IP from inside my network, so homeassistant_internal is the web address from inside my LAN, and homeassistant_external is my public duckdns.org address (or the cloud webhook address if you use that). If you don’t have the NAT loopback problem, these can be the same.
- webhook_id - Whatever your webhook ID is in the automation below.
It also requires a bit of configuration in YAML to set up the device_tracker. The automation here receives the JSON via the webhook and publishes it to MQTT with the topic “location/[person]”. I had to rewrite the JSON here to ensure that some of the values got published as integers. the device_tracker component didn’t like it when they weren’t.
The “original_json” field isn’t necessary, it was just useful to look at when I was debugging things. You may find it useful if you change any elements of the flow or the automation.
The device_tracker then listens for that MQTT topic and that’s it.
automation:
- id: lat_long_presence
alias: lat_long_presence
trigger:
- platform: webhook
webhook_id: <YOUR WEBHOOK ID HERE>
action:
- condition: template
value_template: >
{{ trigger.json.gps_accuracy | int <= 300 }}
- service: mqtt.publish
data_template:
topic: 'location/{{ trigger.json.person | lower }}'
retain: true
payload: >-
{
"device_time": "{{ trigger.json.timestamp }}",
"latitude": "{{ trigger.json.latitude }}",
"longitude": "{{ trigger.json.longitude }}",
"altitude": "{{ trigger.json.altitude }}",
"battery_level": {{ trigger.json.battery_level | int }},
"battery_charging": "{{ trigger.json_battery_charging }}",
"gps_accuracy": {{ trigger.json.gps_accuracy | int }},
"provider": "{{ trigger.json.provider }}",
"trigger": "{{ trigger.json.trigger }}",
"original_json": "{{ trigger.json }}"
}
device_tracker:
- platform: mqtt_json
devices:
my_device_tracker: location/<YOUR PERSON ID>
Hope you guys find this useful!