[TUTORIEL] Tracking GPS with Android + Tasker

Hello guys,

Here is a tutorial for those who like me, got an android phone and has played with Owntracks and have been disappointed.

In my case, Owntracks was regularly loosing connection to my MQTT broker, and I needed to refresh the app to get back the connection and the location… though I could not track myself into Gladys reliably.

I’ve managed to find a way to get this working with Takser by copying the owntracks messages.

I will present you a tutorial where Tasker run tracking GPS once my phone is in my car, and stop once I left the car. (I don’t want to track 24/7).


Apps & Account

MQTT configuration

I assume you already have a MQTT working account.

Configure the connection:

  1. Start MQTT client on your phone
  2. Click on the + button bottom right
  3. Switch to Enabled
  4. Enter a nickname for this connection
  5. Enable SSL and port if you use SSL
  6. Enter Host and port (those given by your broker)
  7. Enter Username and Password (still your broker)
  8. Enter your client ID which is your user ID in Gladys (this is the Tracker Id in owntracks)
  9. Save it

Register to the topic

  1. On the home page, click on your nickname and be sure you connect fine (it should be display Connected at the top.
  2. In the bottom field, enter owntracks/your broker login/a name you want, this is the device id in owntracks (ex: owntracks/kj8z76sk/phone1)
  3. Click on subscribe

Now, your MQTT Client app on android can connect on your broker and publish message on owntracks like topic.

Configure Takser

Now you got takser, if you just paid for this tuto, you won’t regret it, you can do so many things with it :wink:

Some stuff may be a bit different because I use takser in french.

Build the task which gonna handle the GPS tracking:

  1. Go on Task tab
  2. Click on the + in the bottom right
  3. Name the task as you want
  4. Then click again on the + to add each new action
  5. Action 1: Variable -> Affect a variable - : Name: %tracking to yes
  6. Action 2: Location -> Get a location - : Source : GPS - Follow imediatly & Keep tracking (may be not required (?))
  7. Action 3: Task -> Wait: 7 seconds (to be sure we get the location)
  8. Action 4: Variable -> Affect a variable : Name: %Location to %LOC (%LOC is builtin variable containing last location found)
  9. Action 5: Variable -> Split a variable : Name: %Location - Separator: , (We then get lat and lon)
  10. Action 6 : Plugin -> MQTT Client -> Publish Message :
  • Click on the pencil to configure your message:
  • Choose your connection you entered at the begining
  • Enter the topic you subscribed before (owntracks/login/name)
  • Enter this in message:
    {"tid": <owntrack tracker id / gladys user id>, "lat": %Location1, "lon": %Location2, "_type": "location", "tst": %TIMES, "acc": %LOCACC, "alt": %LOCALT}
  • Enable Retained
  • Save (floppy in the top right)
  • Enable Continue after task error
  1. Action 7 : Location -> Stop location
  2. Action 8 : Task -> Wait : 7 seconds
  3. Action 9 : Task -> Go to action : Action 2 & Add a condition If %tracking = yes
  4. Save this task

We then got a task which track every about 14s (you can change the wait values if you want more or less the frequency)

Now, we need a trigger when we enter the car, and when we left it.

  1. Create a new task named Entered car
  2. Create a new action Task -> Run task : the name you entered for the previous task
  3. Save it
  4. Create a new task named Left car
  5. Create a new action Variable -> Affect variable : %tracking to no
  6. Save it
  7. Go on Profile tab
  8. Create a new Profile (+)
  9. Name it as you want an select the trigger you want (in my case, it’s when Bluetooth is connected to my car)
  10. Select the Enter task Entered car
  11. Select the Exit task Left car
  12. Save the whole things, leave tasker and restart it

Let’s try manually, you can run your task manually, run MQTT client and watch if new message comes in your topic, then run the Left car (or whatever you decided to name it) task to stop it.
Then, try with the trigger, bluetooth, nfc, pugin… event in your car or wherever you want

You should see your position in Gladys

For this working, I assume you always have Data and GPS ON on your phone.
If you have rooted your phone, you can also enabled/disable data and gps with secure settings plugin in tasker on different trigger (you could enable Data/Gps and disable wifi and when you enter your car, and start waze for exemple…)

Tell me if it work for you, and don’t hesitate to tell if things are missing or wrong.


Thanks for your time !
Really good stuff for android users, not me, but I appreciate your work for the community ! :wink: