Add an "Error Handler" block to Automations and Scripts #3328
Unanswered
rvst1104
asked this question in
Automations & scripts
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature
Currently, if any action within an automation or script sequence fails, the entire sequence halts immediately. The proposal is to introduce a dedicated on_error block that can be added to the definition of an automation or script.
This block would contain its own sequence of actions that are triggered if, and only if, an action in the main sequence fails (e.g., device unavailability, API error, template error). When a failure occurs, execution of the main sequence stops, and the system immediately transitions to running the actions defined within the on_error block. This allows for centralized, simple, and reliable error management across the entire automation.
Use cases
Critical Failure Notifications: Send a priority notification if an essential automation (like security systems, water leak shutoffs, or HVAC control) fails, rather than a failure going unnoticed.
Graceful Degradation: Implement fallback actions if a primary device fails. For example, if a main light bulb is unavailable, the error handler could try a secondary lamp or log a specific diagnostic message instead of the whole automation failing silently.
System State Cleanup: If an automation manages helpers or input_booleans and fails mid-sequence, the error handler can reset those states to ensure subsequent runs are not broken.
Contextual Logging: Automatically trigger a specific logging service call when an error occurs, capturing relevant details about the state of the system at the time of failure.
Current workarounds
Presently, the only way to manage failures effectively is to use the continue_on_error: true key on individual actions, followed immediately by heavy choose or if/else conditional blocks to check the outcome and execute fallback logic.
While functional, this approach:
Significantly increases the complexity and YAML overhead for even simple error tracking.
Makes the automation UI editor difficult to use and understand.
Requires the user to anticipate every potential failure point individually, rather than handling errors globally for the automation.
Anything else?
The concept of a localized, high-level error handler for workflows is a established pattern in enterprise logic engines, such as the ServiceNow Flow Error Handler. Bringing a similar concept to Home Assistant would dramatically improve the reliability and debuggability of complex user-created systems.
Below is a mock-up illustrating how this concept could be integrated into the Automation/Script UI editor, showing a clear separation between the main sequence and the error handling sequence.

Here is a concept of how the YAML might look:
Beta Was this translation helpful? Give feedback.
All reactions