bokub / rgb-light-card

💡 A Lovelace custom card for RGB lights
MIT License
412 stars 24 forks source link

Icon auto-coloring doesn't work when using xy_color mode #37

Closed BrainDamage closed 2 years ago

BrainDamage commented 3 years ago

Icon auto-coloring doesn't work when using xy_color mode, it always displays a grey icon no matter the colour or the brightness

type: entities
entities:
    - type: 'custom:rgb-light-card'
      entity: light.example_light
      colors:
          # this works
          - rgb_color:
                - 255
                - 127
                - 255
          # this too
          - hs_color:
                - 60
                - 30
          # this results in a gray icon, instead of white
          - xy_color:
              - 0.33
              - 0.33
            brightness: 255
          # this too results in a gray icon, instead of purple
          - xy_color:
              - 0.217
              - 0.077
bokub commented 3 years ago

This is normal, because the auto coloring haven't been implemented yet.

If someone wants to work on this, all we need is a function to convert x,y to r,g,b.

FYI, here is the function used in Home Assistant, but it looks really complex...

wspeth commented 3 years ago

I face that problem too and here I read, others suffer also :( in my project it is essential to send the particular xy_color values to the devices because they will always report their state as xy_color and some code inbetween has to check/compare. So calculation results from conversion of rgb to xy will not help.

here they offer xy_color as an option https://www.home-assistant.io/integrations/light#service-lightturn_on

and this is, what I tried

all shown as HEX (#): 7F848E in the card

bokub commented 3 years ago

Hi Walter, the 2 following syntaxes should work:

- xy_color: [0.5621, 0.4166]
- xy_color:
  - 0.5621
  - 0.4166  

The issue is that the icons will be grey by default, but the icons are supposed to work if you click on them.

You can set the icon color by using the icon_color option.

wspeth commented 3 years ago

thank you so much. This way it works. Set xy_color for the light and icon_color for the ball:

      - xy_color:
          - 0.7006
          - 0.2993
        icon_color: rgb(255, 0, 24)
        brightness: 100
alexmerm commented 2 years ago

Hey, So I was just taking a look at this because I have my HA set up with light_profiles and I was trying to set up this card. I came across this js-CIE-1931-rgb-color-converter repo which converts from x,y, brightness values to RGB in JS. It might be a bit too much code to include in this card for a minimal result but so far( in my tests at least) its given accurate colors :)

bokub commented 2 years ago

This feature is now available is version 1.10.0 🎉