Is this condition correct?

Hi! Changing a little bit my alarm automation. Would like to make sure if I got right how conditions works with ‘or’:

  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: disarmed
      - condition: state
        entity_id: group.family
        state: home
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.motion_sensor_158d00031b4772
            state: 'on'
          - condition: state
            entity_id: binary_sensor.motion_sensor_158d0003667bcb
            state: 'on'

Am I saying this in code?

  • alarm panel has to be ‘disarmed’
  • group family has to be ‘home’
  • one or both of two motion sensors should be on

Looks good. This would also work though:

  condition:
    - condition: state
      entity_id: alarm_control_panel.ha_alarm
      state: disarmed
    - condition: state
      entity_id: group.family
      state: home
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.motion_sensor_158d00031b4772
          state: 'on'
        - condition: state
          entity_id: binary_sensor.motion_sensor_158d0003667bcb
          state: 'on'

Conditions are AND by default, so you don’t need to specify condition: and at the very top. Either works though.

2 Likes