Why don't this work? (before: sunrise)

Why won’t this work?
I want it to only run after 22:30 and before sunrise. If I remove the sun part it works.

outside_lights_night:
  sequence:
    - condition: time
      after: '22:30:00'
    - condition: sun
      before: sunrise
    - service: light.hue_activate_scene
      data:
        group_name: 'Outside'
        scene_name: 'Outside - Night'
```

That should work, but you might also consider looking for sun.sun being “below_horizon”

- condition: state
  entity_id: sun.sun
  state: 'below_horizon'

I think when you have two conditions they are “anded”. The trick about time is that after midnight, time resets to the next day. So your after 22:30:00 fails, because it’s now before 22:30:00 the next day. Look at automation conditions https://home-assistant.io/getting-started/automation-condition/

@turboc is correct. When you put conditions in a sequence, the sequence stops the first time you have a false condition. In a sequence, the conditions don’t have to be first. You can basically say “do this, check to see if a condition is true, do this other thing, check another condition, do the last thing” by inserting conditions into a sequence.

So how would I write this?

The reason for this is that I have different scenes for a room depending on time of day, I have each scen setup as a script then I have a main script like “room_lights_on” that calls all scenes/scripts and depending on time of day only one should trigger.

I would play with something like this. I haven’t tested it, but I think it’s in the right direction.

trigger:
  platform: sun
  below: horizon
condition:
  condition: or
  conditions:
    - condition: time
      after: '22:30:00'
    - condition: sun
      before: sunrise
action:
  - service: light.hue_activate_scene
    data:
      group_name: 'Outside'
      scene_name: 'Outside - Night'

Thank you @turboc but can I really use triggers in scripts?

I don’t want it to trigger but run when called if it’s within the conditions.

Just to avoid any confusion on what I’m trying todo, here is my full code:

## Outdoor Lights
outside_lights_evening:
  sequence:
    - condition: sun
      after: sunset
      after_offset: '-00:30:00'
    - condition: time
      before: '22:30:00'
    - service: light.hue_activate_scene
      data:
        group_name: 'Outside'
        scene_name: 'Outside - Evening'
outside_lights_night:
  sequence:
    - condition: time
      after: '22:30:00'
    - condition: sun
      before: sunrise
    - service: light.hue_activate_scene
      data:
        group_name: 'Outside'
        scene_name: 'Outside - Night'
outside_lights_day:
  sequence:
    - condition: sun
      after: sunrise
    - condition: sun
      before: sunset
      before_offset: '-00:30:00'
    - service: shell_command.phue_outside_off
outside_lights_on:
  alias: 'Outside Lights On'
  sequence:
    - service: script.outside_lights_evening
    - service: script.outside_lights_night
    - service: script.outside_lights_day
outside_lights_off:
  alias: 'Outside Lights Off'
  sequence:
    service: shell_command.phue_outside_off

I don’t know, I’m fairly new to this. I just see it as three automations instead of a script. And I’m really not sure about sequencing conditions. That idea is new to me. Sorry I can’t be more help.

This seams to work.

outside_lights_night:
  sequence:
    - condition: or
      conditions:
        - condition: time
          after: '22:30:00'
        - condition: sun
          before: sunrise
    - service: light.hue_activate_scene
      data:
        group_name: 'Outside'
        scene_name: 'Outside - Night'

Great,
The structure of the condition statement takes some getting used to. but basically it’s just or’ing your conditions so if it’s after 22:30 at night OR it’s before sunrise then it’s successful. that way the problem you run into with time when it crosses midnight is taken care of by the before sunrise and doesn’t impact you.