OR condition in automation

I’m trying to get an automation running using the OR condition, following the docs on Conditions - Home Assistant

However, when I use the following code, I get an error

- id: "1623700150767"
  alias: schedule heating
  initial_state: on
  trigger:
    - platform: state
      entity_id: binary_sensor.window_door_sensor
      from: "on"
      to: "off"
  condition: or
  conditions:
    - condition: state
      entity_id:
        - device_tracker.ac2003
        - device_tracker.samsung_galaxy_s7_2
      state: "home"
  action:
    - event: script.radiatorschedule
      event_data: {}
  mode: single

In VSCode I see the following

afbeelding

What is wrong with my code?

I am currently not on a computer, so I am not able to provide a hint on how to fix the condition, if you want to keep it that way, however my proposal would be to define a group of the device trackers. This group will indicate home, if at least one of those two devices is indicated as being home. In this automation, you can then simply check for the group entity.

Two things:

  1. The automation doesn’t have a condition: statement.
  2. The OR only has one condition.

Add a condition: statement and split the two device_tracker entities into separate State Conditions.

  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.ac2003
        state: "home"
      - condition: state
        entity_id: device_tracker.samsung_galaxy_s7_2
        state: "home"

Thanks, I already have a group, so I definitely use that!

look like you missing a indent

  condition:
    condition: or
    conditions:
    - condition: state
      entity_id:
        - device_tracker.ac2003
        - device_tracker.samsung_galaxy_s7_2
      state: "home"
1 Like

Group or not, it’s still missing a condition: statement.

1 Like

Ah, I see, so it should be

- id: "1623700150767"
  alias: schedule heating
  initial_state: on
  trigger:
    - platform: state
      entity_id: binary_sensor.window_door_sensor
      from: "on"
      to: "off"
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.ac2003
        state: "home"
      - condition: state
        entity_id: device_tracker.samsung_galaxy_s7_2
        state: "home"
  action:
    - event: script.radiatorschedule
      event_data: {}

Yes, just like the example shown in my previous post. Without the condition: statement, everything else you entered makes the automation invalid. In addition, if you use condition: or then it needs a minimum of two conditions to be of any value. You had one State Condition referencing two entities.

1 Like

Thanks all for helping out!

If what I suggested has resolved your original problem, please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This is a useful practice that helps users find answers to similar questions.

EDIT

I see you have already marked another post as the Solution. However that one overlooked to mention your automation lacked a condition statement. As a result, other users reading it will assume it’s not necessary (because you chose it as the Solution). In addition, it’s not the lack of using a group that led to an invalid automation but the lack of a condition statement and at least two conditions for the OR.

1 Like

Clicked the wrong answer :zipper_mouth_face:

1 Like