lovelace-paper-buttons-row icon indicating copy to clipboard operation
lovelace-paper-buttons-row copied to clipboard

Doesn't not pull color from light entity

Open watermarkhu opened this issue 3 years ago • 5 comments

Currently on 2021.5, the button doesn't not pull the color for a light entity.

watermarkhu avatar May 17 '21 10:05 watermarkhu

I don't believe it ever did, for simplicity I just use active and inactive colours from the theme, rather than dynamically fetching the colour of a light. That could be a interesting feature to add, for now you could emulate it using Jinja2 templates.

jcwillox avatar May 17 '21 10:05 jcwillox

Ah I see. I falsely presumed that it had this feature similarly to custom-button-card and a few others. It would indeed be a great addition.

watermarkhu avatar May 17 '21 11:05 watermarkhu

for now you could emulate it using Jinja2 templates.

@jcwillox , can you please elaborate how can I use Jinja2 templates to emulate the colors? It would be a great feature to have if the buttons could pull light entity colors. Thanks a lot for all your efforts!

satyambaba avatar Jan 08 '22 22:01 satyambaba

This is something that I plan to implement properly into the codebase hopefully with the next release, but here's a very basic snippet to pull the colour from the light, note that it only handles RGB colours and doesn't handle the light being turned off or brightness.

- type: custom:paper-buttons-row
  buttons:
    - entity: light.monitor_leds
      styles:
        button:
          color: >-
            {{ "#%02x%02x%02x" % state_attr("light.monitor_leds", "rgb_color") }}

jcwillox avatar Jan 09 '22 00:01 jcwillox

This is something that I plan to implement properly into the codebase hopefully with the next release, but here's a very basic snippet to pull the colour from the light, note that it only handles RGB colours and doesn't handle the light being turned off or brightness.

- type: custom:paper-buttons-row
  buttons:
    - entity: light.monitor_leds
      styles:
        button:
          color: >-
            {{ "#%02x%02x%02x" % state_attr("light.monitor_leds", "rgb_color") }}

Thanks a lot for this, @jcwillox . To handle the 'off' state, I slightly modified the code and it is working great. Thanks again!

- type: custom:paper-buttons-row
  buttons:
    - entity: light.monitor_leds
      styles:
        button:
          color: >-
            {% if states(config.entity) == 'on' %} {{"#%02x%02x%02x" % state_attr(config.entity, "rgb_color")}} {% else %} {% endif %}

satyambaba avatar Jan 09 '22 14:01 satyambaba

I finally got around to adding support for this, better late then never, am I right 😂.

Check out release 2.0.0.

jcwillox avatar Dec 13 '22 13:12 jcwillox