Using Ping to determine if Router needs to be rebooted via smart switch

Hi
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 -

# 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: 10

and used the HACS Uptime Card to show the connection of the Broadband over a three day interval and that has been working well over the last few days.

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.

Considerations would be:
the interval to wait before reboot - certain amount of failed Pings.
what constitutes a failed ping ? 1000mS or ?
To cause a reboot of the Router (Smart Plug off, pause, Smart Plug on) Automations or Scene should cover that.
No more reboots for a certain time to ensure the Internet reconnects or send a warning message that reconnection has failed. Pause Pinging triggered by the Socket recycling.

I think I can work out most of the sequence of events but I cant see how a ping could trigger what does it trigger ?

I’d really be grateful of the more knowledgeable of you :slight_smile:

Something like this:

trigger:
  - platform: state
    entity_id: binary_sensor.virgin
    from: 'on'
    to: 'off'
    for:
      minutes: 3
action:
  - service: switch.turn_off
    target:
      entity_id: switch.router_power
  - delay: 5
  - service: switch.turn_on
    target:
      entity_id: switch.router_power

Now, the big issue: this is not going to work if it is a wifi smart switch. As soon as you turn off the router Home Assistant will not be able to reach the wifi switch to turn it back on.

There are a couple of ways around this:

  1. Use a zigbee or zwave smart switch
  2. Use a wifi switch flashed with Tasmota. You can issue up to 30 “backlog” commands. See: Commands - Tasmota

Awesome TY for your quick reply tom_I :slight_smile:

Where would I paste the code ?

My Router and wifi are different units - one is the Virgin Media Router → Amplfi Wifi system. Plus the RPi has a Zigbee antenna long with Tasmota smart plugs. They are from Local Bytes and all five I have work well so far.
So I can have a system contained within my house not needing the www at all. Well apart from remote access for alerts but I’m hoping to find a 4g SIM device of some sort.
All this is a desire to move away from Alexa as the wifi and/or Alexa stop working so does the house automation.

Yes but does your home assistant need to connect through the router to get to wifi devices?

E.g.

home assistant → Ethernet cable → router → Ethernet cable → wifi access point

What I wrote above you can fill out in the automation editor.

ah no it’s:

RPi →cable → Wi-Fi Access Point→ Cable→ Router→www

Thanks for the help

regards
H