Using or for multiple conditions

Hi

I am new to Home Assistant - testing the new Tuya 2.0 Integration

I have an automation which works fine with 1 sensor , but does not trigger with more than 1

I want an alert if we leave windows open when we go out (in addition to the mention sensor burglar alarm)

thanks in advance
Stuart

alias: check windows on away
description: ''
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: scene
      service: turn_on
      service_data:
        entity_id: scene.away
condition:
  - condition: state
    entity_id: binary_sensor.tybf82b920231699632bjhni
    state: 'on'
  - condition: or
    conditions:
      - condition: state
        entity_id: binary_sensor.tybf9292188b826c3ed6cqac
        state: 'on'
action:
  - service: notify.notify
    data:
      message: away
mode: single

Put both sensors in the OR condition. Conditions are AND by default, this means currently it will only fire the action if both sensors are on.

condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: binary_sensor.tybf9292188b826c3ed6cqac
        state: 'on'
      - condition: state
        entity_id: binary_sensor.tybf82b920231699632bjhni
        state: 'on'

thanks - that worked

I am really looking forward to working with Home assistant after using IFTTT etc

Stuart

you could also create a Group with all windows you want to check and use that group as condition.
If one Window in that Group is on the Group state will be on, similar to an OR condition.

condition:
  - condition: state
    entity_id: group.all_windows
    state: 'on'

A litte template for the notify message i am using would also tell you wich Window is open,
if you are set up a group.

action:
  - service: notify.notify
    data_template:
      message: >
        "{{ states | selectattr('entity_id','in', state_attr('group.all_windows','entity_id')) | selectattr('state','eq','on') | map(attribute='name') | join(', ') }} still open."

There’s no need to do this:

 states | selectattr('entity_id','in', state_attr('group.all_windows','entity_id')) 

You only want to use the entities in the group so there’s no need to start the template by selecting every entity in your system with states and then narrowing it down to just the ones in the group. You only need to do this:

expand('group.all_windows')

Therefore your example is reduced to:

action:
  - service: notify.notify
    data_template:
      message: >
        "{{ expand('group.all_windows') | selectattr('state','eq','on') | map(attribute='name') | join(', ') }} still open."
1 Like

Excellent - 45 years in IT , this is one of the best engineered systems I have seen in a long time