So, you trigger is motion detection, your conditions are the time window though, I’d suggest not a fixed time offset, but a sun elevation. The elevation is consistent for light levels through the year.
This cookbook example and this article will be useful
One boolean to indicate you’re controlling the light with the automation:
input_boolean
motion_light:
initial: off
One automation to turn the light on, if it’s off:
- alias: "Motion causes a dim light"
trigger:
- platform: state
entity_id: binary_sensor.your_motion_sensor_here
to: 'on'
condition:
# Only turn the light on if it's already off
- condition: state
entity_id: light.your_light_here
state: 'off'
# Require the sun elevation to be between -3 and +3 degrees - tune to suit
- condition: numeric_state
entity_id: sun.sun
above: -3
below: 3
value_template: '{{ state_attr("sun.sun", "elevation") }}'
action:
# Turn on the boolean to show we're controlling the light with the automation
- service: input_boolean.turn_on
entity_id: input_boolean.motion_light
# Turn on the light at 5%
- service: light.turn_on
data:
entity_id: light.your_light_here
brightness_pct: 5
One to turn it off after two minutes:
- alias: "No motion brings the darkness back"
trigger:
- platform: state
entity_id: binary_sensor.your_motion_sensor_here
to: 'off'
for: '00:02:00'
condition:
# Only turn it off if it's on
- condition: state
entity_id: light.your_light_here
state: 'on'
# Only turn it off if the automation turned it on
- condition: state
entity_id: input_boolean.motion_light
state: 'on'
action:
- service: light.turn_off
data:
entity_id: light.your_light_here
And, finally, one to turn off the input boolean when the light turns off:
- alias: "If the light is off, so is the magic"
trigger:
- platform: state
entity_id: light.your_light_here
to: 'off'
condition:
# Harmless to not have the condition check
- condition: state
entity_id: input_boolean.motion_light
state: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.motion_light
You can build in other logic, like an automation to detect if the light was turned above 5% brightness and then turn off the boolean too:
- alias: "Turn it up and I turn it off"
trigger:
- platform: numeric_state
entity_id: light.your_light_here
# 13 is roughly 5% of 255, the maximum brightness
above: 14
value_template: '{{ state_attr("light.your_light_here", "brightness") }}'
condition:
- condition: state
entity_id: input_boolean.motion_light
state: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.motion_light