Hi Ashley,
I have started using your script after you kindly responded in another post about a problem I was having. Your script has worked brilliantly to solve the issue of my light overloading from a tight loop and refusing to finish a fade.
When I looked at your script I wondered if you have ever considered doing RGB fades in addition to the color temperature fades? I was thinking that you already have most of the logic and it would just be a matter of applying it in triplicate. I wrote a very crude proof of concept that you can try if you’d like. (Clearly this is missing all of the special sauce that makes your script so popular.)
alias: Lights Fader with RGB
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state(light_entity, 'off') }}"
sequence:
- data:
entity_id: "{{ light_entity }}"
action: light.turn_on
- delay: "00:00:01"
- variables:
starting_rgb: >
{{ starting_rgb if starting_rgb is defined else
(state_attr(light_entity, 'rgb_color')[0], state_attr(light_entity,
'rgb_color')[1], state_attr(light_entity, 'rgb_color')[2]) if
state_attr(light_entity, 'rgb_color') is not none else (255, 255, 255)
}}
starting_brightness: >
{{ starting_brightness if starting_brightness is defined else
state_attr(light_entity, 'brightness') | int if state_attr(light_entity,
'brightness') is not none else 255 }}
- data:
name: Lights Fader
message: >-
Captured or provided state: RGB: {{ starting_rgb }}, Brightness: {{
starting_brightness }} for light: {{ light_entity }}
action: logbook.log
- repeat:
count: "{{ steps | int }}"
sequence:
- data_template:
entity_id: "{{ light_entity }}"
rgb_color:
- >-
{{ (starting_rgb[0] + ((ending_rgb[0] - starting_rgb[0]) /
steps) * repeat.index) | int }}
- >-
{{ (starting_rgb[1] + ((ending_rgb[1] - starting_rgb[1]) /
steps) * repeat.index) | int }}
- >-
{{ (starting_rgb[2] + ((ending_rgb[2] - starting_rgb[2]) /
steps) * repeat.index) | int }}
brightness: >-
{{ (starting_brightness + ((ending_brightness -
starting_brightness) / steps) * repeat.index) | int }}
action: light.turn_on
- delay:
milliseconds: "{{ (fade_duration / steps * 1000) | int }}"
variables:
light_entity: "{{ light_entity }}"
ending_rgb: "{{ ending_rgb | default([255,255,255]) }}"
ending_brightness: "{{ ending_brightness | default(100) }}"
fade_duration: "{{ fade_duration | default(20) }}"
steps: "{{ steps | default(100) }}"
mode: single
description: >
Fade between two RGB colors or fade from the current state of the light to a
target RGB color
icon: mdi:color-helper
Then I just did a few very basic actions in an automation.
With Starting RGB and Brightness provided:
action: script.lights_fader_with_rgb
data:
light_entity: light.master_led_strip
starting_rgb: [170,13,5]
starting_brightness: 1
ending_rgb: [40,40,200]
ending_brightness: 200
fade_duration: 20
steps: 30
Starting from the current state of the light:
action: script.lights_fader_with_rgb
data:
light_entity: light.master_led_strip
ending_rgb: [40,40,200]
ending_brightness: 200
fade_duration: 20
steps: 30