esphome / esphome/feature-requests
Error handling for automation blocks
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
I propose that the syntax for an automation block be enhanced by adding keywords for error handling. For example:
```
on_...:
then:
- some.action:
- another.action:
except:
- script.execute:
id: send_notification
message: x
- light.turn_on: error_led
finally:
- script.execute: reset_to_nominal_state
```
The expectation is that an action in the `then` block may signal an error, terminating the execution of the block and triggering the automation block following `except` (with parameter `x` representing the error.)
The `finally` block will be executed either on normal termination or abnormal. The `finally` block would also be executed if the automation block was terminated by a `script.stop` action.
The definition of what constitutes an error in execution of an action will be up to the action. Most existing actions would not throw errors.
**Please describe your use case for this integration and alternatives you've tried:**
I'm working on enhancements to the `ble_client` component and actions within that component (e.g. `ble_client.ble_write`) can fail. There is currently no way to handle that. In general any action that depends on a communication channel subject to outages would have the same possibility of failure.
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Research direction
The request names no files, tests, or entry points. Start by locating automation action execution and script.stop handling, then define and test how action failures trigger except, how the error parameter is passed, and when finally runs during normal completion, failure, or cancellation.
Written by the indexing model from the issue text.
Assessment
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100