Automation mode single when using multiple triggers

Apologies for what may be an obvious question - just need to double-check my understanding.

Q: Does automation mode single apply to the automation, or to the automation per trigger?

Context:
I’m refactoring some automations at the moment and have a rewritten automation triggered by a state change, and with the following key characteristics:

  • single trigger entity_id
  • mode: single
  • use of a wait_for_template (this is a key element)

I could in theory use the same automation to replicate the functionality for multiple trigger entities (with some minor variable templating). These entities could trigger at the same time / within the same time window, so if automation mode single applies at the automation level, rather than automation + trigger level, then I will have to replicate the code per trigger entity (although
(I suppose an alternative could be to convert the automation to a blueprint)

Single–> Run a single instance of the automation, no new runs are allowed while the previous is running,
Restart → Abort the previously running automation and restart it.
Queued → Wait with the next run until the previous run has finished.
Parallel → Run multiple instances of the automation simultaneously (parallel).

This applies to the automation itself, not to the triggers within.

1 Like

For future reference, script modes are explained in the documentation and include diagrams. The explanation also applies to automations.

Thanks for the link - I did actually check the docs before posting, however for a rather tired me they left a question over whether the single run might be restricted to automation + trigger. Hence the apology in my OP.

It would be great to have single mode + trigger as an option. That would reduce amount of automations that I duplicate where trigger is the only thing different. I also use wait in action part.

Can you elaborate? Because it’s already possible for an automation to use single mode and have multiple triggers.

I mean single mode that will be based on automation and trigger. Now if I have 2 triggers and one of them fires the automation. Then under actions I have wait template that is preventing automation to complete because of some condition. Then if second trigger fires the automation, it will not be actually run because the first one is not finished.

So I would like to have single mode, that is perfectly fine, but if single mode can take into account which trigger is executed, and if the same trigger is executed again while the first one is running, block it. Now it is blocking entire automation regardless what trigger is fired.

Here is my automation:

alias: "Notify: Temperature in Attic and Basement too low"
description: Not supporting multiple trigger entities.
trigger:
  - type: temperature
    platform: device
    device_id: 03278deac1cd9391c7659fda6c7c9789
    entity_id: sensor.temperature_3
    domain: sensor
    below: 15.5
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: temperature
    platform: device
    device_id: 4d38dbf9c86ac992983b8ffdea97c9b9
    entity_id: 3984875c3ae775bcbbec7237688e89ee
    domain: sensor
    below: 15.5
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_alan_s22
    data:
      message: >
        Temperature for {{ trigger.to_state.attributes.friendly_name }} is at {{
        trigger.to_state.state }} {{
        trigger.to_state.attributes.unit_of_measurement }}.
      title: Temperature is too low
      data:
        tag: temperature_low_{{ trigger.entity_id }}
        group: Temperature low
        channel: Temperature sensor
        notification_icon: mdi:snowflake-thermometer
        color: "#179FE7"
        ttl: 0
        priority: high
  - service: notify.persistent_notification
    data:
      title: Temperature is too low
      message: >-
        Temperature for {{ trigger.to_state.attributes.friendly_name }} is at {{
        trigger.to_state.state }} {{
        trigger.to_state.attributes.unit_of_measurement }}.
  - alias: Wait until value back to normal for 15 minutes (900 seconds).
    wait_template: >-
      {{ (states(trigger.entity_id) | float > trigger.below) and
      (as_timestamp(now()) -
      as_timestamp(states[trigger.entity_id].last_changed) >= 15*60) }}
    enabled: false
  - repeat:
      while:
        - condition: template
          value_template: "{{ states(trigger.entity_id) | float <= trigger.below }}"
      sequence:
        - alias: Wait until value back to normal
          delay:
            hours: 0
            minutes: 10
            seconds: 0
            milliseconds: 0
mode: single

Because that’s the very definition of single mode.

The mode of operation you described isn’t any of the four available modes (single, restart, parallel, queued) but a hybrid of single and restart. In other words, operate like single if it’s the same trigger triggering and behave like restart if it’s a different trigger. Feel free to submit a Feature Request.