StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
621 stars 111 forks source link

[FR] Please add CW/WW support for RGBW2 #448

Open apeeters opened 4 years ago

apeeters commented 4 years ago

Is your feature request related to a problem? Please describe.

I have LED strips which contain both CW and WW leds. It would be nice if these were supported in ShellyForHASS, as discussed a while ago on Facebook.

These strips are also called CCT strips.

Describe the solution you'd like

An implementation of CW/WW support for the RGBW2 device, similar to what is available in Homey with this change: https://github.com/jghaanstra/cloud.shelly/pull/11/commits/fc8f82796214e2a30e9b724efbe4f814a75e2480.

Describe alternatives you've considered

Combining both led colors in a template light, but is is complex and is not user-friendly.

Additional context

filmgarage commented 4 years ago

If this is possible, it would help me a lot too!

hakana commented 3 years ago

can you please let me know how this should look like in HA and what and how is the connection to the Shelly RGBW2 look like?

apeeters commented 3 years ago

The setup contains two CW/WW led (strips) connected to a single Shelly RGBW2. These should show up in HA as two lights with color_temp/kelvin support.

Wiring: Shelly Strip 1 Strip 2
R CW
G WW
B CW
W WW
hakana commented 3 years ago

How will the conversation from color_temp to percent for WW and CW look like? I guess that depends on what led strips connected?

filmgarage commented 3 years ago

ESPhome has a similar feature: https://esphome.io/components/light/cwww.html?highlight=cwww

In the config it is possible to choose for constant brightness (cw+ww equals 100% brightness) mix 50/50 = 100% brightness

Or to disable constant brightness mix of cold + warm 100/100 = 200% brightness The brightness is dynamic in this setup.

I would love to be able to choose between these two options.

CWWW

hk-ret commented 3 years ago

I'm using the same configuration with RGBW2's. I have written my own LightRGB class that combines two channels for a light with color temperature. I would also welcome a 'native' support of this feature. My class uses the following conversion between brightness/color temperature and warm/cold values. The conversion supports two methods, were 'A' is basically the "dynamic brightness" curve from @filmgarage, and the other method is the "constant brightness" flavor.

def _bright_temp_from_cold_warm(self, cold, warm):
    """Calculate CT and brightness from cold and warm white."""
    if (cold + warm) == 0:
        return 0, self._temp
    if self._calc_method == "A":
        r = cold / (cold + warm)
        color_temp = round(
            min(MAX_KELVIN, (r * max(0, MAX_KELVIN - MIN_KELVIN)) + MIN_KELVIN)
        )
        brightness = warm if r < 0.5 else cold
    else:
        brightness = max(1, min(100, cold + warm))
        color_temp = round(
            min(
                MAX_KELVIN,
                (cold * max(0, MAX_KELVIN - MIN_KELVIN) / brightness) + MIN_KELVIN,
            )
        )
    return brightness, color_temp

def _cold_warm_from_bright_temp(self, brightness, color_temp):
    """Calculate cold and warm white from CT and brightness."""
    if brightness <= 0:
        return 0.0, 0.0
    if self._calc_method == "A":
        r = (color_temp - MIN_KELVIN) / (MAX_KELVIN - MIN_KELVIN)
        if r < 0.5:
            cold = round(r / (1 - r) * brightness)
            warm = brightness
        else:
            warm = round((1 - r) / r * brightness)
            cold = brightness
    else:
        cold = round(
            (color_temp - MIN_KELVIN) / (MAX_KELVIN - MIN_KELVIN) * brightness
        )
        warm = brightness - cold
    return max(1, min(100, cold)), max(1, min(100, warm))
apeeters commented 3 years ago

For reference, the Esphome calculation can be found here: https://github.com/esphome/esphome/blob/dev/esphome/components/light/light_color_values.h#L218

apeeters commented 3 years ago

Gamma correct seems to default to 2.8: https://esphome.io/components/light/index.html#config-light

ChrMaass commented 3 years ago

This feature would be great 😊

duckqu commented 3 years ago

Because of this I switched to a ESPHome (cwww platform)

Loic691 commented 3 months ago

Some news of this thread ? Ha manage correctly CW/WW led strip Thx