Automatically cable reboot modem when Internet is down

I have a Z-Wave smartplug on my cable modem. If my Internet goes down for an extended period of time, I want to reboot the modem, by powering it off first, then having a delay, then powering it back on.

Here is the automation I use :

alias: Reboot cable modem if no Internet for 30 minutes
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.googlednsping
    to: "off"
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.power_switch_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.power_switch_2
mode: single

Yesterday, there was an extended outage of 3.5 hours. The automation triggered once after the first 30 minutes of outage, but never again. It wasn’t until I got home and reset the modem manually that Internet came back. The outage could well have been shorter than 3.5 hours, but the XB8 gateway/modem (in bridge mode) somehow isn’t smart enough to reconnect on its own when service comes back, so a reset was necessary, whether manual or automated.

How can I make my automation trigger more than once (ie. try again every 30 minutes during an outage) ? This is primarily to keep the network going in my absence, as was the case yesterday. I actually noticed it because I tried to connect to my home VPN and it failed.

I have the same setup and the same problem. It’s quite fresh for me because the past two days Comcast has been a total piece of crap, going in and out all day. My setup works like this:

  • Created a Ping sensor to check the internet
  • When it goes down for more than 5 minutes (indicating an outage) then it enables a “restart” automation that will turn off the smart plug the modem is connected to for 30 seconds and then power it back on again
  • The automation restarts the modem up to 6 times, with a repeat for every 5 minutes (so 30 minutes total) to see if it comes up. Each time it does that it increments a Helper with how many restarts have been attempted.
  • If it’s still down then the 5 minute restart automation is disabled and the 15 minute restart automation begins, again incrementing the helper up to 16 times.
  • If it’s still down then the 15 minute automaton is disabled and a 30 minute automation runs until it comes up again
  • When it comes up the helper is set back to zero (I call it Comcast Restart Count), all restart automations are disabled and it is back to normal
  • During each step I use persistent notifications so I know what is happening and at what frequency

I used to just restart the modem in perpetuity but I would sometimes get into strange issues where the modem might take more than 5 minutes to come back up and just get restarted again, resulting in never having my Internet back until I stopped the madness. This new system has been rock solid for me. The biggest reason I wanted such an elaborate system is because I’m often out of town in my RV and cannot afford to have the Internet down at the house.

1 Like

You could use a helper timer and a couple automations.

When the binary_sensor.googlednsping goes off, start the timer. When it goes on, cancel the timer.

Change the trigger on this automation to be timer.finished of the new helper timer

And, the helper timer will survive an HA restart. The for 30 minutes you have will not.

Wouldn’t timer.finished trigger only when the Google DNS ping has already come back online, if I implemented what you proposed ?

@CO_4X4,
Would you mind posting your working automations for this for inspiration ?

Yes. But, you keep running it.

Timer should start when ping does not work (new automation). Then, run for 30 minutes.

When timer finishes, run your above automation and restart timer.

And, a new automation that cancels the timer when the ping works.

1 Like

Thanks. This works !

It requires 3 automations, though. And the duration of the timer has to be input twice, each time the timer is started. Is there any way to avoid that duplication ?

Yes. Three automations. It is what it is.

But, once the timer is setup, do you really need to set the number of minutes (I think that is what you are saying) multiple times? I was thinking restart just started over.

Can you show what you have setup so we can discuss?

1 Like

I haven’t tried restarting the timer without specifying the time. I don’t know if it would run for the previously set amount of time, or if it would run indefinitely.

What I have is this :

alias: Start Google DNS ping timer for 30 minutes
description: Start timer when Google DNS becomes unreachable
trigger:
  - platform: state
    entity_id:
      - binary_sensor.googlednsping
    to: "off"
condition: []
action:
  - service: timer.start
    data:
      duration: "00:30:00"
    target:
      entity_id: timer.googlednstimer
mode: single

alias: Reset Google DNS ping timer
description: Reset timer when Google DNS becomes reachable
trigger:
  - platform: state
    entity_id:
      - binary_sensor.googlednsping
    to: "on"
condition: []
action:
  - service: timer.cancel
    target:
      entity_id:
        - timer.googlednstimer
      device_id: []
      area_id: []
    data: {}
mode: single

alias: >-
  Reboot cable modem if Google DNS ping timer finishes, and restart timer for 30
  minutes
description: ""
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.googlednstimer
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.power_switch_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.power_switch_2
  - service: timer.start
    data:
      duration: "00:30:00"
    target:
      entity_id: timer.googlednstimer
mode: single

According to Timer - Home Assistant (home-assistant.io)
.start will either start new or continue from where it was. So, do a .cancel then a .start.

Then, you never need to put in a duration. Only duration is done when setting the initial timer up.

1 Like

Thank you !

Actually it will, not that I care if it survives, because it’s one of the very few places where I enable and disable automation and the automation is on a time pattern, so within X minutes of restart it will try to cycle again.