A delayed Home Assistant action can be canceled by a restart. Save the shutoff as a real date and time instead, then let an automation check that deadline both when it arrives and when Home Assistant starts.

Illustration of a timed smart switch, deadline timer, and recovery after a Home Assistant restart.

This guide builds one complete timed switch: start it for 30 minutes, turn it off at the saved deadline, recover after a restart, and cancel by turning the switch off manually.

This is not a safety interlock. Home Assistant cannot deliver an off command while it, the network, or the device is unavailable. Use a hardware cutoff for anything where a missed shutoff could cause harm.

Requirements

  • A current Home Assistant installation with built-in Helpers, Scripts, and Automations.
  • A switch that Home Assistant can turn on and off. Find its entity ID under Settings → Devices & services → Entities. This example uses switch.workshop_fan; replace it in both YAML examples.

1. Create two helpers

Go to Settings → Devices & services → Helpers → Create helper. Create a Date and/or time helper named “Timed switch deadline” with both Date and Time enabled. Leave its initial value unset so Home Assistant restores its previous state. Then create a Toggle helper named “Timed switch active” and leave it off.

The examples assume the IDs input_datetime.timed_switch_deadline and input_boolean.timed_switch_active. If Home Assistant assigns different IDs, replace them throughout. The deadline needs both date and time; a time-only helper would repeat each day.

2. Add the start script

Go to Settings → Automations & scenes → Scripts → Create script → Create new script → Edit in YAML. Paste this and save it as “Start timed switch”:

Run the script with Minutes set to 30. Run it again to replace the active deadline and start a fresh interval. You can add this script to a dashboard button.

3. Add the shutoff and recovery automation

Create an automation, choose Edit in YAML, paste the complete automation below, replace the switch entity ID, and save:

The time trigger handles normal expiry. The Home Assistant start trigger catches up if the deadline passed while Home Assistant was stopped. The switch-on trigger also catches up if the device reconnects and reports on after the deadline. A manual switch-off clears the active flag. The deadline check requires both the active flag and an on switch, so turning the switch on manually does not enroll it in a timed run.

4. Verify it

The YAML was parsed and the decision logic simulated offline, but this setup was not loaded into Home Assistant or tested with a device. Test on a noncritical switch first. Then:

  1. Run the script for 1 minute. Confirm the switch and active helper turn on and the deadline is about a minute ahead.
  2. Wait for the deadline. Confirm both switch and helper turn off.
  3. Start another run, turn the switch off manually, then wait past the old deadline. It should remain off and the helper should stay off.
  4. Start a run with several minutes remaining and restart Home Assistant. Confirm the switch stays on and turns off at the original deadline.
  5. For catch-up, stop Home Assistant until after a run’s deadline, then start it. When the switch entity is available, confirm it is turned off and the helper cleared.

If an action fails, inspect the automation’s Traces, confirm it is enabled, and check the entity IDs and helper states. Check Settings → System → Logs for a failed switch service call. A device that reports state slowly can delay recovery.

Limitations and removal

This controls one switch and stores one run at a time. The off command can fail if Home Assistant, the network, or the switch is unavailable. It is not protection against flooding, fire, overheating, or other hazards. Use a device’s own cutoff or an appropriately rated hardware timer where a missed command would be dangerous.

To remove the setup, disable and delete the automation, delete the script, then delete both helpers. This does not change the device or its integration.

Why store a deadline?

An automation delay or a trigger’s for: period is reset when automations reload or Home Assistant restarts. A date-and-time helper can be used directly by a time trigger and restores its prior state when no valid initial value is set. The startup trigger handles a deadline that passed while Home Assistant was down. See Home Assistant’s automation trigger guide, input datetime documentation, set input datetime action, time trigger reference, and Home Assistant start trigger.

The restart problem also appears in community questions about timed switch-offs, including a 2026.7 beta discussion. That discussion is a signal of reader demand; the implementation here follows the official documentation.

Leave a comment