Which trigger wins?

In a scenario where 2 triggers could match the criteria of an automation, are they evaluated ‘top’ down, or is there a way of telling which would fire ?

For example:

trigger:
  - platform: state
    entity_id:
      - sensor.green_room_temperature_difference_with_main_house
    id: turn_on_heat
  - platform: numeric_state
    entity_id: sensor.green_room_temperature_difference_with_main_house
    id: turn_off_heat
    below: 0.1

Hi @Rofo

This is not a definitive answer but I suspect that if an event occurs which satisfies both triggers then the trigger that triggers will not be predictable.

In addition, depending on the mode that is set for the automation (single, queued, parallel), you may either get errors in your log or multiple executions - one for each triggered trigger.

I would suggest that triggers are mutually exclusive.

In the example above, I can get around it with a template trigger instead, but made me curious. Thanks for your answer.

The first one to become true - what happens next depends on the run mode you picked.

1 Like

This trigger will trigger on any state change, the other one only when the temperate difference goes from above 0.1 to below 0.1. So the first one will trigger a lot more.

1 Like

Thanks @francisp - i am aware of that. Was curious if 2 triggers qualified, if there was a way of predicting which would actually be counted as starting the automation, but it appears not.

More of an accademic issue, as i can use other methods to avoid the scenario from happening.

You can determine, within the automation, which trigger triggered the automation.

The issue I was trying to understand is whether or not, I could tell in advance which trigger would be triggered, when both matched the criteria.

That’s a very simple test. Program both triggers w/ automation mode single that executes a 1 second delay in your action section. Look at the trace and see which one ‘won the race’. I’d wager it’ll randomly flip flop.

mode: single
trigger:
  - platform: state
    entity_id:
      - sensor.green_room_temperature_difference_with_main_house
    id: turn_on_heat
  - platform: numeric_state
    entity_id: sensor.green_room_temperature_difference_with_main_house
    id: turn_off_heat
    below: 0.1
action:
- delay: "00:00:01"

if you don’t want to look at the trace, you can be even lazier and just make it have a persistent notification

mode: single
trigger:
  - platform: state
    entity_id:
      - sensor.green_room_temperature_difference_with_main_house
    id: turn_on_heat
  - platform: numeric_state
    entity_id: sensor.green_room_temperature_difference_with_main_house
    id: turn_off_heat
    below: 0.1
action:
- service: persistent_notification.create
  data:
    message: "{{ trigger.id }}"
- delay: "00:00:01"

2 Likes

Spot on Pedro. It will be be whichever arrived for processing first and that is at the whim of the cpu.

So Rofo no it is NOT predictable.