Automation conditions and triggers

Hello, I recently successfully added a Sonoff relay to my ventialtion system and I can now trigger extractor fan when either 2 bathrooms or kitchen humidity goes over a certain level (70% for bathrooms and 60% for kitchen) and turn off if all three are below the set humidity level OR if time is after 10PM or before 6AM (basically ventilation should never be triggered between 10PM and 6AM)

Originally I’ve made 3 automations, for each bathroom and the kitchen plus another 3 automations to turn ventialtion off based on the humidity of the 3 rooms and a another automation to turn off after 10PM, for a total of 7 automations…

I then realised I can definetely simplify that, am I correct in understanding that each trigger in the automation is considered on its own?

Here my 2 automation for ventilation ON and ventilation OFF:


or if you prefer review the code:

ventilation on

alias: "ventilation ON "
description: ""
trigger:
  - type: humidity
    platform: device
    device_id: d73d7f1649feea66f53982dd61375073
    entity_id: sensor.ewelink_th01_humidity
    domain: sensor
    above: 70
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: humidity
    platform: device
    device_id: 25891d20773080b4421a11cfb9206287
    entity_id: sensor.ewelink_th01_humidity_2
    domain: sensor
    above: 70
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: humidity
    platform: device
    device_id: c8e55a0f409ec513df09f947c4a0a36f
    entity_id: sensor.kitchen_living_humidity
    domain: sensor
    above: 60
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition:
  - condition: time
    after: "06:00:00"
    before: "22:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - type: turn_on
    device_id: 4a48b1e85cfbe115b01a2bbf6b700c1a
    entity_id: light.sonoff_01minizb_light
    domain: light
mode: single

ventilation off

alias: ventilation OFF
description: ""
trigger:
  - type: humidity
    platform: device
    device_id: 25891d20773080b4421a11cfb9206287
    entity_id: sensor.ewelink_th01_humidity_2
    domain: sensor
    below: 70
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: humidity
    platform: device
    device_id: d73d7f1649feea66f53982dd61375073
    entity_id: sensor.ewelink_th01_humidity
    domain: sensor
    below: 70
  - type: humidity
    platform: device
    device_id: c8e55a0f409ec513df09f947c4a0a36f
    entity_id: sensor.kitchen_living_humidity
    domain: sensor
    below: 60
  - platform: time
    at: "22:00:01"
condition:
  - condition: and
    conditions:
      - type: is_temperature
        condition: device
        device_id: 25891d20773080b4421a11cfb9206287
        entity_id: sensor.ewelink_th01_temperature_2
        domain: sensor
        below: 70
      - type: is_temperature
        condition: device
        device_id: d73d7f1649feea66f53982dd61375073
        entity_id: sensor.ewelink_th01_temperature
        domain: sensor
        below: 70
      - type: is_humidity
        condition: device
        device_id: c8e55a0f409ec513df09f947c4a0a36f
        entity_id: sensor.kitchen_living_humidity
        domain: sensor
        below: 60
  - condition: or
    conditions:
      - condition: time
        after: "22:00:00"
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
        before: "06:00:00"
action:
  - type: turn_off
    device_id: 4a48b1e85cfbe115b01a2bbf6b700c1a
    entity_id: light.sonoff_01minizb_light
    domain: light
mode: single

Yes.

You need to make a small change to the “off” automation. For the conditions to be affected by the “OR” they all need to be nested under the Or condition.

alias: ventilation OFF
description: ""
trigger:
  - type: humidity
    platform: device
    device_id: 25891d20773080b4421a11cfb9206287
    entity_id: sensor.ewelink_th01_humidity_2
    domain: sensor
    below: 70
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: humidity
    platform: device
    device_id: d73d7f1649feea66f53982dd61375073
    entity_id: sensor.ewelink_th01_humidity
    domain: sensor
    below: 70
  - type: humidity
    platform: device
    device_id: c8e55a0f409ec513df09f947c4a0a36f
    entity_id: sensor.kitchen_living_humidity
    domain: sensor
    below: 60
  - platform: time
    at: "22:00:01"
condition:
  - condition: or
    conditions:
      - condition: time
        after: "22:00:00"
        before: "06:00:00"
      - condition: and
        conditions:
          - type: is_temperature
            condition: device
            device_id: 25891d20773080b4421a11cfb9206287
            entity_id: sensor.ewelink_th01_temperature_2
            domain: sensor
            below: 70
          - type: is_temperature
            condition: device
            device_id: d73d7f1649feea66f53982dd61375073
            entity_id: sensor.ewelink_th01_temperature
            domain: sensor
            below: 70
          - type: is_humidity
            condition: device
            device_id: c8e55a0f409ec513df09f947c4a0a36f
            entity_id: sensor.kitchen_living_humidity
            domain: sensor
            below: 60
action:
  - type: turn_off
    device_id: 4a48b1e85cfbe115b01a2bbf6b700c1a
    entity_id: light.sonoff_01minizb_light
    domain: light
mode: single

ah brilliant thanks, that is somehow counterintuitive and I just come home to the ventilation still running despite humidity being below the level everywhere.

And this will still ALWAYS shut it off at 22:00:01 right? Because how it visualised make me thing it needs to be AFTER the time AND below level… even thought it’s saying "Test if any of 2 conditions matches… so that should be ok, is just weird to see the OR and then the “and” but I understand is not a logical AND is just “and also evaluate this other conditions…”

It might help to think about it like distribution in algebra instead of reading it like a sentence.

Because of the order/application of conditions in you original, the Or was only being applied to the time condition. The entire condition block could only ever pass after 22:00:01.

As long as Home Assistant is running, yes. It also produces an edge case where if the fan is running after 22:00:01 and any of the sensors trigger the automation by falling below threshold it will be turned off (even if only 1 of 3 sensors is below threshold)… If that’s not okay, you’ll need another condition inside the And block.