Detect internet is down and reboot modem

Seems to me that all the examples over complicate things.

Use a ping sensor.

Here’s my “router booter”:

configuration.yaml:

binary_sensor:
########INTERNET CONNECTION PING SENSORS
  - platform: ping
    host: xxx.xxx.xxx.xxx
    name: "ISP DNS Ping"
    scan_interval: 60
  - platform: ping
    host: xxx.xxx.xxx.xxx
    name: "ISP Default Gateway Ping"
    scan_interval: 60

You can ping your ISP DNS, or your ISP gateway. Gateway has the advantage is that it should always be up if your Internet connection is up.

It will be the first hop past your router if you tracert to an external IP address (ie. 8.8.8.8). So if you tracert 8.8.8.8, you’ll get:

Tracing route to dns.google [8.8.8.8]
over a maximum of 30 hops:

1 3 ms 1 ms 1 ms your local router (ie. 192.168.x.x)
2 5 ms 5 ms 6 ms your ISP router (THIS IS THE IP YOU WANT TO PING)
3 17 ms 16 ms 16 ms next hops…

Then your automation is something like:

###########REBOOT ROUTER IF NO PING
- id: '9568133497643846847'
  alias: Reboot Router If No Ping To Gateway
  trigger:
  - entity_id: binary_sensor.isp_default_gateway_ping
    platform: state
    to: 'off'
    for:
      minutes: 10
  action:
  - data:
      topic: 'cmnd/routerbooter/POWER'
      payload: "OFF"
    service: mqtt.publish
  - delay: '00:00:30'
  - data:
      topic: 'cmnd/routerbooter/POWER'
      payload: "ON"
    service: mqtt.publish
  - delay: '00:05:00'
  - data:
      message: 'Internet was down for 10 minutes. Rebooted router 5 minutes ago.'
      title: 'HOUSE: Router Reboot'
    service: notify.aaron_email

I switch the router power by directly publishing MQTT messages (for reasons) but you can perform any action.

3 Likes