After having looked for a script for sweeping through a range of colors and brightnesses on an RGBW LED strip, I found this post from @TheHolyRoger. Although it is very complete, it was lacking brightness adjustment, and also color ranges from -360 to 360, so that you could select (for example) a “red pallet” from -10 until 40.
blueprint:
name: Fading Hue, Saturation and Brightness
description: Gradually change light colour
domain: script
input:
entity:
name: Entity
description: Which entity to control.
selector:
entity:
max_value_hue:
name: Max Hue Value [-360:360]
description: Max Hue Value
default: 360.0
selector:
number:
min: -360.0
max: 360.0
step: 0.1
mode: box
min_value_hue:
name: Min Hue Value [-360:360]
description: Min Hue Value
default: 0.0
selector:
number:
min: -360.0
max: 360.0
step: 0.1
mode: box
max_value_sat:
name: Max Saturation [0:100]
description: Max Saturation
default: 100.0
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
min_value_sat:
name: Min Saturation [0:100]
description: Min Saturation
default: 0.0
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
max_value_bri:
name: Max Brightness [0:100]
description: Max Brightness
default: 100.0
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
min_value_bri:
name: Min Brightness [0:100]
description: Min Brightness
default: 0.0
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
step_value_hue:
name: Hue Step value
description: Maximum random step value to change each time. [0:360]
default: 30
selector:
number:
min: 0.0
max: 360.0
step: 0.1
mode: box
step_value_sat:
name: Saturation Step value
description: Maximum random step value to change each time. [0:100]
default: 30
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
step_value_bri:
name: Brightness step value.
description: Maximum random step value to change each time. [0:100]
default: 30
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
default_value_hue:
name: Default Hue Value
description: Default starting hue value.
default: 0.0
selector:
number:
min: 0.0
max: 360.0
step: 0.1
mode: box
default_value_sat:
name: Default Saturation
description: Default starting saturation.
default: 100
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
default_value_bri:
name: Default Brightness
description: Default starting brightness.
default: 100
selector:
number:
min: 0.0
max: 100.0
step: 0.1
mode: box
sequence:
- service: light.turn_on
data:
entity_id: '{{ entity }}'
hs_color: "
{% if state_attr(entity, 'hs_color') == None %}
{{ default_colour }}
{% else %}
{% set rand_hue = range(-5000, 5000) | random / 5000.0 | float * step_value_hue %}
{% set rand_sat = range(-5000, 5000) | random / 5000.0 | float * step_value_sat %}
{% set cur_hs = state_attr(entity, 'hs_color') | list %}
{% set cur_hue = float(cur_hs[0]) %}
{% if cur_hue > max_value_hue and cur_hue - 360.0 >= min_value_hue and cur_hue - 360.0 <= max_value_hue %}
{% set cur_hue = cur_hue - 360.0 %}
{% endif %}
{% set new_hue = cur_hue + rand_hue %}
{% if new_hue > max_value_hue %}
{% set new_hue = max_value_hue %}
{% else %}
{% if new_hue < min_value_hue %}
{% set new_hue = min_value_hue %}
{% endif %}
{% endif %}
{% if new_hue < 0.0 %}
{% set new_hue = new_hue + 360.0 %}
{% endif %}
{% set new_sat = float(cur_hs[1]) + rand_sat %}
{% if new_sat > max_value_sat %}
{% set new_sat = max_value_sat %}
{% else %}
{% if new_sat < min_value_sat %}
{% set new_sat = min_value_sat %}
{% endif %}
{% endif %}
{% set new_hs = [new_hue, new_sat] %}
{{ new_hs }}
{% endif %}
"
brightness_pct: "
{% if state_attr(entity, 'brightness') == None %}
{{ default_value_bri }}
{% else %}
{% set rand_bri = range(-5000, 5000) | random / 5000.0 | float * step_value_bri %}
{% set cur_bri_abs = state_attr(entity, 'brightness') | int %}
{% set cur_bri = float(cur_bri_abs) * 100.0 / 255.0 | int %}
{% set new_bri = float(cur_bri) + rand_bri %}
{% if new_bri > max_value_bri %}
{% set new_bri = max_value_bri %}
{% else %}
{% if new_bri < min_value_bri %}
{% set new_bri = min_value_bri %}
{% endif %}
{% endif %}
{{ new_bri }}
{% endif %}
"
transition: 1.0
variables:
entity: !input entity
max_value_hue: !input max_value_hue
min_value_hue: !input min_value_hue
max_value_sat: !input max_value_sat
min_value_sat: !input min_value_sat
max_value_bri: !input max_value_bri
min_value_bri: !input min_value_bri
step_value_hue: !input step_value_hue
step_value_sat: !input step_value_sat
step_value_bri: !input step_value_bri
default_value_hue: !input default_value_hue
default_value_sat: !input default_value_sat
default_value_bri: !input default_value_bri
default_colour:
- !input default_value_hue
- !input default_value_sat
mode: single