Help with conditions and trigger IDs for brightness change

I have an automation that turns on a light after sunset and off at 1am. Works great. Now I want to add brightness change on motion and change again when motion ends but I’m having trouble getting my triggers and conditions to work correctly.

The light comes on just before sunset and off at 1am. I want the brightness to change on motion detection within those times.

alias: Front Light on/off
trigger:
  - event: sunset
    offset: '-00:15:00'
    platform: sun
    id: sunset
  - platform: time
    at: '01:00'
    id: 1am
  - platform: state
    entity_id: binary_sensor.front_door_person_motion
    to: 'on'
    id: motion
  - platform: state
    entity_id: binary_sensor.front_door_person_motion
    id: no motion
    to: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 30
            target:
              entity_id: light.yeelight_mono1_f0b429a93ec5
      - conditions:
          - condition: trigger
            id: 1am
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.yeelight_mono1_f0b429a93ec5
      - conditions:
          - condition: sun
            after: sunset
            after_offset: '-00:15:00'
          - condition: time
            before: '01:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
          - condition: trigger
            id: motion
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 100
            target:
              entity_id: light.yeelight_mono1_f0b429a93ec5
      - conditions:
          - condition: sun
            after: sunset
            after_offset: '-00:15:00'
          - condition: time
            before: '01:00'
            weekday:
              - sun
              - sat
              - fri
              - thu
              - wed
              - tue
              - mon
          - condition: trigger
            id: no motion
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 30
            target:
              entity_id: light.yeelight_mono1_f0b429a93ec5
    default: []

All the functions I want are contained in this single automation using trigger ID’s but clearly I have made mistake. Can anyone spot it? Cause I definitely can not…

change no motion to no_motion

~B

Thanks @beaj but unfortunately that didn’t work.

What does the trace for the automation show when you trigger motion?

it shows the conditions were not met but I can’t see why.
After 00:00:00 shows on the debug but is not in the yaml?

Because the Time Condition checks if the current time is between midnight and the time specified by the before option. See the second line here:

Any time between sunset and midnight won’t meet that criteria.

The documentation explains you can define a time range that spans midnight by specifying before and after. Unfortunately, in your case, after isn’t a fixed time but a floating time (sunset) which is not accepted by the after option.

Thank for you the detailed explanation. I under stand. Is there a way around this? Or do I need to specify a fixed after time?

OR the two conditions.

      - conditions:
          - condition: or
            conditions:
              - condition: sun
                after: sunset
                after_offset: '-00:15:00'
              - condition: time
                before: '01:00'
                weekday: ...etc

This will give you sunset (with offset) to midnight OR between midnight and 1am.

My choice would be to redesign it, relying on a template, but tom_l’s suggestion should give you what you want.