AnthonMS / my-cards

Bundle of my custom Lovelace cards for Home Assistant. Includes: my-slider, my-slider-v2, my-button
Other
104 stars 27 forks source link

Actual light colors? #28

Open Kmanggaard opened 2 years ago

Kmanggaard commented 2 years ago

I'm using rgb-light-card to choose light temperature. The card does a good job of using light temperature values to color the buttons. button-card does something similar, but is suffering under some HA issue as far as I can tell.

Again, amazing work! Hope we get to see some great features before life comes knocking :-)

AnthonMS commented 2 years ago

Isn't this a duplicate of this issue: #20 ? Or am I misunderstanding your request?

Kmanggaard commented 2 years ago

Sorry for being unclear. I'm not talking about a color slider, although that would be nice. What I wold like is to use the color_temp/rgb/xy/hs state of the light entity translated into a color code, which would then be accessible (as a variable I guess) to use anywhere in the card.

Here's the design I'm working on:

Screenshot 2022-07-04 at 13 35 11

The colors of the buttons on the right are achieved simply by putting the desired color state of the light entity into rgb-light-card, so there's some translating going on. I was thinking it must be possible to get the state from the entity dynamically.

The bottom button-card is using var(--button-card-light-color) for the icon color, but considering that the selected light color is the blue one on the bottom right, it's not working very well.

AnthonMS commented 2 years ago

The slider can already handle color_temp?

The old slider has the 'warmth' key which in turn will change the color_temp of the light. The new slider will have the 'colorMode' key and for a start accept the values: brightness, temperature, hue, saturation, red, green, blue, white and toggle. But as of now it only supports brightness, temperature, hue and saturation.

temperature is handling color_temp attribute on a light.

I have thought about it a little, and I am not mathematician or lights expert. So I do not know how I would start implementing a dynamic slider with one value, to handle both hue AND saturation at the same time. Then the slider value range would have to be insanely huge to be able to handle just hs_color. It would have to handle hue 0-360 and saturation 0-100. So the slider range should be 36.000? So it can handle all combinations?

I have also thought about the rgb, rgbw, rgbww and xy_color color modes. And it is the exact same dilemma with all of them. So as a start I am implemented them all, but separately. And then I might be able to figure something out down the line. But that is pretty low priority unless someone comes around with the perfect formular for calculating hue/sat from a single slider value.

AnthonMS commented 2 years ago

I'm thinking as a start I might be able to make a template slider where you set what happens on specific percentages on the slider. Then you could use a linear gradient to set the slider color to match the actions specified.

This is actually something I think some people could find useful. I could think of a few scenarios where I could use something like that. So I will probably implement something like that to the new slider as well.

Kmanggaard commented 2 years ago

Have you looked at this? https://github.com/NAStools/homeassistant/blob/master/homeassistant/util/color.py#L9

AnthonMS commented 2 years ago

Have you looked at this? https://github.com/NAStools/homeassistant/blob/master/homeassistant/util/color.py#L9

It doesn't resolve to anything?

Kmanggaard commented 2 years ago

Have you looked at this? https://github.com/NAStools/homeassistant/blob/master/homeassistant/util/color.py#L9

It doesn't resolve to anything?

Sorry about that, seems there are some issues with internal linking on github. I just copied from the address bar.

This is the correct link, but I can only open by right click > go to... Or copy/pasting the address.

https://github.com/NAStools/homeassistant/tree/master/homeassistant/util/color.py

Interesting part begins at line 170.

AnthonMS commented 2 years ago

Yes there are some interesting snippets that I will definitely look at more in depth when time comes to implement RGB colors and XY colors since there are some nice functions to convert from one to the other. This might also help me create temperature sliders for RGB lights not supporting setting temperature natively. But not something I will look at, at the moment.

Is it me who is blind, but I do not see how that relates to creating RGB/XY/HS colors from a single value? Don't get me wrong, I appreciate the link and I think it will help me down the line when time comes. But these snippets will only help me when the first part is done, and that is creating the colors from a slider value.

Kmanggaard commented 2 years ago

I think there's som miscommunication here.

To be clear: My initial request was not about controlling the state of the light, but using the state to calculate colors to be used in the graphical interface.

Glad to hear the link was of some use, though.

AnthonMS commented 2 years ago

Ahh I see, yeah I have misunderstood what it was you were asking. I apologize. Your request should technically already be possible in the new slider, since you an use templating to determine the colors or anything else now.

But I agree, it could also be a nice build in feature and something I will take into consideration when I have fixed some of the other stuff.

usernein commented 2 years ago

you can use templating to determine the colors or anything else now.

For anyone interested, i got it working in this way:

  progress:
    - background: |
        [[[
          return `rgb(${entity.attributes.rgb_color})`
        ]]]
Mika255 commented 1 year ago

Thanks! Here the solution to handle both rgb and non-rgb lights for me

 - background: |
                          [[[
                            if (entity?.attributes?.rgb_color) return `rgb(${entity.attributes.rgb_color})`
                            else return 'var(--primary-color)';
                          ]]]
GD-Dal commented 7 months ago

Thanks! Here the solution to handle both rgb and non-rgb lights for me ```

* background: |
  [[[
  if (entity?.attributes?.rgb_color) return `rgb(${entity.attributes.rgb_color})`
  else return 'var(--primary-color)';
  ]]]

Late to the party, but this does not work for me (with a philips hue bulb). This is under progress?

progress:

gives me: Configuration errors detected:

missed comma between flow collection entries (21:55)

 18 |  ... 
 19 |  ... 
 20 |  ... 
 21 |  ... utes?.rgb_color) return `rgb(${entity.attributes.rgb_color})`
-----------------------------------------^
 22 |  ... -primary-color)';
 23 |  ...