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.
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