Automation not running while script is still running

I have a weird behavior when trying to diagnose why one of my automation doesn’t run as it should. I removed all my condition to rule them out but I am still having issue that seems to be related to a delay in my script.

Basically, here is the automation:

alias: H - Target change - Normal (TEST)
description: ''
trigger:
  - platform: state
    entity_id: input_number.temperature_cible
condition: []
action:
  - service: script.turn_off
    data:
      entity_id: script.heating_normal
  - service: script.heating_normal
mode: single

And here is the script (which is pretty simple):

lias: H - Demarre le chauffage normal
sequence:
  - service: climate.set_temperature
    data:
      temperature: 10
    entity_id: climate.thermostat_salon
  - service: climate.set_temperature
    data_template:
      temperature: '{{ states(''input_number.temperature_cible'') | float }}'
    entity_id: climate.thermostat_central
  - delay: '00:15:00'
  - service: climate.set_temperature
    data_template:
      temperature: '{{ states(''input_number.temperature_cible'') | float - 1.5 }}'
    entity_id: climate.thermostat_salon
mode: single

So, basically, the automation stop the script if it is still running from a previous trigger. I am using this with other automation and I never had any problem but on this one, the script.turn_off doesn’t seem to work.

If I manually stop the script, the automation will work and the script will launch. But, if the script is still running, the automation simply doesn’t work. It actually look as if it isn’t being called at all.

Any idea why this isn’t working? It must be something stupid that I just don’t see because I’ve been looking at this for too long.

This is based on this: How to Turn Light on only for 2 minutes?

Ok, after testing my other automation that use the same principle (a script with a delay that the automation turns off in case it fires again before the end of the delay) and it seems that it doesn’t work.Maybe something changed in the way HA do this? I do remember setting this up and testing and it worked. Well, I believe it worked! :stuck_out_tongue:

Ok, it seems that an automation cannot be triggered again as long as its action are still running.

After playing around with the mode, it seems that enabling the parallel mode allow the automation to run multiple time, which actually cause the turn_off script to work as it should.

Is that how this should be done?

Setting your script and automation to mode: restart might allow you to do away with the script.turn_off line entirely.

This is a relatively new feature (a month or two ago? In the northern hemisphere, this is the first heating season with this feature :laughing:). You can read about it here and decide how you want to do things.

1 Like