Automation doesn't complete when Delay used

Hi All,
I have an automation (1) that doesn’t always complete once a delay is added. For as far as I can tell the automation does not complete once another automation (2) is triggered that turns on a light that is part of the group the automation (1) will turn off after the delay.

Now I am first of all curious if someone can confirm this behavior.

Secondly
I rebuild my automation to work around the delay function by using a DateTime-helper to trigger a turn-all lights of automation, which works as designed. The downer is that the trigger, using ‘sensor.date_time’, is exact to the minute and not the second. So say the helper is set to 23:45:54, it is triggered at 23:45. Adding a delay for the resulting seconds reintroduces the same issue. Is there a way to make it trigger to the exact second?

My current template trigger is this:

{{ states('sensor.date_time') == (state_attr('input_datetime.all-off', 'timestamp') | int | timestamp_custom('%Y-%m-%d, %H:%M', True)) }}

So:

  1. can anyone confirm that the delay-function gets interrupted if a light that is part of the automation is triggered by another automation?
  2. is there a way to trigger an automation, using a helper, to the second?

Only if the light is part of the trigger and…

What version of home assistant are you running?

If you are running 0.113 or above read this: Automation - Home Assistant

If you are running a version below 0.113 the answer to your question is - yes. If your trigger fires while waiting in a delay the delay will be cancelled and the actions after it will be executed.

Time trigger or time pattern trigger both support seconds.

Time pattern triggers are usually not the best way to trigger an automation.

It would help diagnosing your issue if you posted the two interfering automations in full.

After I took another look at the Template trigger docs I realized that the option for -> seconds could be my solution. It has to be the amount of seconds past the specified minute before it triggers. Below my tested solution.

  trigger:
  - for:
      seconds: '{{ (state_attr(''input_datetime.all-off'', ''timestamp'') | timestamp_custom(''%S'', True)) | int }}'
    platform: template
    value_template: '{{ states(''sensor.date_time'') == (state_attr(''input_datetime.all-off'',
      ''timestamp'') | int | timestamp_custom(''%Y-%m-%d, %H:%M'', True)) }}'

I did however had to edit the automations.yaml because the ‘for: seconds:’ got removed. So I am not sure how future proof this is, but it does work perfectly at the moment.