Can you use multiple triggers with an "OR" statement like multiple conditions?

I have some mqtt switches that are currently firing an automation trigger when any one switch in the group is turned on by checking the group state. I’d like to change this so if one of the switches is already on and I fire another switch in the group, I retrigger the automation sequence.

Can you use OR statements with triggers like you can with conditions like this:

condition: or
conditions:
  - condition: state
    entity_id: 'device_tracker.paulus'
    state: 'home'
  - condition: numeric_state
    entity_id: 'sensor.temperature'
    below: '20'

and just use:

trigger: or
triggers:
  - trigger: state
    entity_id: 'switch1'
    state: 'on'
  - trigger: state
    entity_id: 'switch2'
    state: 'on'
etc. etc.

I looked in the docs and on the forums but couldn’t find anything related.

2 Likes

Hi,

i think it work out of the box, even simpler.
mine is working fine. have a look:

- alias: 'disparar full'
  trigger:
    - platform: state
      entity_id: sensor.multisensor_6_motion
      from: 'still'
      to: 'motion'
    - platform: state
      entity_id: sensor.multisensor_6_motion
      from: 'motion'
      to: 'tamper'
    - platform: state
      entity_id: sensor.multisensor_6_motion
      from: 'still'
      to: 'tamper'
    - platform: state
      entity_id: sensor.door
      from: 'closed'
      to: 'open'

any of the trigger event will trigger the automation.

Luis

9 Likes

Thanks @luismoed! I’ll give this a shot later. Sometimes I overthink things… :sweat_smile:

Ya know, I just realized that I am already doing this with my manual alarm control panel automation without even thinking of it. Why I didn’t remember this until now is beyond me… Thanks again, Luis!

So, it means that multiple triggers are actually using OR
So my question is how can write automation script with AND between my two triggers

what would your 2 triggers be? I can help you convert them to a value_template trigger.

As far as formatting: here is what it accepts now. I will have to wait this next day to see it working

alias: electric blanket off
description: Check duration of on time
trigger:

  • platform: time
    at: ‘05:55:00’
    condition:
  • condition: or
    conditions:
    • condition: state
      entity_id: sensor.tasmota_11_status
      state: ‘08:00:00’
      attribute: Uptime
      action:
  • type: turn_off
    device_id: f34424baaxxxxxxx
    entity_id: switch.electric_blanket_2
    domain: switch
    mode: single

The mechanism I’m using for this sort of thing is to define a complex binary_sensor then have simple automations running off it. For example

template:
  - binary_sensor:
      - name: garage_or_mudroom_door_open
        delay_on: 0
        delay_off: 00:01:00
        state: >
          {{  is_state('cover.garage_door', 'open') 
              or is_state('binary_sensor.garage_mudroom_door', 'on') }}

  - id: garage_lights_on
    alias: Garage light on when doors open
    trigger:
      - platform: state
        entity_id: binary_sensor.garage_or_mudroom_door_open
        to: "on"
    action:
      service: switch.turn_on
      entity_id: switch.garage_lights

Hi,

For those who wants 2 triggers and 2 actions

Below code says,

Before sunset

If tv goes on then close the cover,
If tv goes off then open the cover

You can modify for your scenario

alias: TV Mode
description: ''
trigger:
  - platform: state
    entity_id:
      - media_player.sony_bravia_tv
    to: playing
    from: 'off'
  - platform: state
    entity_id:
      - media_player.sony_bravia_tv
    from: playing
    to: 'off'
condition:
  - condition: sun
    before: sunset
    after: sunrise
action:
  - if:
      - condition: state
        entity_id: media_player.sony_bravia_tv
        state: playing
    then:
      - service: cover.close_cover
        data: {}
        target:
          entity_id: cover.veranda_sag
    else:
      - service: cover.open_cover
        data: {}
        target:
          entity_id: cover.veranda_sag
mode: single