Working with two different conditions

I have this automation to lighten the lights at 1 o’clock in the night and to turn off at sunrise with an offset, but it is not working as expected:

- alias: Accendi Luce Camera Letto Notte
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0001a92ca1
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: time
        after: 01:00:00
      - condition: sun
        before: 'sunrise'
        before_offset: "-00:45:00"
  action:
    - service: light.turn_on
      entity_id:
        - light.yeelight_3
        - light.yeelight_4
      data:
        transition: 15
        color_name: green
    - delay: 00:00:45
    - service: light.turn_off
      entity_id:
        - light.yeelight_3
        - light.yeelight_4

I know in this way the automation is triggered for all the day from 1 o’clock in the night to the next sunrise. How to make it working as i want?

So it looks to me like you want the lights to come on with motion (that’s the trigger in your automation), but only between the hours of 1am and 45 minutes before sunrise), then you want the lights to stay on for 45 seconds and then turn off.

Maybe try an AND vs an OR in your condition. You want it to be after 1AM AND 45 minutes before sunrise

EDIT: Actually condtions are automatically ANDs so

  condition:
      - condition: time
        after: 01:00:00
      - condition: sun
        before: 'sunrise'
        before_offset: "-00:45:00"

Formatting might be a bit off,but you should get the gist

Ok, thanks… i’ll try it…