Hi,
I wanted to control my dual-white LED stripes (CCT) in our kitchen. The LED controller is a Shelly RGBW2 which natively only supports RGBW or single color white stripes.
The solution was to connect two LED channels (CW & WW) to two Shelly Channels, set the Shelly to white mode and have Home Assistant do work.
You need:
- A light template for the logic and as the final CCT Light entity
- Three helper variables
Calculated CCT Brightness > input_number.kuche_arbeitslicht_helligkeit
Value Range 0-255
Calculated CCT Color Temperature > input_number.kuche_arbeitslicht_farbtemperatur
When you want to keep orignial color values convert your stripes range in K to MIRED (e.g. 2700-6500 K equals 153-370 MIREDS)
When you want to use the full slider range in Lovelace use 153 to 500
Calculated CCT Color Ratio between CW and WW inputs > input_number.kuche_arbeitslicht_cw_ww
Value Range 0-100 (as percent)
Here is the magic:
- Set the template values to the helper variables, DO NOT calculate them directly in the template itself
- Set temperature script
Set Helper value to the slider value (when using original color values make sure to use min/max limit because the silder always allows values between 153 and 500 MIREDS)
Calculate Color Ratio and set helper value
Set Cold White Channel brightness to selected temperature times Ratio Helper Value in Percent
Set Warm White Channel brightness to selected temperature times (1 - Ratio Helper Value in Percent) - Set level script
Set helper value to selected brightness
Set Cold Warm Channel brightness to selected brightness times Ratio Helper Value in Percent
Set Warm White Channel brightness to selected brightness times (1 - Ratio Helper Value in Percent)
- platform: template
lights:
kuche_arbeitslight_cct:
friendly_name: "Küche Arbeitslicht"
level_template: "{{ ( states('input_number.kuche_arbeitslicht_helligkeit' ) | int(0) ) }}"
temperature_template: "{{ ( states('input_number.kuche_arbeitslicht_farbtemperatur' ) | int(0) ) }}"
value_template: >
{% if is_state('light.kuche_arbeitslicht_cw', 'on' ) + is_state('light.kuche_arbeitslicht_ww', 'on' ) > 0 %}
on
{% else %}
off
{% endif %}
turn_off:
service: light.turn_off
data: {}
target:
entity_id:
- light.kuche_arbeitslicht_cw
- light.kuche_arbeitslicht_ww
turn_on:
service: light.turn_on
data: {}
target:
entity_id:
- light.kuche_arbeitslicht_cw
- light.kuche_arbeitslicht_ww
set_temperature:
- service: input_number.set_value
data:
value: "{{ color_temp }}"
# with original color values set lower and upper limits: "{{ [ [ color_temp, 200 ] | max, 370 ] | min }}"
entity_id: input_number.kuche_arbeitslicht_farbtemperatur
- service: input_number.set_value
data:
value: "{{ [ [ ( -1/347 * states( 'input_number.kuche_arbeitslicht_farbtemperatur' ) | int + 500 / 347 ) * 100, 0 ] | max, 100 ] | min }}"
# with original color values: replace 500 with upper limit, replace 347 with upper limit minus lower limit (e.g. 370-200 = 170)
entity_id: input_number.kuche_arbeitslicht_cw_ww
- service: light.turn_on
data:
brightness: "{{ ( this.attributes.brightness | int(0) ) * states( 'input_number.kuche_arbeitslicht_cw_ww' ) | int / 100 }}"
entity_id: light.kuche_arbeitslicht_cw
- service: light.turn_on
data:
brightness: "{{ ( this.attributes.brightness | int(0) ) * ( 1 - states( 'input_number.kuche_arbeitslicht_cw_ww' ) | int / 100 ) }}"
entity_id: light.kuche_arbeitslicht_ww
set_level:
- service: input_number.set_value
data:
value: "{{ brightness }}"
entity_id: input_number.kuche_arbeitslicht_helligkeit
- service: light.turn_on
data:
brightness: "{{ brightness * states( 'input_number.kuche_arbeitslicht_cw_ww' ) | int / 100}}"
entity_id: light.kuche_arbeitslicht_cw
- service: light.turn_on
data:
brightness: "{{ brightness * ( 1 - states( 'input_number.kuche_arbeitslicht_cw_ww' ) | int / 100 ) }}"
entity_id: light.kuche_arbeitslicht_ww