rianadon/timer-bar-card

icon_color from active light color or template

Closed this issue · 4 comments

Is it possible or how can i change the icon_color automatically into the color from the light entity or with a template?
I had to change this with card_mod, but i dont get it.

image
INTO
image
image

type: custom:timer-bar-card
entity: light.kuchenlampe
icon: mdi:lightbulb
invert: true
layout: hide_name
duration:
entity: input_number.timer_kuchen_beleuchtung
units: seconds
sync_issues: fix
bar_radius: 4px
bar_width: 60%
mushroom:
layout: horizontal
secondary_info: last-changed
icon_color: red
tap_action:
action: toggle
hold_action:
action: more-info

Hey, I think you should be able to do this with only a template card that can query the color of the light from Home Assistant. You can figure out the light color with a template such as "{{ state_attr('light.mylight', 'rgb_color') }}". That will give you the color components separated by commas like 255, 136, 13.

You can then use this value and plug it directly into the color: option under mushroom:.

@rianadon thanks for the suggestion. i had installed the config-template-card but when i query the rgb_color into a variable, how can i use this in the mushroom: color:. Either the card does not accept the color or the card becomes invisible because it cannot be loaded.

Here the card now:

type: custom:config-template-card
variables:
  RGB: '{{ state_attr('light.kuchenlampe', 'rgb_color') | join(', ') }}'
entities:
  - light.kuchenlampe
  - input_number.timer_kuchen_beleuchtung
card:
  type: custom:timer-bar-card
  entity: light.kuchenlampe
  icon: mdi:lightbulb
  invert: true
  layout: hide_name
  duration:
    entity: input_number.timer_kuchen_beleuchtung
    units: seconds
  sync_issues: fix
  bar_radius: 4px
  bar_width: 60%
  mushroom:
    color: ${RGB}
    layout: horizontal
    secondary_info: last-changed
  tap_action:
    action: toggle
  hold_action:
    action: more-info

Thanks for writing this up! Made it very easy to test on my end.

It's not working because the config-template-card has its own syntax for templates, because rather than sending the template to the Home Assistant server to render it's rendering in-browser. That makes it the card faster and is why I recommend it, but the templating language is different.

card

Here's how I got this to work:

type: custom:config-template-card
variables:
  RGB: states['light.tarp_light'].attributes.rgb_color.join(',')
entities:
  - light.tarp_light
card:
  type: custom:timer-bar-card
  entity: light.tarp_light
  icon: mdi:lightbulb
  invert: true
  layout: hide_name
  duration:
    fixed: 60
    units: seconds
  sync_issues: fix
  bar_radius: 4px
  bar_width: 60%
  mushroom:
    color: ${RGB}
    layout: horizontal
    secondary_info: last-changed
  tap_action:
    action: toggle
  hold_action:
    action: more-info

it works. Thanks !!!