I have be thinking about a reliable method of presence detection for a while now, I have found the usual methods of router, ping or owntracks pretty unreliable.

I am now trialling a method using MQTT with the tasker android app. Tasker is a very powerfull event triggered automation application for android.

What it is doing is sending a MQTT message to your broker on connect and disconnect of your local wifi network.

You will need a MQTT broker that is externally accessible. Mine is setup to accept websocket connections that are proxied through a nginx reverse proxy via https (port 443), if you want to know about that setup I will have to do a whole new post.

You need to install (buy) Tasker and a tasker MQTT plugin, links below.

play.google.com Tasker ⚙No repetitive tasks for you, let your Android device handle it!⚙ Total Automation, From Settings to SMS. Here are only some of the things you could do with Tasker. Its real power is the flexibility to combine contexts and tasks however you wish: https://tasker.joaoapps.com/exampleuses.html ☑ Automations Make your phone a true smart phone! Why remember to change the volume every day when you leave home when your phone can do it for you? Automate stuff based on the app you're in, the time of d... $3.49

play.google.com MQTT Client Connect to any MQTT v3.1 broker and subscribe to topics. Perform Tasker actions on message publish or publish messages on tasker events. The app still might be rough around the edges. Would be releasing the code soon on github so that the development could continue over there. Tasker Integration works as follows: -To publish messages from tasker simply create a action in tasker. The configuration is pretty simple. You may use tasker variables in topic and message. -To perform action whenever ... Free

First thing you need to do is setup the MQTT Tasker plugin, it is a separate app to tasker.

Just press the 3 dots on the top right of the MQTT Tasker plugin app and select ‘Settings’. Then select ‘Server’. In there setup the server settings for your mqqt server. Remember your mqtt server must be externally accessible. SSL and password protected highly recommended.

Next is the tasker setup:

In Profiles you need to select the + at the bottom right. Then choose ‘State’ Then choose ‘Net’ Then choose ‘Wifi Connected’ In the ‘SSID’ field enter your home wifi ssid. This will then only trigger on the state for this wifi SSID only. Then go back by selecting the back arrow on the top left. A new task menu should open. Choose the ‘+’ to create a new task Name the task. I used ‘Mqtt Wifi Connected’ In the task edit select ‘+’ Choose ‘Plugin’ and select ‘MQTT Client’ In MQTT Client select the pen icon right of ‘Configuration’ Enter your MQTT Topic, Message and QOS setting you wish to use. I used ‘occupancy/homewifi’ as the topic and ‘Connected’ as the message, and QOS as 1. Select the back arrow at the top left to leave the MQTT plugin settings Then select the back arrow again to leave the ‘Action Edit’ Then select the back arrow to leave the ‘Task Edit’ You should be back at the 'Profiles" section Press and hold the green arrow on the profile you created (if you do not see the arrow just select the profile and the items should show below it), a menu should pop up, select the ‘Add Exit Task’ item. The exit task will fire when the Wifi Connected state changes from True to False (connected to disconnected) Here you are going to do almost the same again as the ‘MQTT Wifi Connected’ task you created previously but it will be the wifi disconnect event you are triggering on. Select ‘New Task’ Name it, I used ‘MQTT Wifi Disconnected’ Add an action by selecting ‘+’ Choose ‘Plugin’ and select ‘MQTT Client’ In MQTT Client select the pen icon right of ‘Configuration’ Enter your MQTT Topic, Message and QOS setting you wish to use. I used ‘occupancy/homewifi’ as the topic and ‘Disconnected’ as the message, and QOS as 1. Select the back arrow at the top left to leave the MQTT plugin settings Then select the back arrow again to leave the ‘Action Edit’ Then select the back arrow to leave the ‘Task Edit’

You should be back at the 'Profiles" section and it all should run

To debug you can enable a run log:

To do this select the 3 dots at the top right and choose ‘More’ then ‘Run Log’ Just turn it on and then you will see a log of all tasks. Then just turn your wifi on and off to see the events being triggered.

Anyway this is just another method to possibly use to add to your presence detection options. I hope this helps someone.

Here is an XML that can be used to import into tasker to ease the setup.

https://gist.github.com/coza73/60c6b602fc28c8244398dda4c4564e45