Converting Shelly RGBW2 Color/White mode into a "CCT mode"

I am using a Shelly RGBW2 relay to power two CCT led strips. One strip is connected R for WW and G for CW colors. Second strip is connected similarly to BW for WW and CW colors.

While Shelly RGBW2 does support only RGBW or 4x White LED strips mode the light visualization is shown (logically) as RGBW or 4xW.

While I’ve met some tutorials on how to set Shelly via MQTT to do that I’ve never seen a tutorial how to modify one of these modes (RGBW or 4x White) into a CCT mode while having native Shelly integration.

So my question is if there is an option to convert a light (not just a visualization of a card) from RGBW/4xW mode into a CCT mode using native Shelly integration + some modifications e.g. in config file? I am using also a Homekit Bridge to produce those devices into a Homekit. Therefore I want Homekit to recognize this as CCT.

1 Like

Okay. So I’ve made the code already using “light template” that converts two channels for Shelly RGBW2 and converts them into a CCT LED with a temperature slider.

In case this helps to anyone:

info:
I am using two channels for one light. One channel is light.cw1 and the second channel is light.ww1.

steps to perform:

  1. you need to create a two number “helper” objects called:
  • helper_brightness_level_1 (this one should have values from 0 to 255)
  • helper_temperature_ratio_1 (this one should have values from 0 to 100)
  1. edit configuration.yaml to include “light template”

light.yaml follows:

- platform: template
  lights:
    four_white_to_cct_1:
      friendly_name: "light-edge-1"
      value_template: >
        {% if is_state('light.cw1', 'on' ) or is_state('light.ww1', 'on' ) %}
          on
        {% else %}
          off
        {% endif %}
      turn_on:
        service: light.turn_on
        target:
          entity_id:
          - light.cw1
          - light.ww1
      turn_off:
        service: light.turn_off
        target:
          entity_id:
          - light.cw1
          - light.ww1
      min_mireds_template: "{{ (1000000/6500)|round }}"
      max_mireds_template: "{{ (1000000/2700)|round }}"
      level_template: >
        {{ states('input_number.helper_brightness_level_1') }}
      temperature_template: >
        {{ states('input_number.helper_temperature_ratio_1')|int }}
      set_level:
        - service: input_number.set_value
          data:
            value: "{{ brightness }}"
            entity_id: input_number.helper_brightness_level_1
        - service: light.turn_on
          data:
            brightness: >
              {% set helper_temp_slider = states('input_number.helper_temperature_ratio_1') %}
              {% set cold = helper_temp_slider|int %}
              {% set brightness_ratio = (brightness/255)|round(2) %}
              {% set cold_light_brightness_level = (cold * brightness_ratio * 2.55)|int %}
              {{ cold_light_brightness_level }}
            entity_id: light.cw1
        - service: light.turn_on
          data:
            brightness: >
              {% set helper_temp_slider = states('input_number.helper_temperature_ratio_1') %}
              {% set warm = (helper_temp_slider|int) - 100 %}
              {% set brightness_ratio = (brightness/255)|round(2) %}
              {% set warm_light_brightness_level = (warm * brightness_ratio * 2.55)|int %}
              {{ warm_light_brightness_level|abs }}
            entity_id: light.ww1
      set_temperature:
        - service: input_number.set_value
          data:
            value: >
              {% set kelvin_temp = (1000000/color_temp)|int %}
              {% set helper_temp_slider = ((kelvin_temp - 2700) * 0.0263)|int %}
              {{ helper_temp_slider }}
            entity_id: input_number.helper_temperature_ratio_1
        - service: light.turn_on
          data:
            brightness: >
              {% set brightness = states('input_number.helper_brightness_level_1')|int %}
              {% set kelvin_temp = (1000000/color_temp)|int %}
              {% set helper_temp_slider = ((kelvin_temp - 2700) * 0.0263)|int %}
              {% set brightness_ratio = (brightness/255)|round(2) %}
              {% set cold_light_brightness_level = (helper_temp_slider * brightness_ratio * 2.55)|int %}
              {{ cold_light_brightness_level }}
            entity_id: light.cw1
        - service: light.turn_on
          data:
            brightness: >
              {% set brightness = states('input_number.helper_brightness_level_1')|int %}
              {% set kelvin_temp = (1000000/color_temp)|int %}
              {% set helper_temp_slider = (((kelvin_temp - 2700) * 0.0263)|int) -100 %}
              {% set brightness_ratio = (brightness/255)|round(2) %}
              {% set warm_light_brightness_level = (helper_temp_slider * brightness_ratio * 2.55)|int %}
              {{ warm_light_brightness_level | abs }}
            entity_id: light.ww1
1 Like

Hi @koblihac,

thank you a lot, works great for me!
One question: Even if it works and the output is fine, I cannot see the slider moving or the position of the slider for temperature. The numbers above, however, are changing. Regarding brightness, behaviour is fine… Please see video below. Any idea? Maybe input number for temperture should be switched to mireds?

Screen_Recording_20230927_213436_Home-Assistant-4

Thank you a lot and all the best
Benedikt

And it seems min/max temperature are transposed?

I think this might be the failure. Your temperature ratio helper (allowing values in between 0 and 100) is fine for adjusting cw and ww light brightness but not for the temperature_template value expecting mired values in between 153 and 500.

As a result, no value can be defined for the attribute color_temp.

Can you help me fixing this issue? :slight_smile:

Hello,

Thank you for this tutorial.
worked like a charm with my Shelly RGBW and a professionally installed LED Light.

One thing is odd though: When I try to use the light in a scene or a script/automation it does not apply the brightness.

Any idea why?

Thanks…
Akio

Hey @Mngsps,

there was an issue in which I’ve improperly stated what is min_mired and max_mired value. So basically I switched 2700K for 6500K and vice versa.

I’ve edited the code in my second post so now it is completely okay.

Changed lines:

min_mireds_template: "{{ (1000000/6500)|round }}"
max_mireds_template: "{{ (1000000/2700)|round }}"

I hope the solution will work for everyone.

Thank you.

I have recently installed a Shelly RGBW2 to control a warm + cold white led light strip. Having spent quite some time browsing the HA forums for a similar setup to mine, I quickly realized that HA templates were not the most appropriate solution, given the amount of tasks that they would need to cover inside the (quite limited) templating language:

  • checking the input for out-of-bound values
  • handling a request to set only the color temperature OR only the brightness OR both the color temperature + brightness
  • keeping track of the previous state

I decided therefore for a more direct approach, arriving at the following custom integration:

I would greatly appreciate some feedback if you would like to try it out, before making an official post on this forum for all the rest of the community to see…

Good work! Very good solution.
Unfortunately, the switching does not work well. It doesn’t remember the last status and then switches on random values.

I just refactored the code related to this part the other day, maybe I introduced some unexpected bugs unfortunately.

Can you please attach (here or on a Github issue) the diagnostic generated from the HA UI?

Here are the official instruction for getting the logs and debug data.

EDIT: I just released version 0.1.1 with the appropriate fix. If there are still problems please let me know.

2 Likes

Excellent work! I appreciate that these settings are made within the UI so we don’t have to depend on the template and yaml configurations.

I’ve submitted one defect (missing icon) and one feature request (brightness shouldn’t override temperature value). I appreciate the enhancement is a documented, known limitation and the current design may be desired by some. However; in my house I’ll find people unnecessarily set lights to 100% which overrides the temperature while I installed lights with the intention of prioritizing temperature.

Thank you for the contribution!

1 Like

Nice work @mion00 ! Your card looks nice, is the code behind it available?

Great integration! This looks very promising. I have one question though: how would this work with one Shelly RGBW2, with cold white on white, and warm white on red? In the setup of the integration I van only choose the Shelly itself, not the different channels.

Hello!
It seems that Shelly RGBW2 is being discontinued.
Does anyone know if Shelly RGBW PM is also supported?

Thank you