How make sure automations runs between evening and until sunrise

Hi …
Goal is to have sensors that turn on garden lights when some comes home after 22:30 and until sunrise next morning.
‘light_trigger_havegang_group’ is a group with a couple of PIR sensors and door sensor. This group works fine.
Lights are controlled by a shelly 2.5 switch - works fine.

Below script gets stuck in the sunrise condition… and sI e why, as now when I test, before midnight the sun has risen (this morning)…
If I disable the sunrise check - everthing works…

So, how do I do this ? - can it be done in one automation ? or should I make two, one runs from 22:30 until 23:59:59 and another from 00:00:00 until sunrise ?

/Joern

alias: Havegang - Tænder lys efter 2230 ved sensor
description: Automation som tænder og slukker lyset i havegangen
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.light_trigger_havegang_group
    to: "on"
    id: SensorsTriggered
conditions:
  - condition: time
    after: “22:30:00"
  - condition: sun
    before: sunrise
    enabled: true
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.shellyswitch25_c45bbe5f33eb_channel_1
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.shellyswitch25_c45bbe5f33eb_channel_1
mode: restart

Yes. Your problem is that conditions are AND by default. Given that it can’t be both after 10:30 and before sunrise, you simply need to add an OR for those 2 specific conditions.

Thanks…

conditions:
  - or:
      - condition: time
        after: “18:30:00"
      - condition: sun
        before: sunrise
        enabled: true

seems to have done it…

1 Like