Interesting concept, thanks for posting the snippets.
I do something very similar, but for a different reason. The URL I call every 5 minutes is a script on an external web hosting service where I have a few domains I dabble with. That script records the caller’s IP address in a text file on the server.
Thus, the scripts on the server always “know” the IP address of my external router. This can come in handy. For example I have a link that sends me to the correct HA address whether I’m home or away. That link calls another script which compares my home IP address to the one I’m currently using. If they match, t redirects to my internal (192.168…) HA address, but if not, it redirects to the external address it reads from that text file.
The check-in script also returns the IP address to the caller, so now HA also can display my home IP address:
- platform: command_line
command: python3 -c "import requests; print(requests.get('http://www.mydomain.com/myip.asp').text)"
name: home_ip
scan_interval: 300
(Yes, I’m an old Windows guy so it’s still running an old, classic ASP script. But it’s dead simple logic. You could do the same thing in PHP or any other scripting language.)
Since I already have this up, it wouldn’t be hard to add some logic to notify me if HA hasn’t “checked in” for a while, or at the very least, show on my home page when the last time was.
My point is, here’s another way to implement the regular check-in, using the command_line platform instead of rest and an automation. The main benefit here is that you can call a URL which returns some useful text (in my case, the IP address) that you can use elsewhere.
It does all depend on a reliable web hosting service. But the big names in hosting all boast uptime far better than anything I could achieve with my own hardware.