Multiple Triggers - AND

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

I am looking for the same thing where 2 kitchen lights are turned off, I would like the breakfast room light to turn off as well. That is using Lutron dimmers and the breakfast room is Philips Hue. I was thinking to have separate automation to record timestamp when light is turned off for each kitchen light and another automation on either light state changing to off compare these timestamps and if the difference is no more than 1 second, turn off another light, what I wanted to turn off. Going to try to develop these automations… I have 2 kitchen lights, one is the main light and another is over the sink. Either could be turned off separately and I do not want to turn off the breakfast room in that case. I have a Lutron Peco remote, which turns both kitchen lights at the same time. That is where I want my automation to start to turn off the breakfast room light.

My situation is a little different: I’d lke to fire my ‘action’ after all of my 5 PIR Sensors do not ‘see’ any presence or movement for X minutes. I should achieve a logical AND for 5 triggers. Am I wrong? Is there a way to write such an automation ? Thank you for every kind help.