mono
April 11, 2021, 8:41pm
1
It would be useful to be able to specify that an action should not prevent further execution of a script/automation upon failure.
I have a sequence of actions that first attempts to pause any playback from a specific media player (using Spotify). However, if that media player is not playing, the service call will fail and the remaining actions in the sequence will not be executed.
In the above example, I’m fortunate that I can simply re-order the actions to place the failing one at the end. However, there will be other cases where multiple steps have the potential to fail and a ‘best effort’ to complete all steps may be preferred.
My proposal would be to introduce a syntax similar to that of the wait timeouts, where a user can currently specify continue_on_timeout
with a boolean value. For actions within a sequence, a property such as continue_on_fail
could be set by the user, defaulting to false if omitted to maintain backward compatibility.
Hellis81
(Hellis81)
April 11, 2021, 8:58pm
2
Not the best workaround but you could use choose templates as actions.
So template is media player is playing, action pause.
But a short version of that could be handy.
Another option is Node red where you can put all call services in parallel.
mono
April 11, 2021, 9:02pm
3
Indeed, there are workarounds for specific cases if you anticipate where actions might fail. This is more so you can define something upfront as ‘best effort’ and not need to know all the ways in which it might fail ahead of time.
Isn’t that exactly what the wait
templates together with a timeout do? Wait for something to get to a specific state, and if not, move on after a set timeout… So in your case, wait for pause, if it won’t get there, move on after X minutes…
mono
April 11, 2021, 9:41pm
5
Not quite. Let’s say you call light.turn_off
and for whatever reason it throws an exception. Now your script just ends prematurely. There’s nothing to wait for, since you’re the one issuing the service call in the first place.
230delphi
(230delphi)
November 25, 2021, 12:24pm
6
exactly my problem right now… did you find any workarounds?
if (exec failed) then?
crixi
(Paul)
February 16, 2022, 2:20am
7
My current workaround is to have a script like script.play_media
with all the variables etc and then call this script via the ‘indirect’ method as described here: Scripts - Home Assistant
Hope this helps
Agree, this has already negatively impacted me a few times but now I know to be cognizant of it.
frenck
(Franck Nijhof)
April 10, 2022, 8:15pm
9
I agree on this one. It is become more an more needed and it allows us to require all integration to fail on error (instead of suppressing it).
The result would be more predictable and consistent and allowing failure to become a conscious choice.
I’ve prepared a change for this. This PR start by creating a way to manually allow failure/stopping (and makes a clear distinction between aborting and stopping.
home-assistant:dev
← home-assistant:frenck-2022-0488
opened 05:07PM - 27 Feb 22 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
This PR introduces/proposes 2 new script actions: `stop` and `fail`.
Both halt script sequence executions (in e.g., script and automations), `stop` indicates an expected halt, while `fail` can be used to raise an unexpected halt of execution.
This can e.g., be useful in to stop further automations in scripts conditionally (or abort script conditionally).
For example:
```yaml
trigger:
- ...
action:
- service: ...
- service: ...
- ... # More logic
- choose:
- condition: ... # e.g, someone home?
sequence:
- stop: "Someone is home, don't run the rest of this script"
- ... # Other things you would run if not stopped...
```
Or when something happened you think should not be possible:
```yaml
trigger:
- ...
action:
- choose:
- condition: ... # E.g., the temperature in living room hotter than lava
sequence:
- fail: "At least we can play the floor is lava game now..."
```
You already could achieve things like this in other ways, for example, set an empty sequence `sequence: []` or just use the condition as an action.
However, it doesn't tell you why it stopped in the automation debugger and additionally this will make explicitly clear script execution was stopped intentionally (or not).
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [ ] There is no commented out code in this PR.
- [ ] I have followed the [development checklist][dev-checklist]
- [ ] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [ ] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
I’ll try to make a follow up for this feature request after that.
2 Likes
frenck
(Franck Nijhof)
April 14, 2022, 5:18pm
10
Implemented in:
home-assistant:dev
← home-assistant:frenck-2022-0870
opened 07:58PM - 13 Apr 22 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Ideally, services throw errors when something goes wrong. Like, anything at all. We do a review on this nowadays to make everything more consistent.
However, many services don't do that (e.g., when a device is offline, or on API errors), because it stops scripts and automation sequences. (And users sometimes raise issues for those occurrences, while actually correct).
So that means we have a gap now. A user may want to ignore an error... and might not care if that single step failed or not.
This PR introduces: `continue_on_error`.
It can be set on each step in a script sequence and continues the sequence if the error is reasonable to handle. For example, broken templates and not handled errors by integration libraries (for example), are still raised, even when this option is used.
```yaml
action:
- alias: "If this one fails..."
continue_on_error: true
service: notify.super_unreliable_service_provider
data:
message: "I'm going to error out..."
- alias: "I'm still OK! :)"
service: persistent_notification.create
data:
title: "Hi there!"
message: "I'm fine..."
```
The name `continue_on_error` has been chosen to be consistent with the existing `continue_on_timeout` we use in other places.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/22390
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [x] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [x] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
Should become part of Home Assistant 2022.5
6 Likes
dbrunt
(Daniel)
April 16, 2022, 5:00pm
11
Hi @frenck , thanks for this!
I’ve just been troubleshooting a daily ZWJS battery level refresh that was not refreshing all entities and discovered one of my entity_id’s had changed for reasons that are obviously clear to me now that I’ve found it. It would be nice to obtain a direct notification of the failed automation action in addition to the standard logger entry. Something like on_error: service: notify.persistent_notification data: title: message: {{ error_message }}
Alternatively, does the error in the automation/script fire an event on the event bus that I could watch for? If not, might that be possible?
1 Like
Guys, updated to 2022.5
so yaml:
all_off:
alias: Alles uit
continue_on_error: true
sequence:
blabla...
but gives me:
2022-05-04 22:27:58 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [continue_on_error] is an invalid option for [script]. Check: script->continue_on_error. (See /config/configuration.yaml, line 130).
mono
May 4, 2022, 8:54pm
13
It’s a property of an action, not of the script itself. Try moving continue_on_fail: true
into one of your actions instead.
1 Like
dbrunt
(Daniel)
July 1, 2022, 6:09am
14
It would be nice if this option were also available as a tick box in the UI editor…
11 Likes
Guarddog13
(Ryan DeVoe)
September 1, 2022, 12:39am
15
I would like to see it as an option for the entire automation and not just one action. @frenck
13 Likes
nick2525
(Nick2525)
January 14, 2023, 9:19am
16
Yes, please add it to entire automation
7 Likes
Hi guys,
so for now the only way to prevent actions terminate in case or error is set for every action the attribute continue_on_error
to true?
Also for me it would be really VERY welcome to have the possibility to set it directly for all actions in both automations and scripts.
Unfortunately I am noticing several execution problems in the actions dependents cloud services (unfortunately for some devices there is no alternative…)
Thanks a lot for you amazing job
dbrunt
(Daniel)
August 1, 2023, 1:22am
18
@frenck Frank, I don’t know if you’ve been following this conversation or not, but a number of users would like to see the ability to set the continue_on_error
for all actions in an automation i.e. a global setting, if possible.
Also, it would be nice to see the option appear in the visual editor rather than resorting to yaml mode to add it. The other yaml only setting I would like to see in the visual editor is…
trace:
stored_traces: xx
Thanks.
4 Likes
H.E
August 29, 2023, 11:53am
19
Having a way to continue on error would be amazing - happens to me all the time especially on some lights with iffy connectivity…
Especially user friendly would be having a tick box in the UI and-or a way to just tell an automation once to ignore errors instead of for each step.
Also, might it not be better to have continue on error be a default in an automation, instead of failing out?
3 Likes
dbrunt
(Daniel)
December 4, 2023, 11:16pm
20
At least it’s visually apparent now…
Baby steps first I guess!