OR condition odd behavior

Hi All,
I have setup a OR condition in an automation the 1st works but the 2nd doesn’t could some explain to me why.
Thanks

condition: or
conditions:
  - condition: state
    entity_id: device_tracker.iphone
    state: not_home
  - condition: time
    after: '15:00:00'
    before: '07:00:00'

######################################
condition: or
conditions:
  - condition: time
    after: '15:00:00'
    before: '07:00:00'
  - condition: state
    entity_id: device_tracker.iphone
    state: not_home

If you have both in the same automation it won’t work as you can have only one condition block. If you tried each of them separately and it didn’t work, then there is an issue.

1 Like

HI I tried them separately, I tried the 2nd one first and could get it to work correctly so I change it to have the device_tracker 1st and this works

I’m confused now, does it work or not?

#MeeTOO

@gazzaman, post the complete automation blocks for all aliases please.

Sorry I missed typed
it should read " I tried the 2nd one first and couldn’t get it to work, so I change it to have the device_tracker 1st and this works"

This works

alias: motion_detect_hall
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.hall_motion
    from: 'off'
    to: 'on'
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.iphone
        state: not_home
      - condition: time
        after: '15:00:00'
        before: '07:00:00'
action:
  - service: image_processing.scan
    data: {}
    entity_id: image_processing.doods_hall

this does not work

alias: motion_detect_hall
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.hall_motion
    from: 'off'
    to: 'on'
condition:
  - condition: or
    conditions:
    - condition: time
      after: '15:00:00'
      before: '07:00:00'
   - condition: state
     entity_id: device_tracker.iphone
     state: not_home
action:
  - service: image_processing.scan
    data: {}
    entity_id: image_processing.doods_hall

Your indentation on the second one is wrong,you should have an error under Configuration -> Logs

Should be like this:

alias: motion_detect_hall
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.hall_motion
    from: 'off'
    to: 'on'
condition:
  - condition: or
    conditions:
      - condition: time
        after: '15:00:00'
        before: '07:00:00'
      - condition: state
        entity_id: device_tracker.iphone
        state: not_home
action:
  - service: image_processing.scan
    entity_id: image_processing.doods_hall
2 Likes

Thanks I will give it ago when I get home

assuming he hasn’t turned logger off “default: none” in his yaml (or similar)

Who in their sane mind would do that? :rofl:

1 Like

Hi I have had a look at the config and it is correct on the one that didn’t work ,not sure why it didn’t copy ,still the other way works

It makes no difference to homeassistant which order the conditions are in, they’re just items in a list. If it wasn’t working you had a syntax error of some kind, most likely indentation (as 2 spaces back would take it out of the ‘OR’ list and put it in the default ‘AND’ list).

1 Like

Copy my automation 1:1 and test it again, it’s impossible that it works one way but not the other,as Marc said, Home Assistant doesn’t care in which order the conditions are, as long as they are on the same indentation level.

1 Like