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
tom_l
May 1, 2021, 3:04pm
2
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.
123
(Taras)
May 1, 2021, 4:24pm
4
The following isn’t more compact but can be applied to any light:
Here is a script version of mrsnyds original work. Be advised this script is not identical to the original automation version. It uses the same algorithm but with several differences:
Uses light not entity_id
The option to specify the light(s) to be dimmed is named light instead of entity_id. The reason is because when you call a script using the script.turn_on service, you specify which script to turn on by setting the service’s entity_id option. This is the same name, so the script’s varia…
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.