Increase/decrease brightness based on motion sensor

I have a working automation that turns on the corridor light based on sunset.
What I try to accomplish is increase the brightness based on motion sensor and decrease the brightness again back to the old state after a few minutes when no motion is detected.

Brightness when light turns on based on sunset: 128

The first part of the automation is working when motion is detected:

- id: sensor_corridor_on
  alias: Increase brightness when movement
  trigger:
    platform: state
    entity_id: binary_sensor.tradfri_motion_sensor_2
    to: 'on'
  condition:
    condition: state
    entity_id: light.dimmable_light_1
    state: "on"
  action:
    service: light.turn_on
    entity_id:  light.dimmable_light_1
    data:
      brightness: 254
      transition: 3
- id: sensor_corridor_off_3_min
  alias: Decrease brightness 3 minutes after last motion
  trigger:
    platform: state
    entity_id: binary_sensor.tradfri_motion_sensor_2
    to: 'off'
    for:
      minutes: 3
  condition:
    condition: state
    entity_id: light.dimmable_light_1
    state: "on"
  action:
    service: light.turn_on
    entity_id: light.dimmable_light_1
    data:
      brightness: 128
      transition: 15

I understand that last action doesn’t work because light is already on.
How can I decrease brightness when light is on or go back to previous brightness: 128

That should work, are you sure you’re waiting a full 3 minutes with definitely no motion? Try reducing the ‘for’ time as a test.

1 Like

And it is working ineed. :slight_smile:
Somehow I didn’t wait long enough.
Thanks for looking at it!

1 Like