Skip to content

Instantly share code, notes, and snippets.

@tathamoddie
Created August 7, 2023 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tathamoddie/7b54f53b0e2b25936afcafcbe5ba826c to your computer and use it in GitHub Desktop.
Save tathamoddie/7b54f53b0e2b25936afcafcbe5ba826c to your computer and use it in GitHub Desktop.
HA automation for a router/modem watchdog
alias: "[Tech] Router Watchdog"
mode: single
trigger:
- platform: state
entity_id:
- binary_sensor.ping_udm_ipv4
to: "off"
for:
minutes: 15
condition:
- condition: state
entity_id: binary_sensor.ping_cloudflare_dns_ipv4
state: "off"
- condition: state
entity_id: binary_sensor.ping_aussie_dns_ipv4
state: "off"
action:
- repeat:
until:
- condition: state
entity_id: binary_sensor.ping_udm_ipv4
state: "on"
sequence:
- service: switch.turn_off
target:
entity_id: switch.udm_power
- delay:
seconds: 5
- service: switch.turn_on
target:
entity_id: switch.udm_power
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.ping_udm_ipv4
to: "on"
timeout:
hours: 2
- if:
- condition: template
value_template: "{{ repeat.index >= 10 }}"
then:
- stop: >-
Abandoning after too many attempts, so we don't completely break
or corrupt the device.
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.ping_cloudflare_dns_ipv4
- binary_sensor.ping_aussie_dns_ipv4
to: "on"
timeout:
minutes: 5
- service: notify.everyone
data:
title: 🐶 Router Watchdog
message: Router is back online thanks to the watchdog power cycling it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment