Reboot Router with Zigbee Switch Automation Help

I have a Mi power plug ZigBee (ZNCZ02LM) and I want to use it to reboot my router when my internet goes down. I’m using a ping binary sensor as suggested here, but I want to take it a step further, but I’m not skilled enough to do this. Is anyone able to help me or at least point me in the right direction?

So I currently have my binary sensor as follows

binary_sensor:
  - platform: ping
    host: 8.8.8.8
    count: 2
    scan_interval: 900 # 15 minutes
    name: "Internet Connection"

And then my current automation is as follows:

id: reboot_router
alias: Reboot Router when Internet Down
trigger:
- platform: state
  entity_id: binary_sensor.internet_connection
  from: "on"
  to: "off"
action:
- service: switch.turn_off
  data:
    entity_id: switch.0x00158d00028caf80_switch
- delay: 30
- service: switch.turn_on
  data:
    entity_id: switch.0x00158d00028caf80_switch

Which hasn’t actually triggered yet, so I hope it works!

Anyway, what I would actually ideally like is to have my first binary sensor ping every 15 minutes like it currently does, BUT, when it goes down, I would like to trigger another binary sensor to ping the exact same every 30 seconds, and if it stays down for more than 2 minutes, then trigger the reboot and start the cycle all over again. I’m just at a loss with how to add the second trigger in the mix or if this is even possible. Any help would be much apprecited.

TIA :smile:

there’s no way that I know of to control a binary_sensor like that.

But…you could have two ping sensors running all the time - one running every 15 minutes and another running every 30 seconds.

then in your automation use the 30 second sensor being off for 2 minutes as the trigger but use a condition that the 15 minute sensor is off too.

2 Likes

Hmm, thanks for the suggestion. The main reason I didn’t want the shorter one pinging at the same time as mainly for resources usage, but if it’s not really going to affect it then I guess I could just use the shorter one without the longer one right?

sure. whatever meets your needs. I just suggested both based on what you posted above wanting two different time frames.

1 Like

I am going to implement the same
But do often pings actually take resources? Is second ping also to 8.8.8.8 or did you ping some other addresses?

I am using also healtchecks.io and I wonder how can I use also this. Maybe ping something on healthchecks in second ping sensor?