Automation for Gradually Increasing Brightness

Hi,
I managed to create automation that switches lights on when motion is detected and off when no motion detected. However, I want to go further step by making the brightness of the lights 20% when motion is first triggered, then the brightness increases as long as motion duration increases. Any ideas how to do that?

Here is the code I have now for the automation:

alias: Hallway Light On/Off by Motion
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.human_motion_sensor_motion
      to: “on”
      id: Motion_On
      for:
      hours: 0
      minutes: 0
      seconds: 30
  • platform: state
    entity_id:
    • binary_sensor.human_motion_sensor_motion
      to: “off”
      id: Motion_Off
      condition: []
      action:
  • choose:
    • conditions:
      • condition: trigger
        id:
        • Motion_On
          sequence:
      • service: light.turn_on
        data:
        brightness_pct: 20
        target:
        entity_id: light.hallway_lamp_2
  • choose:
    • conditions:
      • condition: trigger
        id:
        • Motion_Off
          sequence:
      • service: light.turn_off
        data: {}
        target:
        entity_id: light.hallway_lamp_2
        mode: single

Here’s one way:

  action:
    - repeat:
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: light.sunroom_lights_zw033
              brightness: >-
                {% set sr1_current = states.light.sunroom_lights_zw033.attributes.brightness|default(0)|int %}
                {% set sr1_step = 2 %}
                {% set sr1_brightness = sr1_current - sr1_step %}
                {% if sr1_brightness < 73 %}
                  {% set sr1_brightness = 73 %}
                {% endif %}
                {{ sr1_brightness }}
          - delay: "00:05:00"
        until:
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.sunroom_lights_zw033', 'brightness') == 73 }}"
              - "{{ repeat.index >= 24 }}"
              - "{{ states.light.sunroom_lights_zw033.state == 'off' }}"
              - "{{ states.input_boolean.sr_slow_dim.state == 'off' }}"
#

The basic approach is this;
Get the current brightness
Define the amount to go up or down (I’m using 2)
Set the new brightness value (note VALUE, not State)
Test to see if new value is within defined range
Set the brightness State
Delay a set time period
The UNTIL portion defines when to stop ramping.

  • at no less than 73
  • no more than 24 decrements (loops/steps)
  • if the light turns off
  • if the input boolean that controls the dimming is turned off.

Hope this helps.

And here’s another way… :slightly_smiling_face:

I use this to ramp up the brightness at dusk for my deck light. you’ll need to adjust the step and delay to get the timing you want.

  - alias: LC Deck Light Fade On at Dusk
    id: lc_deck_light_fade_on_at_dusk
    initial_state: 'on'
    mode: restart
    trigger:
      - platform: sun
        event: sunset
        offset: "+00:07:00"
    condition:
      - condition: state
        entity_id: light.deck_light
        state: 'off'
    action:
      - service: light.turn_on
        data:
          entity_id: light.deck_light
          brightness: 5
      - delay: 2
      - repeat:
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.deck_light
                brightness: "{{ state_attr('light.deck_light', 'brightness') | int + 1 }}"
            - delay: 2
          until:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.deck_light', 'brightness') | int >= 254 }}"
              - condition: state
                entity_id: light.deck_light
                state: 'off'

thank you guys for the help. will try these and let you know if i had issues. really useful!

guys, both solutions worked for me.

Thank you indeed.

1 Like