I am almost certain that there is no solution to this (except to duplicate code) but it doesn’t hurt to ask.
I have more than one automation which at certain times as defined by its own input_datetime
, call a single script.
The automations use
- wait_template: >
{{ is_state('script.my_script' , 'off') }}
to ensure that the script isn’t already running before calling it because the input_datetime
s could have the same time.
However, I am still experiencing situations where one automation fails because,
Script script.my_script already running.
I suspect that this is because they are both reaching the wait_template
at the same time. Or more likely, not at exactly the same time but close enough that HA doesn’t update the state of the script fast enough when the ‘first’ automation calls it.
Does anyone by any chance have any solution to this apart from repeating the script code in each automation?
Further reading…
I am already suspicious of the integrity of the states reported by HA because I have (an admittedly slightly over complicated) notification engine which relies on the state of scripts and the Sonos component in order to process sequential announcements.
I have had to include a timeout
on every wait_template
because sometimes the state never gets set to playing
for the Sonos.
I know it is only sometimes because the gap between announcements varies between short (as it should be) and long (the timeout
). More evidence is that sometimes the timeout has been shorter than the length of the announcement meaning it is cut short by the next one when clearly the Sonos component should be in a state of playing
.
I have also watched the states not update in the front end. (These announcements are many seconds long so it can’t be my ‘underpowered’ RPi but in this case I suppose it could be a problem with the Sonos component).