basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.77k stars 131 forks source link

RGBWW support #289

Open vandalon opened 2 years ago

vandalon commented 2 years ago

Hi Bas,

First of all thanks for the great plugin, i've been using it for a while now with my zigbee lights and all is great! But now i've added some RGBWW lights to my setup and those don't seem to work with adaptive lighting. I glanced over the code and I don't see any color_temperature_to_rgbww anywhere so i'm guessing this is just missing :) Since RGBWW light don't support CT I think it would be great if you can add RGBWW color mode support.

Thanks for all the great stuff! Joris

RubenKelevra commented 2 years ago

RGBWW means RGB plus Warm-White, right?

Can you enable Warm-White output and mix it with regular RGB?

vandalon commented 2 years ago

@RubenKelevra No, RGB warm + cold white, so 2 white channels instead of one. I know it's also called RGBCCT but in HA this is called RGBWW (see: https://www.home-assistant.io/integrations/light/)

RubenKelevra commented 2 years ago

@vandalon I got like 20 lamps of this type, they work fine with Adaptive Lighting. Can you elaborate what's not working for you?

vandalon commented 2 years ago

@RubenKelevra Are you sure, are they also running with color_mode: rgbww in home assistant?

RubenKelevra commented 2 years ago

Ah yeah, just realised the same thing. They do run with HS/RGB/XY or color temperature.

So your lights only support RGBWW?

vandalon commented 2 years ago

Well i'm running esphome on the controller, but RGBWW would be the most flexible option. Mostly because you can combine that white channels and RGB channels in a very flexible way. When using RGBWW there is no CT mode. When using RGB instead of CT I only use the RGB channels and the white channels are off, giving me less lumens :)

RubenKelevra commented 2 years ago

@vandalon ah! Gotcha. Yeah using RGB to "emulate" real warm/cool white LEDs is quite bad. I assumed that your lights would convert the CT-mode commands to just the white LEDs and the RGB/HSV commands to the colored LEDs – as that's how my Zigbee LED strips works, which is also RGBWW.

Yeah, will have a look at this on this goal. Should be pretty easy.

I'll close the ticket, as it's now on the roadmap :)

th3w1zard1 commented 1 year ago

I've been looking into this issue, and it seems to be inaccurate on hassio itself? https://github.com/home-assistant/core/issues/54216 Are you able to get accurate RGBWW colors using light.turn_on inside of HASS? Are you certain it's just adaptive-lighting that's inaccurate? @vandalon

th3w1zard1 commented 1 year ago

@vandalon This should already be in adaptive lighting as its already in home assistant. If your light doesn't support the right color output, home assistant will convert to whatever your bulb supports inside its own code. see homeassistant\components\light\light.py

I glanced over the code and I don't see any color_temperature_to_rgbww anywhere

You wouldn't see this in the integration's code as this is all done by Home Assistant itself.

th3w1zard1 commented 1 year ago

I believe I've found a function that will convert ct to rgbcct for more accurate values:

def kelvin_to_rgbcct(kelvin):
    """
    Convert a color temperature in Kelvin to RGBCCT values.

    :param kelvin: The color temperature in Kelvin.
    :type kelvin: int or float
    :return: A tuple of five values representing the RGBCCT values.
    :rtype: tuple
    """
    # Convert the color temperature to mireds
    mireds = 1000000 / kelvin

    # Calculate the CT value (CCT range is typically 153 to 500)
    ct = 449 * mireds ** 3 - 3525 * mireds ** 2 + 6823.3 * mireds + 5520.33

    # Calculate the red, green, and blue values
    if ct <= 153:
        red = 255
        green = (ct * 255) // 153
        blue = 0
    elif ct <= 255:
        red = (255 * (255 - (ct - 153) * 5)) // 255
        green = 255
        blue = 0
    elif ct <= 400:
        red = 0
        green = 255
        blue = ((ct - 255) * 255) // (400 - 255)
    elif ct <= 500:
        red = 0
        green = (255 * (500 - ct)) // (500 - 400)
        blue = 255
    else:
        red = 0
        green = 0
        blue = 255

    # Calculate the CCT value
    cct = 1000000 / mireds

    # Return the RGBCCT values as a tuple
    return red, green, blue, 255, int(cct)
basnijholt commented 1 year ago

Related: https://github.com/basnijholt/adaptive-lighting/issues/118

basnijholt commented 1 year ago

@th3w1zard1, do you remember where you found that (https://github.com/basnijholt/adaptive-lighting/issues/289#issuecomment-1504843965)?

th3w1zard1 commented 11 months ago

I don't, I might have just wrote it using wikipedia to help me with the conversions.

lloeki commented 9 months ago

I just set up GU10 and E27 Shelly RGB bulbs (moved from IKEA Tradfri white-only bulbs which were working perfectly in that regard). I appear to be experiencing #118.

I've been looking into this issue, and it seems to be inaccurate on hassio itself? https://github.com/home-assistant/core/issues/54216

This has been merged and released in https://github.com/home-assistant/core/pull/61473

Are you able to get accurate RGBWW colors using light.turn_on inside of HASS?

I am. Brightness slider works, RGB colour picking works, white temperature slider works, all completely independently. I don't know if this uses light.turn_on behind the scenes.

Are you certain it's just adaptive-lighting that's inaccurate?

Given the above, yes. With adaptive-lighting, colour and brightness were coupled in some way, e.g pure red was super dim, some other colours were much brighter - can't recall which exactly -, white was super bright and of fixed temperature (interestingly enough temperature wasn't entirely consistent across all bulbs), in all cases brightness slider was ineffective.

I had to fully disable the adaptive-lighting integration to be able to debug this (when the component was enabled adaptive-lighting kept on mucking with the lights in various ways, which made debugging inconsistent and annoying), which made lights immediately work properly with HASS. Weirdly enough, adaptive-lighting seemed to have an influence even with all light control toggles off, and also on lights removed from the light control list.

lloeki commented 9 months ago

May I ask, what's the semantic of the hardcoded 255 here?

def kelvin_to_rgbcct(kelvin):
  ...
  # Return the RGBCCT values as a tuple
  return red, green, blue, 255, int(cct)
th3w1zard1 commented 9 months ago

I am not sure, sorry. Been almost a year. I recall something about it not being fully convertible without loss of accuracy, and I remember that loss of data was negligible when it comes to smart bulbs.

lloeki commented 9 months ago

Totally fair, thanks for taking the time to answer!

basnijholt commented 5 months ago

[Copy pasting this message in a few recent open issues]

I just wanted to take a moment to express my heartfelt thanks to everyone that is active in this repo. Your contributions, from answering questions to addressing issues, have been invaluable. It's amazing to see how supportive and helpful our community is!

Adaptive Lighting is all about enhancing your living spaces with smart, sunlight-responsive lighting. We've had quite a few discussions and open issues recently, and I see this as a positive sign of our community's engagement and growth. If you come across anything in the documentation that's unclear or if you have suggestions for improvement, please don't hesitate to share!. Your feedback is crucial for making Adaptive Lighting better for everyone.

On a personal note, I've recently welcomed twin boys into my family, which has been an incredible and life-changing experience. As you can imagine, my time is now more limited, and while I'm doing my best to keep up with the project, there may be delays in my responses. I appreciate your understanding and patience during this time.

Rest assured, I'm fully committed to addressing any bugs, especially those related to new Home Assistant updates, as swiftly as possible. I understand that many issues may stem from hardware limitations or misunderstandings about things like Zigbee groups. Your continued support and collaboration in helping each other out not only strengthen our community but also enhance the Adaptive Lighting experience for all.

Thank you once again for your understanding, patience, and support. Let's keep our houses well lit and adaptive for maximal enjoyment of life! 🌞🏠🌙