Color fade out

Hi, I would like to do a fade out (decrease brightness 5% every 10 seconds until it reach 1%, then it turn off the light) of my light bulb (entity: light.blub) once i press the switch (entity: switch.abc123). It should capture the brightness of the current brightness initially, for example, if the current brightness is 60%, it should decrease 5% starting from brightness 60% until the end, then turn off the light.

Really appreciate somebody can show me how the coding on this.

this is what I do for my stove hood light for dimming 16 (out of 255) every 250ms:

    action:
      - repeat:
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.stove_hood_light_12d6
                brightness: "{{ state_attr('light.stove_hood_light_12d6', 'brightness') | int - 16 }}"
            - delay:
               milliseconds: 250
          until:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.stove_hood_light_12d6', 'brightness') | int <= 32 }}"
              - condition: state
                entity_id: light.stove_hood_light_12d6
                state: 'off'

You can modify it to fit your use.

In this case it doesn’t matter where it starts. it just dims down until it’s < 32 or off.

1 Like

Hi, i try to use your coding for testing. But, there is error message when i try to save it. Do u know what’s wrong?

alias: light fade out
action:
  - repeat:
      sequence:
        - service: light.turn_on
          data:
            entity_id: light.color5_cloud_586753
            brightness: "{{ state_attr('light.color5_cloud_586753', 'brightness') | int - 16 }}"
        - delay:
           milliseconds: 250
      until:
        condition: or
        conditions:
          - condition: template
            value_template: "{{ state_attr('light.color5_cloud_586753', 'brightness') | int <= 32 }}"
          - condition: state
            entity_id: light.color5_cloud_586753
            state: 'off'
mode: single

That is because you don’t have actions in scripts.
Finity gave you a snippet of an automation.

Try replacing action: with sequence:

and remove mode: single

Also, if your light brightness is in percent then you will need to change that also.

I think you need to change “brightness” to “brightness_pct” and then modify the numbers to be in percentages instead of values between 1 and 255.

My intention is to reduce 5% every 250 millisecond, but it strait away turn off.

alias: light fade out
sequence:
  - repeat:
      sequence:
        - service: light.turn_on
          data:
            entity_id: light.color5_cloud_586753
            brightness: "{{ state_attr('light.color5_cloud_586753', 'brightness_pct') | int - 5 }}"
        - delay:
           milliseconds: 250
      until:
        condition: state
        entity_id: light.color5_cloud_586753
        state: 'off'

I try to use your coding to change the temperature of my RGB light bulb, but it doesn’t decrease the temperature gradually, it will strait away decrease the temperature to 250 or lesser. What’s wrong?

alias: Living hall door opened - Center car porch -  increase brightness (Duplicate)
description: ''
trigger:
  - platform: state
    to: 'on'
    entity_id: binary_sensor.a4b00034ac
    attribute: state
condition:
  - condition: time
    after: '19:30:00'
    before: '07:00:00'
action:
  - repeat:
      sequence:
        - service: light.turn_on
          data:
            entity_id: light.color5_cloud_586753
            color_temp: "{{ state_attr('light.color5_cloud_586753', 'color_temp') | int - 15 }}"
        - delay:
           milliseconds: 250
      until:
        condition: template
        value_template: "{{ state_attr('light.color5_cloud_586753', 'color_temp') | int <= 250 }}"

mode: single

What kind of light is it? Which integration are you using to control the light?

Depending on the light integration, it may not be able to handle a stream of commands separated by only a quarter-second.

But, if i change it to brightness instead of color_temp, it works.

I asked you several times what light integration it uses but you decided it’s not important to answer them.

Good luck and goodbye.

Opps… sorry. I am using Xiaomi MIoT. The type of light blub that i am using is Mi LED Smart Light Bulb Essential (White and Color).