Closed EPMatt closed 3 years ago
I'm not in position to fix this Issue but thought you might like to know I tried your suggested automation and script and can confirm it produced two notifications. I modified the service call to include a timestamp in the notification. The two notifications report the exact same time (to the second).
I agree this is unexpected; seems there should only be one notification. On the other hand, if this is working to spec then it would be useful to know why.
automation documentation automation source (message by IssueLinks)
Hey there @home-assistant/core, mind taking a look at this issue as its been labeled with an integration (automation
) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)
Hi @tdejneka, thank you for testing this by yourself.
It's interesting that the two automation runs look to be fired exactly at the same time, but to the second. This info might help developers to identify the problem. 👍🏻
~~Could you change the script to trigger only 2 times, then share the resulting 2 automation traces? Edit: Or does running the script, which loops 10 times create two persistent notifications, not 10?~~
Never mind about this, I can reproduce it.
I think there's a race here: https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/script.py#L1149
Hi @emontnemery,
~Could you change the script to trigger only 2 times, then share the resulting 2 automation traces? Edit: Or does running the script, which loops 10 times create two persistent notifications, not 10?~
Never mind about this, I can reproduce it.
by the way, I tried to tweak the number of automation triggers in the provided script, and it looks like only firing 4+ automations produces 2 notifications. I tested it also with 100 automation triggers and the result is still the same - two separate runs complete execution.
The problem
The automation run mode
restart
does not restart an automation run if a second one is triggered moments after the first one started.This issue was encountered while debugging a blueprint (https://github.com/EPMatt/awesome-ha-blueprints/issues/20). OP noticed that the automation generated by the blueprint was not restarted, even if
mode: restart
was set in the blueprint config.I was able to craft a faulty automation to reproduce the issue only by using a script, custom events and the
persistent_notification
integration.The faulty automation, configured with
mode: restart
, waits 5 seconds, then creates a persistent notification in the HA frontend. The script simply triggers the automation 10 times in a row without waiting single runs to complete.To reproduce
scripts.yaml
andautomations.yaml
of your instance.test_issue
script.Expected Behaviour
Only one
completed
notification is created in the frontend. That means that only an automation run completes execution and the automation was succesfully restarted, every time a new run was spawned, asmode: restart
is expected to work.Actual Behaviour
Two or more
completed
notifications are created in the frontend. That means that at least one automation run was not terminated when the next one was spawned; instead it was able to complete execution, even ifmode: restart
is set in the automation config.What is version of Home Assistant Core has the issue?
core-2021.4.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
automation
Link to integration documentation on our website
https://www.home-assistant.io/docs/automation/
Example YAML snippet
Anything in the logs that might be useful for us?
No response