Home assistant checking if internet connection is online

@Andy_Allsopp, how did you get this chart? It looks great.

As said here…a ping sensor to a host nearby f.e. the dns server of you isp?

It’s the custom uptime card. I pair it with a ping sensor that looks to Google’s DNS server.

type: custom:uptime-card
entity: binary_sensor.internet_reachable
hours_to_show: 48
title_adaptive_color: true
status_adaptive_color: true
icon: mdi:web
update_interval: 30
severity: 10
icon_adaptive_color: true
tooltip_adaptive_color: true
alias:
  ok: Connected
  ko: Disconnected
12 Likes

thanks a lot.
just implemented it.
Even for a beginner like me, with a little research and effort, it take 20 minutes tops.

1 Like

For those still searching, here’s what I did :

  1. Creation of a binary sensor in configuration.yaml
    see here for details : Ping (ICMP) - Home Assistant
# Test internet connection
binary_sensor:
  - platform: ping
    name: Internet #(or whatever you want to name it)
    host: 8.8.8.8
    scan_interval: 60
  1. install custom:uptime-card in HACS
    Instructions here GitHub - dylandoamaral/uptime-card: Minimalistic uptime card for Home Assistant Lovelace UI

  2. Create a custom dashboard in the Lovelace config.
    In your Home Assistant home page, click the menu at the top right, click Configure UI.

http://192.168.xx.xx:8123/lovelace/default_view?edit=1

Click the menu again, then click Raw config editor.
Add the following :

      - type: custom:uptime-card
        entity: binary_sensor.internet
        hours_to_show: 168
        title_adaptive_color: true
        status_adaptive_color: true
        icon: mdi:web
        update_interval: 30
        severity: 10
        icon_adaptive_color: true
        tooltip_adaptive_color: true
        alias:
          ok: Connected
          ko: Disconnected
        resources:
          - url: /local/uptime-card.js
          - type: module

A lot of customization exist for this board, please check here for details.

10 Likes

Hi
I followed this thread to the end as I’m looking for a way to reboot my Router when my broadband is disconnected for a certain amount of time.
I have added the ping entity and it seems to work and is registering the uptime.

I have modified my config.yaml -

here’s the code:

`# Example configuration.yaml entry to ping host google DNS with 2 packets every 10 seconds.

binary_sensor:

  • platform: ping
    host: 8.8.8.8
    name: “Virgin”
    count: 2
    scan_interval: 15`

and used the HACS Uptime Card to show the connection of the Broadband over a three day interval

But now I’m stuck with how to trigger a socket to go off and on to reboot the Router. I have a few smart switches on my system so I know how to add a new one just for this purpose.

Hi Howie, bumped on this topic after browsing/searching for something and saw your issue:
In case you have not solved it yet:

alias: "Internet Down"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.virgin
    to: "off"
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: <your switch>
  - delay: 00:00:02
  - service: switch.turn_on
    data: {}
    target:
      entity_id: <your switch>

Hi Nick4,

TY, but since I set up the config.yaml with the ping and set it going, the connection hasn’t dropped !

Updated to add my solution using an automation to control a LocalBytes Smart Plug for the router power supply.

It detects the connection has dropped for 55S, warns me it’s rebooting, then cycles the power to the Router over 30S then starts watching again

I need a push or a shove to get this going. I think I messed up the sensor and don’t know where or how. I put this into my config.yaml

binary_sensor:
  - platform: ping
    name: "T-Mobile"  #(or whatever you want to name it)
    host: 8.8.8.8
    scan_interval: 60

Then in the card config on the dashboard I did this

type: custom:uptime-card
entity: binary_sensor.T-Mobile
hours_to_show: 72
title_adaptive_color: true
status_adaptive_color: true
icon: mdi:web
update_interval: 30
severity: 10
icon_adaptive_color: true
tooltip_adaptive_color: true
alias:
  ok: Connected
  ko: Disconnected
resources:
  - url: /local/uptime-card.js
  - type: module
show:
  header: false

The card shows unknown. I think I need to do something with the sensor but am having a brain fart here. Can someone point me in the right direction? I even reloaded the config.yaml.

Thanks

try binary_sensor.t-mobile

If you look in developer tools - states you should be able to find the entity and get the correct entity_id

Thanks for the reply Holdestmade

I do not find t-mobile under States in the developer section. Did I need to do something basic to get it to show up?

Thanks

Ed

Assume you have restarted after editing comfig.yaml ?

Did you reload your Ping Binary Sensor config (or just restart HA) after adding it to your config?

yes did a quick reload

Where would I reload ping binary sensor config? Sorry

apparently a quick reload doesn’t “enable” the sensor but a full restart does the trick. So I am good

Thanks for your time guys!

Ed

For an one else wanting to do this:

Another tool you could use.
Still create the ‘ping’ device tracker, and use it in here:
https://github.com/SirGoodenough/HA_Blueprints/blob/b1fd838ceab6a5c0acf556da63e9b42d41680278/Automations/Device_tracker_Monitor_and_Notifier.md.

I hate digging up old posts, but this is along the lines with what I’m trying to do. A bit of reading through the comments and my modem power is now automatically turned off/on if the internet is down for 5 minutes.

The “ping” binary_sensor is not allowed anymore:

Dies funktioniert nicht mehr in Version 2024.6.0. Bitte behebe dies vor dem Upgrade.