Combine cool white and warm white led strip into one light

try be more precise :wink:

how many wires did the led have and which wire did you put in which hole of the shelly?
i’m guessing 1 in red and one in green by reading the template, however this is brand new for me so i wanted to make sure i understand.
if it is so, would it be possible to do 1 led strip with red and blue and 1 led strip with blue and white?

yes it’s possible however on/off state is common for all channels. So in result you could set brightness and warmth independently, but turn on and off would work for both strips at the same time

hi, How your project works? I think about the same? Is it work?

I just did this and it seems to be working ok. I used a Shelly RGBW2 and tunable white led strip.

# Living Room LED Strips

# Light temperature in mireds is converted to/from color in hue/sat.
#   Warm white values:  Hue = 0 (red has WW led connector), Mireds: 370 (1,000,000 / 2700 K)
#   Cool white values:  Hue = 120 (green has CW led connector), Mireds: 153 (1,000,000 / 6500 K)
#   Saturation always at 100 (100% saturated)

- platform: template
      friendly_name: "Living Room Ledge LED Strip"
      value_template: "{{ is_state('light.living_ledge_rgbw','on') }}"
      level_template: "{{ state_attr('light.living_ledge_rgbw', 'brightness') }}"
      temperature_template: "{{ (state_attr('light.living_ledge_rgbw', 'hs_color')[0] * -1.808333 + 370.3704 ) | round(0) }}"
        - service: light.turn_on
            entity_id: light.living_ledge_rgbw
        - service: homeassistant.update_entity
            entity_id: light.living_ledge_cct
        - service: light.turn_off
            entity_id: light.living_ledge_rgbw
        - service: homeassistant.update_entity
            entity_id: light.living_ledge_cct
        service: light.turn_on
          entity_id: light.living_ledge_rgbw
          brightness: "{{ brightness }}"
        service: light.turn_on
          entity_id: light.living_ledge_rgbw
            - "{{ ( color_temp * -0.552995 + 204.608298 ) | round(0) }}"
            - 100
      min_mireds_template: "{{ 153 }}"
      max_mireds_template: "{{ 370 }}"
1 Like

Is templating like this possible if shelly rgbw2 is configured as four white cannels?

If yes, can you show me how?

@lpt2007 Hi! Sorry it took me a while to get back to you. I’ve never used a Shelly RGBW2 with 4 white channels but I think it would be possible.

Here’s the HA documentation for the template light:

The on/off should be pretty straight forward against the two lights instead of one. You’ll need to build some logic for the temperature_template, level_template, set_level, and set_temperature.

For example, to get the temperature_template you might start with a formula like this:
cool_light_brightness / (warm_light_brightness + cool_light_brightness) to get a “% cool” value.

Then you could use “% cool” to determine mireds. (100% cool means 153 mireds, 0% cool means 370 mireds.) Assuming this is linear, the final equation for your temperature_template might look like this:

mireds = - 2.17 * (cool_light_brightness / (warm_light_brightness + cool_light_brightness)) + 370

You’d reverse the process to know how to assign the cool and warm light brightness given mired value.

Thx for reply.

I already find solution here:

Is still little buggy, but working:)

Hey! Thanks for this. May I know how did you do the calculations, so I know how to adjust it if I connected the cool one into blue (instead of green) and warm white into white (instead of red)?

Anyway, in the end, I flashed ESPHome OTA: Shelly 2.5: Flash ESPHome Over The Air! | with this config and it works perfectly:

  device_name: bottommirror

  name: ${device_name}
  platform: ESP8266
  board: esp01_1m


  ssid: !secret wifi_ssid
  password: !secret wifi_password


  - platform: cwww
    name: "Bottom Bathroom Mirror"
    cold_white: ${device_name}_out_ch3
    warm_white: ${device_name}_out_ch4
    cold_white_color_temperature: 6500 K
    warm_white_color_temperature: 2700 K
    constant_brightness: false

# Example output entry
  - platform: esp8266_pwm
    id: ${device_name}_out_ch1
    pin: GPIO12
    frequency: 1000 Hz
  - platform: esp8266_pwm
    id: ${device_name}_out_ch2
    pin: GPIO15
    frequency: 1000 Hz
  - platform: esp8266_pwm
    id: ${device_name}_out_ch3
    pin: GPIO14
    frequency: 1000 Hz
  - platform: esp8266_pwm
    id: ${device_name}_out_ch4
    pin: GPIO4
    frequency: 1000 Hz

  - platform: wifi_signal
    name: "${device_name} - WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "${device_name} - Uptime"
    icon: mdi:clock-outline
    update_interval: 60s
  - platform: uptime
    name: "${device_name} - Uptime Seconds"
    id: uptime_sensor
    update_interval: 60s
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
  - platform: adc
    pin: A0
    name: "${device_name} - adc"
    update_interval: 30s
    accuracy_decimals: 2
    id: current_raw
    internal: true
  - platform: template
    name: "${device_name} - Power"
    unit_of_measurement: W
    accuracy_decimals: 1
    device_class: power
    update_interval: 30s
    id: my_power
    lambda: return id(current_raw).state;
      - calibrate_linear:
        - 0.4000 -> 0.0  # you need to adjust these values
        - 0.4043 -> 0.14
        - 0.4053 -> 0.20
      - multiply: 24 # 24V strips
  - platform: total_daily_energy
    name: "${device_name} - Total Daily Energy"
    power_id: my_power
          # Multiplication factor from W to kW is 0.001
          - multiply: 0.001
    unit_of_measurement: kW

# Enable time component to reset energy at midnight
  - platform: sntp
    id: my_time

  - platform: template
    name: "${device_name} - Uptime"
    id: uptime_human
    icon: mdi:clock-start
    update_interval: 60s
  - platform: version
    name: "${device_name} - ESPHome Version"
  - platform: wifi_info
      name: "${device_name} - IP"

  - platform: restart
    name: "${device_name} - Restart"

Unfortunately, the energy tracking is pretty hard to get right and I had to add some more filters, calibration, … to get it at least somewhat reliable

I just followed the same steps, however I’ve not been able to flash ESPhome after Tasmota.
It says the device has not enough space to do it OTA.

Any tip?

Did you try Tasmota-minimal?

Fixed it flashing old fashion way: wiring

I was in the same position as OP: Shelly rgbw2 + CW/WW LED strip only controllable as two separate lights.

The existing templates I found were either a bit buggy or didn’t allow to set the LED strip to full power (CW 100% + WW 100%), so I created a new template that solves the original problem in addition to unlocking the option to set the strip up to full power.

There is no need to reflash the controller or install any additional component. Here is my blog post with a detailed explanation, link to the template code and instructions.


Thanks for the github/blog post @gfra. I´m new to this type of configuration so I´m a bit confused where to put the yaml file you have created.

I have put it in the config folder and replaced the UPPERCASE entries - but the new light entity is not appearing anywhere after restarting HA. Should the «template_light_cwww.yaml» file be referenced in the configuration.yaml somehow?

Thanks :smiley:

Yes, you have two options:

  • Copy and paste all the content of the yaml file in your configuration.yaml, see the template light docs for an example of this
  • Add a reference to the template light yaml in your configuration.yaml, I created a template_lights/ directory where I put all my template light yaml files, below the code


  - platform:     template
    lights:       !include_dir_merge_named   template_lights/

Let me know if you get it work! :slight_smile:

@gfra. Hell yes. Thanks for writing up that template. I just installed a bunch of Carro ceiling fans w/ lights. The lights are setup as 2 separate entities in the Tuya integration tied to Home Assistant. I was able to use your template to mesh the warm and cold channels to create a single entity that can be controlled from Home Assistant. WAY better than messing with each channel by themselves.


I got the same fans and I’m struggling with the same issue, can you show me the template that worked for you?

Finally got the time to test this properly. Works perfectly when operating the light card manually - but when creating scenes only the color temperature seems to be saved.

I.e scene «Daytime» will have 100% brightness and 4000K. «Nightlight» scene is saved with 20% brightness and 2700K. When activating the scenes only the color temperature changes. The brightness remains on whatever setting it had before activating the scene.

Any idea what could be causing that?

Thanks for your help:)

Yes, see this reply, and a few of the previous ones. Not an easy fix.