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.

Do you mind sharing your code for the automation? Thanks

can you post your automation please?

can you post your completed automation? I’m looking into having a smart plug for both my router and cable modem to automatically reboot if my internet goes down

Sure, but I currently have them disabled due to issues with pfSense not coming back up properly.

Modem

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

Router :

alias: Reboot router if not pingable for 30 minutes
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.routerping
    to: "off"
    for:
      hours: 0
      minutes: 30
      seconds: 0
    trigger: state
conditions: []
actions:
  - data: {}
    target:
      entity_id: switch.power_switch
    action: switch.turn_off
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.power_switch
    action: switch.turn_on

Timer start helper


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

Timer reset helper

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

There is no YAML definition for the ping integration devices.

GoogleDNSPing :

RouterPing :

This works if I test it, for example by forcibly unplugging the modem from the router.

Somehow, it doesn’t work in an actual extended power outage, when the ISP’s power goes down too. I have not figured out why yet.

One problem is a timing issue in pfSense - it seems to hang in some cases when the ISP is in the process of powering up. Only 2 people on planet earth have reported seeing this so far, and unfortunately I’m one of the 2.

Another problem is that sometimes, my HAOS VM will not come back up after a power outage. I have seen it hang during boot, waiting for Internet access, which it never gets. That defeats the entire purpose of the automation.

Another problem I saw is that the disk array on which my HAOS VM is stored didn’t come back online. Only 2 of the 5 NVMe drives showed up in the Windows device manager somehow. This is very rare, but also seems to happen only during extended power outages. I don’t know how to reproduce it. The boot drive is SATA, and is always OK, but it’s 256GB and a bit small to have the HAOS VM on it, on top of the OS and host applications. I might be able to live with a 128GB VM size, but in the long run would probably want to buy a larger SATA boot drive. I would also need to find a way to automatically reboot the host, so that all 5 drives power up, and the array can come back online. That’s tricky to do. Probably involves using something like rsh . But if the host reboots, the VM may get corrupt. Well, it would alerady risk getting corrupt during the power outage anyway, after the UPSes run out …

TLDR :wink: I’m very far from having a system resilient to ISP & power outages, despite all the hardware I invested in, which should allow it.

Thank you!

I’m trying out a few cheap options first to see if I can get something going.

If the cheap options fail during an actual real life event, I’ll buy the $100+ options on the market which are actually made for this scenario.