Skip to main content

On-Off schedule with state persistence

Import this blueprint

My Home Assistant

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
(Home Assistant 2021.3.0 or higher)

Direct Link

Description​

This blueprint provides a simple on-off schedule, with the addition of state persistence across server reboots, powercuts, or other disruptive events which could potentially alter the expected state of the targeted entities. The automation makes sure the target is always in the expected state, even in these situations, but always leaving the freedom to manually toggle the target state as desired. It can be used on critical targets which require a simple on-off schedule during every single day.

One common scenario where this could be useful is in the case of a server reboot or shutdown. For example, let's assume you've an automation A set to turn on light L at 12:00. If for whatever reason Home Assistant goes offline at 11:59 and turns back on at 12:01, automation A scheduled for 12:00 is not executed, with the result of L not being in the state you'd expect to be, after 12:00.

Using this blueprint in the above example would have guaranteed the expected behaviour, with the automation A being run at Home Assistant startup, and setting the L state as described by the schedule.

Examples of disruptive scenarios could include server reboots, network outages or powercuts. Since every installation could be influenced by many different events and check for them in many different ways, the blueprints includes the flexibility to optionally supply a custom event type which the automation will listen to. When such event is fired, the automation is run.

The blueprint already implements the support for listening to Home Assistant startup events, but this functionality can be disabled as desired by the user.

Internally, the blueprint calculates time ranges based on the provided On-Off times, bound to the target expected state. Whenever one of the specified times is reached or a disruptive event occurs, the automation retrieves the expected state from the calculated ranges, and enforces it on the target.

Requirements​

No additional integrations or addons are required for this blueprint, since it's only based on the Home Assistant Core Integration.

If you optionally want to supply a custom event type to the blueprint, you should setup a mechanism to fire the event in any situation a state check should be performed. This could be an integration firing an event, or another automation, so any additional required setup is out of scope of this documentation.

Inputs​

Automation target Target Required

The target which the automation will turn on and off based on the provided schedule.


On Time Time Required

Time when the target should be placed in the on state.


Off Time Time Required

Time when the target should be placed in the off state.


Custom Trigger Event Text Optional

A custom event which can trigger the state check (eg. a powercut event reported by external integrations).


Trigger at Home Assistant startup Boolean Optional

Trigger the target state check and enforcement at Home Assistant startup.


Additional Notes​

This automation only provides a simple On-Off schedule. More complex situations could require a different approach to the problem. Also, be aware that running multiple automations generated with this blueprint against the same target could result in unexpected behaviour.

Changelog​

  • 2021-02-01: first blueprint version 🎉
  • 2021-10-26: Standardize blueprints structure and inputs naming across the whole collection. Improve blueprint documentation. Remove default value from required inputs. No functionality change.