How do I track internet downtime?

So this morning I woke up to no internet service, which is rare as I have fiber. While this doesn’t bother me all that much as the majority of my gear and media is local to my network, it got me thinking that I want to receive a notification when my internet access has been restored. I’m not sure fully how to go about this and could use the communities help.

I want to receive a notification when home-assistant detects that it can ping a cloud server (says google) which I could do via a binary sensor. But what I’m not sure how to do is how do I track the amount of time between the first bad ping and the first good ping, as I want the notification to tell me how long my internet service has been down for?

I’ll probably set up the ping to be every 5 mins just to help filter out any intermittent drop outs.

Your can use a input_boolean to track the time. When ping fails then turn it off. When its back to normal than calculate the down as follows and turn the input_boolean to on.

          {% set down_time = (((as_timestamp(now()) - as_timestamp(states.input_boolean.internet_connection.last_changed))) / 60) | int %}
          {%- if down_time == 1 -%}
            "Internet was down for 1 minute"
          {%- else -%}
            "Internet was down for {{down_time}} minutes"
          {%- endif -%}  

You can use binary sensor template:

binary_sensor:
  - platform: ping
    host: 8.8.8.8
    count: 1
    scan_interval: 60
    name: Internet

8.8.8.8 is Googles DNS service.

Should read more carefully, I guess you already had this. :slight_smile:

Wow that’s a really novel and great idea. I think this solved the the last piece I needed

But that sensor will only let you know that Google’s DNS is up.

What if Google’s DNS goes down, yet your Internet connection remains up? Rare, probably, but could happen.

Ping the ISP default gateway on the WAN side instead. Or even better, use two or three ping sensors to ping several IPs such as the default gateway on the ISP side, the next hop, and your ISP DNS.

yea great point. The thought definitely crossed my mind. I should definitely ping my ISP’s services.

I got this mostly working by using Frontier’s DNS servers, but I have one question. How can I find out the IP address of the Frontier gateway?

The easiest way is to use tracert (I’m assuming Windows here but works on any OS).

Open a command prompt, then tracert to some address. Example:

c:\tracert 8.8.8.8

The first hop will be the LAN address of your router (ie. 192.168.x.x / 10.x.x.x / 172.x.x.x).

The 2nd hop should be the IP of the WAN side gateway. That’s the IP you should ping to determine if the connection is up.

Alternatively, log into your router, check the WAN settings and find the default gateway.

1 Like