Multiply Action conditions

Im trying to create an automation that will turn off the bathroom light lights but keep on the light over the toilet on if the light level is low. Also to turn off the extractor fan if the humidity is below a level of 64.

Ive come up with this:

- alias: bathroom lights off
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  action:
  - data:
      entity_id:
      - light.basin
      - light.bath_1
      - light.bath_2
      - light.shower
      - light.toilet
    service: light.turn_off
  - condition: template
    value_template: '{{ states.sensor.outside_light_level.state | int < 70 }}'
  - data:
      entity_id: light.toilet
      brightness_pct: '1'
    service: light.turn_on
  - condition: template
    value_template: '{{ states.sensor.humidity_bathroom.state | int < 64 }}'
  - data:
      entity_id: switch.bath_extractor
    service: switch.turn_off

But have realised that the 2 conditions only work if the first one is true, it then continues to the next condition (the extractor fan). If this is during the day when the light level is above 70, then that condition returns false and the second condition is ignored, living the extractor on.

I also tried:

  - entity_id: light.toilet
    service_template: >
      {% if states.sensor.outside_light_level.state | int < 70 %}
        light.turn_on
          brightness_pct: '1'
      {% endif %}
  - entity_id: switch.bath_extractor
    service_template: >
      {% if state.sensor.humidity_bathroom.state | int < 64 %}
        switch.turn_off
      {% endif %}

but that didn’t work so Im stuck for ideas now, can anyone help or advise me here. Thank you.

I would break it up into three automations:

- alias: bathroom lights off 1
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  action:
  - data:
      entity_id:
      - light.basin
      - light.bath_1
      - light.bath_2
      - light.shower
      - light.toilet
    service: light.turn_off
- alias: bathroom lights off 2
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  condition:
  - condition: numeric_state
    entity_id: sensor.outside_light_level
    below: 70
  action:
  - data:
      entity_id: light.toilet
      brightness_pct: '1'
    service: light.turn_on
- alias: bathroom lights off 3
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  condition:
  - condition: numeric_state
    entity_id: sensor.humidity_bathroom
    below: 64
  action:
  - data:
      entity_id: switch.bath_extractor
    service: switch.turn_off

Thank you for your prompt help @pnbruckner . I don’t know a lot about yaml but was wondering if anchors and aliases can be used in the trigger section to save on repeat typing.

I shall have to read up on yaml structuring.

I’ve only used them a few times, but yep, this is a good example where that would help:

- alias: bathroom lights off 1
  initial_state: 'on'
  trigger: &brl_trigger
  - platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  action:
  - data:
      entity_id:
      - light.basin
      - light.bath_1
      - light.bath_2
      - light.shower
      - light.toilet
    service: light.turn_off
- alias: bathroom lights off 2
  initial_state: 'on'
  trigger: *brl_trigger
  condition:
  - condition: numeric_state
    entity_id: sensor.outside_light_level
    below: 70
  action:
  - data:
      entity_id: light.toilet
      brightness_pct: '1'
    service: light.turn_on
- alias: bathroom lights off 3
  initial_state: 'on'
  trigger: *brl_trigger
  condition:
  - condition: numeric_state
    entity_id: sensor.humidity_bathroom
    below: 64
  action:
  - data:
      entity_id: switch.bath_extractor
    service: switch.turn_off

Oh wow, thank you, I spent the afternoon trying different ways to solve this with anchors and aliases, and you do it that quick. Thats very good of you.

1 Like