OR condition not considered in the execution. Please take a look at my code. Thank you!

SOLVED! Thank you all!

I posted this plea in Reddit (r/homeassistant) yesterday AND today but taken immediately down by the moderator! Why?

Anyway, I used to have two separate automations to turn on the utility room light when motion is triggered - one for the evening after sunset, and one for the morning, before sunrise. I then decided to consolidate the two automations into one with a compound OR condition. Please see my code below. However this is not working. The traces show that when one condition is false, it exits the automation immediately, without going down on the OR condition. What am I doing wrong? I ended up doing two if/then code blocks. Please take a look at my code:

alias: Utility Room Motion Sensor - new
description: Utility room motion sensor will turn on entrance light
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.zz_motion_sensor
    to:
      - "on"
conditions: null
actions:
  - if:
      - condition: sun
        before: sunrise
      - condition: or
        conditions:
          - condition: sun
            after: sunset
    then:
      - action: script.turn_on
        metadata: {}
        target:
          entity_id: script.entrance_light_triggered_by_motion
        data: {}
mode: single

What am I doing wrong? When a false condition is encountered, HA does not go on farther for OR condition!

All things relevant for the or should be inside the or (it is not an infix notation, but a prefix notation). Currently there is only one thing inside the or, so the or is not doing anything.

Furthermore, you are not using the conditions but using an if instead, thich does exactly the same as your conditions. It is not wrong, but unneccessarily complex, plus it will indicate the automation has run while the conditions failed.

alias: Utility Room Motion Sensor - new
description: Utility room motion sensor will turn on entrance light
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.zz_motion_sensor
    to:
      - "on"
conditions: 
  - condition: or
     conditions:
       - condition: sun
         before: sunrise
       - condition: sun
         after: sunset
actions:
  - action: script.turn_on
    metadata: {}
    target:
      entity_id: script.entrance_light_triggered_by_motion
    data: {}
mode: single

You may be able to put before and after in the same sun condition, removing the or in its entirety. Unfortunately I cannot check, because the documentation for this condition seems to be removed with the arrival of the new conditions.

Thank you very much! I don’t know why the moderator in Reddit removed my post immediately. One removal was from a “moderator”.

Update: The moderator put it back into a LIVE post in Reddit!!! Yeah, and I marked it “SOlved”.

Niether do we. Reddit has nothing to do with here. Glad you’re fixed.

If you are on the latest release of HA you can use the sun.is_set condition and avoid the or statement altogether

Here are all the new Sun conditions: Sun - Home Assistant