Assuming you already have a Home Assistant server humming away quietly, the most important thing you’ll need for this to work is a smart plug that doesn’t rely on Wi-Fi. Because we’re restarting your router, plugs that depend on a wireless network connection won’t be able to receive the trigger to switch back on when your automation runs.
I’ve got a Zigbee network that uses IKEA smart plugs, but you could also use Matter over Thread, Z-Wave, or even a Bluetooth smart plug as long as it’s within range of a nearby adapter. We’ll be using the smart plug to power cycle our network equipment, and any non-Wi-Fi smart plug should work as long as your server remains up and running.
Though it’s not necessary, it’s also handy to have both your router and modem (assuming they’re separate devices) connected to the same smart plug via a power strip. This allows you to power cycle both with a single trigger, and means you only need to sacrifice a single smart plug. Alternatively, you can plug both devices into separate plugs and make sure you target both with your automation.
With your smart plugs paired, correctly labeled, and attached to your network equipment, it’s time to set everything up.
Home Assistant Connect ZBT-2
The Home Assistant Connect ZBT-2 supports both Zigbee and Thread, although it must be set up for use with either one of the two protocols. It offers 4x the responsiveness of the previous model, and is designed to be easy to open for modding, with accessible pins and pads.
Home Assistant Connect ZWA-2 Z-Wave Antenna
The Home Assistant Connect ZWA-2 Z-Wave antenna connects to your Home Assistant setup through a simple USB cable. Offering nearly a mile of range from the hub, you can connect Z-Wave devices even from outbuildings on your property to your Home Assistant setup with this hub.
Detecting when your internet connection goes down
There are a few ways you can detect when your internet connection is not online using Home Assistant. Some prefer to use the Healthchecks.io cron job monitoring service with its associated integration (available via the Home Assistant Community Store). Personally, I keep it a little simpler than that.
If you’re lucky enough to have a router that is detected by Home Assistant, you can use that. My TP-Link Archer AX72 router was automatically detected by the platform’s core UPnP/IGD integration and offers two handy “WAN status” triggers that I can use in automations.
For the purpose of this guide, I ignored that in favor of a simple ping operation that should work with pretty much any router. As long as your Home Assistant server is connected to the internet, you can use this to detect your connection status. To be safe, we’ll use two separate ping requests to different servers to account for any remote outages.
To get started, head to Settings > Devices & services and on the “Integrations” tab, click “+ Add Integration” at the bottom of the screen. Search for the “Ping (ICMP)” integration and add it. When prompted, enter 8.8.8.8 as the host, then finish up.
Finally, head back to the Ping (ICMP) integration and click “Add service,” then enter 1.1.1.1 as the host name, then “Submit” and “Skip and Finish.” We now have Home Assistant sending a ping every 30 seconds to Google and Cloudflare’s DNS servers.
Build your reboot automation
Finally, let’s build our automation. Click on Settings > Automations & scenes, then click “+ Create automation” at the bottom of the screen. Hit “Create new automation” when prompted, then click “+ Add trigger” and select the “Device” trigger.
Now, under the “And if” section, click “+ Add condition” and choose “Device” from the list of conditions. Now add the other DNS entry we created (in this instance, that’s 8.8.8.8). Change the condition to “8.8.8.8 is disconnected” and leave the duration blank. The automation now requires that both services be unreachable before anything will happen.
Lastly, it’s time to create a reboot sequence. Under “Then do,” click “+ Add action” and choose “Device” as an action. Now select the smart plug that’s connected to your router and modem (or add both separately, if that’s the route you’re taking) and make sure the “Action” is “Turn off” (for both, if necessary). You’ll need to use the “+ Add action” button again to add a second plug.
Lastly, use the “+ Add action” button to add the same smart plug (or plugs) with a “Turn on” action (for both). This will restart your router.
Avoiding boot loops
A boot loop could occur where your Home Assistant server keeps power cycling for as long as things appear offline. In testing this automation (which depends on the Ping (ICMP) integration), this didn’t happen. My automation required that the servers come back online before it would trigger again.
If you find that you’re getting a boot loop, you could edit your automation and use the “+ Add action” button in the “Then do” section to disable the automation after you send the “Turn on” command at the end. You can then create another automation that turns the reboot automation back on when both ping requests report a “Connected” status.
[mai mult...]