Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actual light colors? #28

Open
Kmanggaard opened this issue Jul 3, 2022 · 13 comments
Open

Actual light colors? #28

Kmanggaard opened this issue Jul 3, 2022 · 13 comments
Assignees
Labels
enhancement New feature or request priority medium This should be looked at after all higher issues and before lower

Comments

@Kmanggaard
Copy link

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
Copy link
Owner

AnthonMS commented Jul 3, 2022

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

@Kmanggaard
Copy link
Author

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
Copy link
Owner

AnthonMS commented Jul 4, 2022

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
Copy link
Owner

AnthonMS commented Jul 4, 2022

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.

@AnthonMS AnthonMS self-assigned this Jul 4, 2022
@AnthonMS AnthonMS added enhancement New feature or request priority medium This should be looked at after all higher issues and before lower labels Jul 4, 2022
@Kmanggaard
Copy link
Author

@AnthonMS
Copy link
Owner

AnthonMS commented Jul 4, 2022

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

It doesn't resolve to anything?

@Kmanggaard
Copy link
Author

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
Copy link
Owner

AnthonMS commented Jul 5, 2022

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
Copy link
Author

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
Copy link
Owner

AnthonMS commented Jul 5, 2022

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
Copy link

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
Copy link

Mika255 commented Feb 19, 2023

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
Copy link

GD-Dal commented Apr 7, 2024

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:
- background: |
[[[
if (entity?.attributes?.rgb_color) return rgb(${entity.attributes.rgb_color})
else return 'var(--primary-color)';
]]]

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 |  ... 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority medium This should be looked at after all higher issues and before lower
Projects
None yet
Development

No branches or pull requests

5 participants