Multiple Triggers - AND

Is there a way to AND triggers together? From what I can tell it behaves as an OR.
I’d like to do:
If Trigger A and Trigger B then do C.

But right now it behave as:
If Trigger A or Trigger B then do C

I could split it into two automations… and use a condition but that seems like a nuisance.
Any help is appreciated.

I’d use ‘Trigger A’ as the real trigger and ‘Trigger B’ as a condition (or a bunch of them) in order to trigger an action.

It’s probably just in the wording, e.g. you say “If I come home AND it’s dark turn, then on the lights.”

You’d turn this into:
Trigger: change of state from not_home to home
Condition: it’s dark (e.g. after sunset)
Action: turn on the lights

5 Likes

In one automation: Trigger on either (A OR B), then use an and condition that asserts both (A AND B) before moving on to the action

automation:
  trigger:
    - platform: numeric_state
      entity_id: 'sensor.A'
      above: 68
    - platform: numeric_state
      entity_id: 'sensor.B'
      above: 72
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: 'sensor.A'
        above: 68
      - condition: numeric_state
        entity_id: 'sensor.B'
        above: 72
  action:
    - 'do stuff'

I don’t think there’s a way to limit the automation to firing on both conditions.

17 Likes

What would be the difference if you took out the trigger for sensor B and the condition for sensor A in this case?

Unless I’ve misunderstood something, it wouldn’t trigger on sensor B, and you’d need a second automation to trigger on sensor B then check the condition of sensor A.

Since nuurban implied that they’d prefer to use one automation, this seemed preferable.

1 Like

Okay, got it.

Either change can trigger, both conditions need to be fulfilled.
Haven’t had a need for this so far, so I hadn’t thought about it that way.

This would be like turning my example into:
“(If I come home AND it’s dark) OR (if I’m home AND the sun sets), then turn on the lights.”

1 Like

This works… I don’t really like the redundancy… but since the trigger section can’t do an AND there’s not really a nicer way to do this in one automation I guess. Thanks for help!

I was looking at this the other day as I wanted to include an AND for my bathroom exhaust fan trigger to compensate for outside humidity. I found that you can put logic into template triggers. Example below.

`- alias: "Turn on Bathroom Fan"
  trigger:
     platform: template
     value_template: '{{ states.sensor.dark_sky_humidity.state | float > 90 and states.sensor.bathroom_humidity.state | float - states.sensor.lounge_humidity.state | float > 20 or states.sensor.dark_sky_humidity.state | float < 90 and states.sensor.bathroom_humidity.state | float - states.sensor.lounge_humidity.state | float > 15 }}'
6 Likes

Based on the idea of using templates, I found a way to get my two motion sensors in the bathroom to function as one:

binary_sensor:
  - platform: template
    sensors:
      master_bath_sensors:
        friendly_name: "Master Bath Sensors"
        value_template: >-
          {{ is_state('binary_sensor.master_toilet_motion_sensor', 'on')
             or is_state('binary_sensor.master_sink_motion_sensor', 'on') }}

now in my automation, i can do:

- alias: Master Bath Auto Off
  trigger:
  - entity_id: binary_sensor.master_bath_sensors
    for: '00:15:00'
    platform: state
    to: 'off'
  action:
     <snip>

so now, so long as there is motion on one of the sensors, the automation will not trigger. hope this helps someone who wants something similar…

7 Likes

Smooth !

Thanks, I was struggling with this. Works perfectly.

Michael

Rather than setting up a template can’t you just put the two sensors in a group?

2 Likes

yes, that probably would work as well… didn’t know about groups when i was working on this. which is one of the main challenges with learning to use HA. it can be difficult to find the best method to solve a particular problem, unless someone has already posted a similar use case.

1 Like

I was looking for the way of using AND (Events Trigger), I tried solutions above but it’s not worked. Please help.
I have Sonoff RF 3 buttons, Sonoff RF bridge and using Sonoff Lan to integrated to Home Assistant.

- id: '1599813275658'
  alias: Test
  trigger:
  - event_data:
      command: 0
    event_type: sonoff.remote
    platform: event
  - event_data:
      command: 1
    event_type: sonoff.remote
    platform: event
  action:
  - data: {}

There’s no such thing as an AND trigger, especially for events. The two events will never happen at the same time there will always be a small delay between them.
You could create input_booleans that get turned on when the event happens, but to be honest this will get very complex and tricky.

What are you trying to achieve?

2 Likes

I have 3 RF buttons can trigger 3 automations by events through Sonoff RF bridge (Sonoff Lan). I want to press button 1, and after 2s press button 2 (or other scenario of buttons press combination) to trigger other automation. Any solution without buy more buttons. Thanks.

I’d wait for version 0.115, from what I understand it should be possible to do this with the new wait_for_trigger.

1 Like

I have an automation (closing my blinds) triggered 30mn after sunset with :

trigger:
  - platform: sun
    event: sunset
    offset: '00:30:00'

Within the same automation (ideally) I would like to also close the blinds at sunset (no offset) IF temperature is below 1°C

- platform: numeric_state
    entity_id: weather.home
    below: '1'

Is it possible to combine :
at sunset + 30mn
OR
at sunset if temp < 1°
I’m not sure about the mix between triggers, conditions and or/and :confused:
Thank you for your tips

You can use options for that.

I didn’t complete option 2 but I think you get the idea.

Thank you for your suggestion.
I started implementing it when I realized that multiple triggers are OR by default according to the first messages of this thread.
And this is exactly what I need. I’m not sure why I didn’t try that 5 months ago :man_shrugging:
Anyways, here is my yaml which I will watch in the coming days to make sure it does what I intend :wink:

alias: 'Blinds : close downstairs 50mn after sunset or if temp below 5'
description: >-
  Close the downstairs blinds 50 minutes after sunset
trigger:
  - platform: sun
    event: sunset
    offset: '00:50:00'
  - platform: numeric_state
    entity_id: weather.bry_sur_marne
    attribute: temperature
    below: '5'
action:
  - device_id: 8d429a48fde411ea9755eb6a665b17b6
    domain: cover
    entity_id: cover.living_room_blind
    type: close
  - device_id: 8d423ac4fde411eaadf487945d441678
    domain: cover
    entity_id: cover.study_blind
    type: close
  - device_id: 8d427234fde411ea8129e33251c2b884
    domain: cover
    entity_id: cover.kitchen_blind
    type: close
  - service: notify.mobile_app_nokia_7_plus
    data:
      message: Downstairs blinds are closing
mode: single

Triggers are always OR, not just by default, there’s no such thing as AND trigger. There’s never to things hapening at the exact same time.

3 Likes