Tasker with Auth device tracker reporting via mqtt

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”

3 Likes

I am curious if this still works for you after the latest updates?

Hi
I’m running version 0.91.2 and it still works fine, but I notice 0.92 has been released!
I’ll give it a go later and update.

1 Like

What’s weird is I can see the MQTT messages get published, but it never registers another device tracker on HA.

EDIT:
LOL. Figured out why it wasn’t registering another device in the tracker…I had my device tracker set to NOT track new devices…derp

Glad to hear, was going to mention if you’ve got the MQTT messages coming through, that’s the tricky bit nailed.

Seems Tasker is using a bit more battery than Ariela or GPS Logger. Just trying to find the best way to track my phone using the least amount of battery possible. Ariela is winning in that department, but the data usage is ridiculous.

That’s interesting to know, I had not really considered that, however have never noticed a significant change.
FYI, Tasker has used 1.7% in 16 hours on my S9. So looking like 2.2-2.3% per day.
I can live with that, it was actually on my list to use known AP’s for location to save battery, which googling revealed Tasker can do, but never got round to it due to the GPS readings not causing an issue.

I had the option set to use “ANY” for getting the location. I will switch to GPS and run for a day and see what happens. Yesterday after I got it working, Tasker used up 6% over the course of the day, with only 2 profiles (one of them being when I get in my truck and it connects via bluetooth it becomes a hotspot, but that one only ran for about 20 minutes yesterday, while plugged into power).

I will give it a day or 2 to settle down and see what happens.

Wondering if people are still using “location push” with tasker these days.

I just started to do some automations based on proximity and I’m using the google map integration. It seems to work fine but I can see HA (or is it the secondary account) polling location every few minutes while I am working from home. I thought it would be better to have the device push location info instead - only when the device knows is outside of the home zone. I figure that should be implementable with tasker (e.g. if the home SSID or cell-id is not visibile, then start reporting location every 5’

Think it will be a resounding “no” as the app does it for you now and has done for a while. Good luck with the optimisation though!

The challenge with this is that it assumes that you fully expose your instance to the internet, which I don’t. I do expose an API endpoint specifically for Alexa to consume via reverse proxy. I could expose a second one for the app if the app had a configurable endpoint entry for this, on where to report location - I couldn’t find it though