🏠Keep Your Smart Switches On Automatically with This Home Assistant Blueprint
Smart homes are convenient - until one of your essential devices goes offline. Maybe a smart switch stays off too long, and your lights or power monitors stop reporting. With this custom Home Assistant blueprint, you can automatically detect when a switch has been off for too long and turn it back on, keeping your automation stable and your devices online.
This automation is perfect for:
- Smart plugs that occasionally disconnect
- Network switches or relays that need to remain powered
- Critical devices like routers or NAS systems
⚙️ The Problem: Intermittent Smart Device Dropouts
Many smart plugs and switches turn off unintentionally due to network hiccups or automation conflicts. The problem? You might not notice until you lose access to something critical - like your Home Assistant hub, Wi-Fi extender, or lighting controller.
Manually checking every few minutes is tedious. That’s where this "Ensure Devices Are On" blueprint comes in.
đź§© The Blueprint Solution
This YAML blueprint checks any number of switches at a user-defined interval and automatically turns them back on if they’ve been off too long. You can also define a global exception—like an input_boolean or a switch—that pauses the automation when needed.
blueprint:
name: Ensure Multiple Devices Are On with Generic Exception
description: >
Checks specified devices at a defined interval, and if any have been off longer than a specified duration,
turns them on. Skips the check if a generic exception entity is on.
domain: automation
input:
target_devices:
name: Devices to monitor
description: The switches or devices to ensure stay on
selector:
entity:
domain: switch
multiple: true
check_interval:
name: Check Interval
description: How often to check the devices (in seconds)
default: 60
selector:
number:
min: 10
max: 3600
unit_of_measurement: seconds
min_off_duration:
name: Minimum Off Duration
description: Only turn on a device if it has been off for longer than this duration (in seconds)
default: 60
selector:
number:
min: 1
max: 3600
unit_of_measurement: seconds
exception_entity:
name: Exception Entity
description: Skip automation if this entity is on. Can be any entity that uses on/off states.
default: none
selector:
entity: {}
trigger:
- platform: time_pattern
minutes: "*"
action:
- repeat:
while:
- condition: template
value_template: "true"
sequence:
- condition: template
value_template: >
{% if exception_entity %}
{{ is_state(exception_entity, 'off') }}
{% else %}
true
{% endif %}
- repeat:
for_each: !input target_devices
sequence:
- condition: template
value_template: >
{% set device = repeat.item %}
{% set last_changed = states(device).last_changed.timestamp() | int %}
{% set current_time = now().timestamp() | int %}
{{ states(device) is not none and
states(device).state == 'off' and
(current_time - last_changed) > (min_off_duration | int) }}
- service: switch.turn_on
target:
entity_id: "{{ repeat.item }}"
- delay:
seconds: !input check_interval
mode: single
đź’ˇ What It Does
- Monitors multiple switches
- Waits a user-defined number of seconds between checks
- Turns on devices if they’ve been off too long
- Pauses all checks if the exception entity is on
đź§ How It Works
This blueprint uses a repeat loop with a delay, so you can set any interval you like—without hitting Home Assistant’s time_pattern limitations. It also casts timestamps as integers to avoid template errors when comparing on/off durations.
Each device is checked individually:
- If it’s off, and
- Has been off longer than your threshold,
→ Home Assistant sends aswitch.turn_oncommand.
⚙️ Setup Instructions
- Copy the YAML into a new Blueprint under Settings → Automations & Scenes → Blueprints.
- Select it when creating a new automation.
- Choose your switches (you can add more later).
- Set your interval and minimum off duration.
- Optionally, choose an exception entity (like an Octopus energy saving session - Not with Octopus? Sign up here).
đź§ Conclusion
With this simple yet powerful blueprint, your Home Assistant setup becomes far more resilient. No more lost switches, offline smart plugs, or random outages. Whether you’re automating lights, routers, or network gear—this template keeps everything on and running.
About the author
Tim Wilkes is a UK-based security architect with over 15 years of experience in electronics, Linux, and Unix systems administration. Since 2021, he's been designing secure systems for a telecom company while indulging his passions for programming, automation, and 3D printing. Tim shares his projects, tinkering adventures, and tech insights here - partly as a personal log, and partly in the hopes that others will find them useful.
Want to connect or follow along?
LinkedIn: [phpsytems]
Twitter / X: [@timmehwimmy]
Mastodon: [@timmehwimmy@infosec.exchange]
If you've found a post helpful, consider supporting the blog - it's a part-time passion that your support helps keep alive.
⚠️ Disclaimer
This post may contain affiliate links. If you choose to purchase through them, I may earn a small commission at no extra cost to you. I only recommend items and services I’ve personally read or used and found valuable.
As an Amazon Associate I earn from qualifying purchases.