Been experiencing a bit of an issue the last month with everything seemingly on and connected, but my Chromecast device would not connect across Wi-Fi today, and sometimes my wife says her phone is not connecting, and I’d have to reboot the home router. So, I decided to write a small routine using the Tasker app to check every 10 mins whether my phone can ping the Home Assistant server over the home LAN. If so, all good, but if not pop up an alert. It only runs this while I’m actually home. If I happen to be at home, but using mobile data, then it will still give an error as the mobile data won’t reach the internal IP address.
I’m using the Auto Location 3rd party app for Tasker, which provides more reliable geofencing status, but one could also use the standard Tasker location Profile. Basically, either of these will set a variable called %HOME to 1 if I’m at home, or to 0 if I’m away from home. Below is the Profile that triggers this: If at home it runs task Set Is Home, and if not at home (Exit action) it will run Set Not Home.
The actions are just simple ones that set a variable called %HOME and set it to 1 or 0.
The other rigger under Profiles is a time one which just runs the WiFi Test task every 10 minutes.
The Wifi Test task that runs every 10 minutes does the following:
* Creates and sets a variable called %HA_PING = 0. You can call it anything as maybe you want to ping the home router instead. We set this to 0 to check if the ping test then changes it, and to ensure it does not contain some non-zero value from a previous ping action.
* The Ping action is added and I set it to the internal IP address of my Home Assistant server. I said it can try 2 pings, and I also set a condition for IF %HOME = 1. In other words, only run this action if at home. If I did not add the condition, it would run when I’m away, and then give the ping error. One of Ping action’s fields is for Average Result Variable, and in there I just put %HA_PING. In other words, if there is an average ping result obtained, then set the variable %HA_PING to that variable (it will no longer be a 0).
* I added a Notify action but set two conditions to check before notifying: I must be at home, and the %HA_PING must equal 0. If the ping was successful, it sets %HA_PING to whatever the average result was. If it was not successful, the original %HA_PING is still 0.
* I just added an audible alert too, also based on same conditions that I must be home and the ping test did not set %HA_PING to above 0.
To see what it is does under various scenarios, you can view the variable values in the Tasker app in the VARS tab, as shown below. Below we can see both variables after a run, and they show I am at home, and the last average ping response was 29.773ms.
The Tasker app is extremely powerful and fun to use and you can automate so many things with it.