Elegant way to simulate a transition?

Hi all,

I’ve got a light bulb not supporting the attribute transition. So I’ve created a script to do the following:

turn_on_lidl_e14_stepwise:
  alias: E14
  sequence:
    - service: light.turn_on
      data:
        brightness_pct: 1
      target:
        entity_id: light.lidl_e14_weiss
    - delay:
        seconds: 9
    - service: light.turn_on
      data:
        brightness_pct: 2
      target:
        entity_id: light.lidl_e14_weiss
    - delay:
        seconds: 9
    - service: light.turn_on
      data:
        brightness_pct: 3
      target:
        entity_id: light.lidl_e14_weiss
    - delay:
        seconds: 9
....

It works - within 15 minutes, it goes from 1% brightness to 100%.

But it’s basically just a simple loop, always waiting 9 seconds before incrementing the value brightness.

Is there a better way to transform those 704 lines into, let’s say, < 10 lines?

Thanks,
Fridolin

Use the repeat until service: Script Syntax - Home Assistant

Repeatedly increment the brightness and delay actions the until the brightness is 100%.

1 Like

Thanks a lot. Should have kept on reading.

The following isn’t more compact but can be applied to any light:

You can use the script in an action like this:

action:
  - service: script.light_fader
    data:
      light: light.lidl_e14_weiss
      transition: '00:15:00'

It calculates the optimal dimming interval based on the specified duration length. All credit goes to community member mysnyds. All I did was refactor it.

1 Like

Nice one. Thank you for your work.
I guess I first need some time to understand, what’s been coded there, but I definitely like the commented version you’ve provided.