What exactly happens on WARNING [homeassistant.components.script] Script script.xxx already running?

Hi All,

I have a script: xxx that stores attributes (temperature, operation mode etc) of generic_thermostat in input_text/input_numbers.
I call it as a reaction on trigger: state of the generic_thermostat.
In the log I can see that often when the generic_thermostat switches itself to Idle/Heat/etc, I got that warning (perhaps because HA fires several state_change events as both mode and temperature are changed consequently).
I wonder why it is happening and what are implications - does it mean that the second call of the script is aborted (i.e it is impossible by HA design to have more than one instance of each script running at any point of time)? There is no info about that in documentation.
And what is the right way to avoid these warnings?

Why? home assistant knows these attributes already.

I believe this is the case.

One way to avoid it is to use a wait_template to check the script isn’t running before calling the script. But this gets messy if the script is called often and from several places.

I’d love the option to have scripts run concurrently but I feel like that might have some negative implications elsewhere.

As far as I can see, if any of these temperatures/modes are changed and then HA is restarted, they revert back to configuration values.
I’m trying to store them and restore when HA is starting.

Please share your thoughts on the matter.

so basically it means “no more than one instance of a script at a time”, right?
might be useful to note it in documentation…

edit: when I added wait_template before calling the script, I got “home assistant spent more than 10 seconds to start” and “operation/bla-blah timeout” (system one).
Then I just moved back script’s sequence into automation, and can see no issues.

Seems like scripts are very limited and pretty time consuming, need to re-think my general design approach accordingly.

Your script saves a bunch of data, right? And if the script is called again, it will just overwrite the saved values with the new values, right? So what you can do before calling the script is to abort it in case it is still running from a previous invocation. Simply:

  - service: script.turn_off
    entity_id: script.my_script
  - service: script.my_script

To test, I just set up a very simple generic_thermostat. I set a target temperature, then restarted ha, and the target temp was still as I set it.

Done it a couple of times now, and it comes back correctly, ie to the values I set, every time.

Not quite, 3 values only.

Correct.

That seems to be valid, at least to avoid those warnings. A bit weird though, but I got the idea. Thanks for sharing!

Well, it’s not as simple as it looks. Can you set away mode? I couldn’t with the approach you described as I need to set away_temp in config to have this option available. Here is more details

Basically, generic_thermostat does not save (even during runtime) value of away_temp. If they fix it and store between restarts as they do with temperature, I’ll be more than happy, but so far this bug is open.