After much experimentation with device tracking, the following method has to be one of the simplest and yet very configurable through Tasker. I.e. if connected to known WiFi send fixed location, I.e. home or work. Otherwise send GPS coordinates.
Start by creating adding an mqtt_json type device_tracker in your configuration.yaml
device_tracker:
- platform: mqtt_json
devices:
YourDeviceName: location/person
If your using groups add it to the default group entities then presence is shown at the top of the screen, eg.
default_view:
name: house
view: true
icon: mdi:home-assistant
entities:
- sensor.outside_symbol
- sensor.outside_temperature
- sensor.outside_humidity
- device_tracker.YourDeviceName
- group.livingroom
- group.bathroom
- group.others
- group.bedrooms
If you don’t already have tasker, install it, and follow this guide:
Tasker service trigger with auth
Big thanks to bokub for that!
Test it by toggling a light or switch as in the above guide. Once you have that working simply add the location reporting as follows:
Create a task (+) and give it a name e.g “Get Location”
Add an action to task->Location->Get Location, Source=GPS, timeout=100s.
Then format the coordinates ready to send to home assistant by adding another action to the “Get Location” task ->Variable->Variable Split, Name=%LOC, Splitter=,
Create another task (+) and give it a name such as “Send Location MQTT”
Add action to task->Task->Perform Task, name “Call HASS” as in above example.
Set Parameter 1=/api/services/mqtt/publish
Set Parameter 2=
{"payload": "{\"longitude\": %LOC2,\"gps_accuracy\": %LOCACC,\"latitude\": %LOC1,\"battery_level\": %BATT}", "topic": "location/person", "qos": 0,"retain": 0}
Now create a task with the 2 actions above added and call it something like “Send Location to HASS”
Add action to task->Task->Perform Task, name “Get Location”
Add action to task->Task->Perform Task, name “Send Location MQTT”
In Tasker go to the profiles tab and add a Time profile.
Set it to run from 0:00 to 23:59 every 10 minutes or what ever your preference is.
And set the task to “Send Location to HASS”
Hey presto.
You might want to test the MQTT service as the above payload is easy to mess the formatting up. I used MQTTBox addon for chrome. Just listen to the topic in the payload, I.e. “location/person”