Using rgb(x,y,z) color for icon_color

I’m trying to use the rgb_color attribute from a LIFX bulb in a template to set the icon_color, but it’s not working (the icon doesn’t change to the proper color).

If I enter icon_color: blue, the icon changes to blue
If I enter icon_color: rgb(0, 0, 255), the icon stays at the default (white) color

What’s the proper way to use rgb attribute values in a template?

Try #0000FF

Thanks. I would, but the LIFX bulb doesn’t have a hex attribute for color.

Then convert your values to hex

Yes, thank you. Before I go Google-fu’ing my way to figure that out, I’d like to know whether rgb is supposed to work without converting or if there’s just something I’m missing in the syntax.

hex:#::rgb:?

It is the setting of the icon color that sets the standard to use and that is HTMLl and CSS.


              icon_color: >
                {{ '#%02x%02x%02x' % state_attr(entity, 'rgb_color') if
                states(entity) == 'on' else 'disabled' }}

5 Likes

Thanks, I came across this syntax a while back, so I adapted yours to get this:

icon_color: >
  {{ iif(is_state('light.tripod_state','on'), "'#%02x%02x%02x' % state_attr('light.tripod','rgb_color')", 'grey') }}

They both work great. I’m still left with my original question, but after three people chimed in with alternative approaches, I’ll assume the answer is that setting color using rgb values is not natively supported.

@WallyR I didn’t quite pick up on what you were teaching me with respect to using rgb color.

1 Like

Show us your complete template or card.

It’s working using the syntax above (yours and mine).

The original question though was how to directly use the rgb value.

At least not in Mushroom Cards. It’s possible e.g. in (custom) Button Card.

P.S. It was possible a few versions ago.

This is for a Mushroom Template Card, so maybe that’s feedback for that project. Thanks.

I was trying to say that hex was the way to go and give an example of a thread with such conversions, but you already master that. :slight_smile:

because this was not the solution for me and i came across it using a google search i want to show what worked for me

            icon_color: |
              {% if is_state('light.bedroom_kate', 'off') %}
                amber
              {% else %}
                {{ state_attr("light.<your_light>", "rgb_color")[0] }},  
                {{ state_attr("light.<your_light>", "rgb_color")[1] }}, 
                {{ state_attr("light.<your_light>", "rgb_color")[2] }}
              {% endif %}