Automation works, but occurs all day

I’m trying to get my garage lights to come on only during “darkness” a little before sunset and a little after sunrise the next day

The automation works, when one or both doors are open, the lights stay on, when both are closed, the lights go off. The issue is that this behavior occurs during any time of the day…

- id: '1637856127265'
  alias: Garage Lights
  description: Garage Lights On when any door is open between sunset and sunrise
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_door_sensor
  - platform: state
    entity_id: binary_sensor.house_garage_door_sensor
  condition:
  - condition: or
    conditions:
    - condition: sun
      before: sunset
      before_offset: -00:30:00
    - condition: sun
      before: sunrise
      before_offset: 00:30:00
  action:
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: binary_sensor.garage_door_sensor
          state: 'on'
        - condition: state
          entity_id: binary_sensor.house_garage_door_sensor
          state: 'on'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.garage
    - conditions:
      - condition: and
        conditions:
        - condition: state
          entity_id: binary_sensor.garage_door_sensor
          state: 'off'
        - condition: state
          entity_id: binary_sensor.house_garage_door_sensor
          state: 'off'
      sequence:
      - service: switch.turn_off
        target:
          entity_id: switch.garage
    default: []
  mode: single

Use only one condition, example:

   condition:
      - condition: sun
        after: sunset
        after_offset: "-01:00:00"

By doing that, what happens the next morning after midnight though?

Made the change, bu that did not fix it, I still get the lights in the middle of the day

It be will not triggered.

Did you refresh/reload automation?

Yep, sure did. Still being triggered…

I want the lights to come on 30 minutes before sunset AND 30 minutes before sunrise the following morning, so I don’t think your code will work for what I want

I think I figured it out, at least is not coming on any more. Had to change the sunset condition to “after” and then set an after offset negative time…

- id: '1637856127265'
  alias: Garage Lights
  description: Garage Lights On when any door is open between sunset and sunrise
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_door_sensor
  - platform: state
    entity_id: binary_sensor.house_garage_door_sensor
  condition:
  - condition: or
    conditions:
    - condition: sun
      after: sunset
      after_offset: -00:30:00
    - condition: sun
      before: sunrise
      before_offset: 00:30:00
  action:
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: binary_sensor.garage_door_sensor
          state: 'on'
        - condition: state
          entity_id: binary_sensor.house_garage_door_sensor
          state: 'on'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.garage
    - conditions:
      - condition: and
        conditions:
        - condition: state
          entity_id: binary_sensor.garage_door_sensor
          state: 'off'
        - condition: state
          entity_id: binary_sensor.house_garage_door_sensor
          state: 'off'
      sequence:
      - service: switch.turn_off
        target:
          entity_id: switch.garage
    default: []
  mode: single