Misunderstanding conditions in Automation "and" or the calling of a script

Yesterday an automation functioned differently than expected.

The automation is as follows:

- id: Garage_Open_Arrival_Automation
  alias: Garage_Open_Arrival_Automation
  description: ""
  trigger:
    - entity_id: device_tracker.iphone_of_me
      event: enter
      platform: zone
      zone: zone.home
  condition:
    - condition: state
      entity_id: binary_sensor.garage_door_sensor
      state: "off"
    - condition: state
      entity_id: input_boolean.arriving_person_boolean
      state: "on"
    - condition: and
      conditions:
        - condition: state
          entity_id: binary_sensor.alarm_arm
          state: "off"
        - condition: state
          entity_id: binary_sensor.alarm_sleep
          state: "off"
        - condition: state
          entity_id: binary_sensor.alarm_stay
          state: "off"
  action:
    - data: {}
      service: script.garage_door_open_script

So what was the case, according to my history:

  • The garage_door_open_script got executed and is only used in my code in the above automation
  • The automation did not get triggered
  • the arriving_person_boolean was on, the garage_door_sensor was closed and alarm_arm was off, alarm_sleep was off and alarm_stay was on

So, the condition should have failed (alarm_stay was on), and the automation should not have triggered.
The automation appears not to have triggered in the history.
However, the script got called and my garage door opened (with the alarm on…).

So… I’m not sure what happened. Any help in how to debug this?

Edit: so my automation did get triggered if I look in the logbook - it appears my conditions succeeded, which should not have happened since alarm_stay was “on”. Or I am misunderstanding it.

Correct me if I’m wrong, aren’t conditions by definition “and”?

If you have conditions A, B, C, all 3 need to be true before the automation action is called. So the behavior of the automation you describe is as expected I believe.

How is the garage door connected to Home Assistant? Any electrical issue that might have triggered the garage door?

Nothing to see in the logbook what triggered the script?

1 Like

You are not wrong.

This:

  condition:
    - condition: state
      entity_id: binary_sensor.garage_door_sensor
      state: "off"
    - condition: state
      entity_id: input_boolean.arriving_person_boolean
      state: "on"
    - condition: and
      conditions:
        - condition: state
          entity_id: binary_sensor.alarm_arm
          state: "off"
        - condition: state
          entity_id: binary_sensor.alarm_sleep
          state: "off"
        - condition: state
          entity_id: binary_sensor.alarm_stay
          state: "off"

Is the same as:

  condition:
    - condition: state
      entity_id: binary_sensor.garage_door_sensor
      state: "off"
    - condition: state
      entity_id: input_boolean.arriving_person_boolean
      state: "on"
    - condition: state
      entity_id: binary_sensor.alarm_arm
      state: "off"
    - condition: state
      entity_id: binary_sensor.alarm_sleep
      state: "off"
    - condition: state
      entity_id: binary_sensor.alarm_stay
      state: "off"
2 Likes