A Foundational Home Assistant Automation
Welcome to the first post in a new series where I will share the foundational configurations that form the bedrock of my Thinking Home. These are the automations and scripts that work quietly in the background, ensuring everything runs smoothly, predictably, and with minimal fuss. As someone who values a smart home that just works, creating a stable and self-correcting system is paramount. Bringing order out of potential chaos is a satisfying principle, reflecting good stewardship over the technology we manage.
We begin with a solution to a problem many Home Assistant users face: the chaos of a scheduled network reboot.
The Nightly Cascade of Errors
For the sake of network stability and security, my router reboots automatically every night. While this is a best practice for network health, it is terrible for Home Assistant. At precisely 3:00 AM, the moment the network goes down, my logs begin to flood with a cascade of red error messages.
Integrations that rely on a constant network connection—like Reolink, Frigate, or my Motion Blinds—desperately try to reconnect to devices that are suddenly unreachable. This generates a storm of timeout errors, DNS failures, and connection refused messages. Not only does this make troubleshooting other issues difficult, but sometimes, integrations fail to recover gracefully once the network is back, requiring a manual restart. There must be a better way.
The Solution: The Network Reboot Handler
Instead of letting the system descend into chaos, I created an automation that anticipates the problem and manages it gracefully. I call it the Network Reboot Handler. Its strategy is simple but effective: proactively disable, wait patiently, and then intelligently re-enable.
This approach turns a chaotic event into a controlled, orderly process. This automation ensures my system remains stable, my logs stay clean, and everything comes back online reliably, every single time.
How It Works
The automation’s logic follows a clear, three-step process:
1. Proactive Shutdown: The automation triggers a minute or two before the router’s scheduled reboot. Its first action is to call a helper script that disables a predefined list of network-sensitive integrations. By disabling them, we are telling Home Assistant, “Don’t even try to connect to these devices for a little while. I know they’re going offline.” This completely prevents the flood of connection errors.
2. The Patient Wait: With the integrations safely disabled, the automation now waits for the network to come back online. It does this by monitoring a sensor that pings my router. After a reboot, when the router responds to the ping, the automation knows the router has rebooted and is accessible again. Of course, what if the network doesn’t come back? The wait has a configurable timeout. If the timeout is reached, the automation doesn’t just stop; it logs a warning, sends a persistent notification, and moves on to the final step.
3. Recovery and Re-Enabling: Using a choose
action, it checks if the wait was completed successfully.
- Success Path: If the network came back online, the automation waits for an additional ‘stabilization delay.’ This is crucial, as it gives the router and other network devices time to fully initialize before Home Assistant starts trying to connect again.
- Failure Path: If the wait timed out, it creates a persistent notification on my dashboard, alerting me that the network failed to recover.
Regardless of success or failure, the final action is always the same: it calls a second helper script to re-enable the integrations it previously disabled. This guarantees that the system always attempts to return to a fully operational state.
How to Implement This in Your Home Assistant
This automation is designed to be easily adaptable. The important settings are defined in the variables
section in the first action block for easy editing.
You can get the complete, up-to-date code from my GitHub repository:
View the Network Reboot Handler on GitHub
To get it running, follow these steps:
1. Install the Spook Integration: This automation relies on the Spook custom integration to programmatically disable and enable other integrations. You can install it easily via HACS.
2. Set Up the Ping Sensor: The automation relies on knowing when your router is back online. You may be able to use your router’s native integration, or you can use the official Ping (ICMP) integration. Add it from the Settings > Devices & Services page and provide the IP address of your router. This will create a binary_sensor
that is on
when the router is reachable and off
when it’s not.
3. Create the Helper Scripts: This is the core of the configuration. You will create two simple scripts.
- Go to Settings > Automations & Scenes > Scripts and click “Add Script”.
- Create a script named Network Reboot Handler – Disabler (
script.network_reboot_handler_disabler
). - Create a second script named Network Reboot Handler – Enabler (
script.network_reboot_handler_enabler
).
4. Find Your Integration IDs and Configure the Scripts: Now, you need to tell the helper scripts which integrations to manage. The most reliable way to get the config_entry_id
for each integration is to use the UI:
Open your Disabler script.
In the Sequence
, add an action. Type “Home Assistant Disable”.
Use the “Integration” dropdown to select the integration you want to manage (e.g., Frigate).
Change the Alias of the action to match name of the integration that is being disabled. I find this is the easiest way manage the script in YAML mode because the alias
 is human readable and config_entry_id
 contains the integration ID.
Open the YAML editor and add continue_on_error: true
 to each action so that if one of the integrations fails, the entire script won’t fail.
Repeat this process for every network-sensitive integration.
Here is an example of what your Disabler script will look like after you’ve added an action for your Frigate integration:
alias: Network Reboot Handler - Disabler
description: >-
This script disables a list of network-sensitive integrations. It is called by
the main 'System - Network Reboot Handler' automation before a scheduled
network reboot to prevent connection errors.
sequence:
- service: spook.disable_config_entry
continue_on_error: true
data:
config_entry_id: xxxxxxxxxxxxxxxx
alias: Frigate
mode: single
Do the same for your Enabler script, but use the Spook: Enable config entry
service.
5. Configure the Main Automation: Finally, open the main Network Reboot Handler
automation and edit the variables:
section:
- network_sensor: Change
binary_sensor.your_router
to the entity ID of the Ping sensor you created in step 2. - Trigger Time: Set the
at:
time in thetrigger:
section to one or two minutes before your router’s scheduled reboot. - Timers: Adjust the
network_recovery_timeout_minutes
andnetwork_stabilization_delay_minutes
to match your network’s typical reboot time.
Conclusion
This simple, robust automation has made a significant difference in the stability and reliability of my smart home. It is a foundational piece that works silently to ensure the system heals itself after a planned disruption.
Did you find this post helpful? Have you implemented something similar or have ideas to improve on this automation? If so, let me know in the comments below or on GitHub. I may feature your changes in a future update!