Automation with group or multiple triggers

I have an automation with several triggers. I want it to tirgger if any of them switches from “off” to “on”. So it’s an “OR” automation. I also tried to do this via group but neither trigger for some reason.

This is my code:

- alias: Irrigation.ON
    trigger:
      - platform: state
        entity_id: switch.irrigation_irrigation_output_01
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_02
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_03
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_04
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_05
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_06
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_07
        from: "off"
        to: "on"
      - platform: state
        entity_id: switch.irrigation_irrigation_output_08
        from: "off"
        to: "on"
    action:
      - service: timer.start
        data_template:
          entity_id: timer.irrigation_timer
          duration: "{{ states('sensor.irrigation_time') }}"

That automation should work.
What does the trace show?

Maybe a typo?
Like switch.irrigation_irrigation_?

The naming is good. It’s so random sometimes it works sometimes it doesn’t.

I changed it to:

- alias: Irrigation.ON
    trigger:
      - platform: state
        entity_id: group.irrig_relays
        to: "on"
    action:
      - service: timer.start
        data_template:
          entity_id: timer.irrigation_timer
          duration: "{{ states('sensor.irrigation_time') }}"

Worked once and then stopped.

Never worked with “trace” before, I’m guessing it’s some kind of a log like a debugger? How can I see these traces?

The trace:


Executed: May 25, 2024 at 11:26:31 AM
Result:
params:
  domain: timer
  service: start
  service_data:
    entity_id: timer.irrigation_timer
    duration: '00:49:20'
  target: {}
running_script: false
  - alias: Irrigation.ON
    mode: single
    trigger:
      - platform: state
        entity_id:
          - switch.irrigation_irrigation_output_01
          - switch.irrigation_irrigation_output_02
          - switch.irrigation_irrigation_output_03
          - switch.irrigation_irrigation_output_04
          - switch.irrigation_irrigation_output_05
          - switch.irrigation_irrigation_output_06
          - switch.irrigation_irrigation_output_07
          - switch.irrigation_irrigation_output_08
        from: "off"
        to: "on"
    condition: []
    action:
      - service: timer.start
        target:
          entity_id: timer.irrigation_timer
        data:
          duration: "{{ states('sensor.irrigation_time') }}"
1 Like

There’s you problem.

Its most likely that the reason it doesn’t run is due to you already have an automation running.
Since it’s in single mode then it can only run one instance at the time all other triggers will not make the automation run

2 Likes

But that duration is dynamic

Doesn’t matter.
It still prevents the automation from running

Well it works now, i added “id” to my automation and it started to work more consistently.

That’s a coincidence because the presence, or absence, of the id option has no bearing on an automation’s behavior.

1 Like

It takes milliseconds for the automation to execute the timer.start service call. The timer’s duration doesn’t determine how long this automation is busy.

In order for this automation to ignore a subsequent trigger, that trigger event would have to occur during those few milliseconds.

1 Like

I know but for some reason no more random issues. Can’t debug this issue to be honest makes no sense.

In your first post you said the automation failed to trigger.

That implies the automation wasn’t loaded or it never detected the specified state-changes.

Later you posted a portion of its trace indicating it did in fact trigger and started the timer.

What is the testing procedure you’re using?

I think the issue is the automation triggers too quickly. So it detects the state change to “ON”. But my “sensor.irrigation_time” which is suppose to get a dynamic value has not yet been set. Hence the automation does work but the “timer.irrigation_timer” does not get the value it should.

So what I did now is instead of using:

 trigger:
      - platform: state
        entity_id: group.irrig_relays
        to: "on"

the code is now:

  - id: Irrigation.ON
    alias: Irrigation.ON
    trigger:
      - platform: state
        entity_id: sensor.irrigation_time
        from: "00:00:00"
    action:
      - service: timer.start
        data_template:
          entity_id: timer.irrigation_timer
          duration: "{{ states('sensor.irrigation_time') }}"
  1. It uses whatever is the sensor’s value at the moment that timer.start is executed. There’s been no explanation of how the sensor’s value is computed so no one can comment on the alleged “does not get the value it should”.

  2. If you’re using a State Trigger with a group entity, it will trigger when the group’s state changes to on which will happen when one of the group’s members changes state to on. If that first member remains on and then another member in the group also changes to on it will not trigger the automation.

  3. The new automation you posted has significantly different behavior than the original automation because it now monitors a completely different entity’s state. There’s been no explanation of the intended application’s requirements so no one can comment on whether the new automation is the best strategy or not.

1 Like