Get the icon with the current lights color

Hi guys, in this code I want to get the icon with the current state color of the lights

type: custom:mushroom-template-card
primary: ILLUMINAZIONE
secondary: '{{ states(''sensor.lights_luci_della_casa_accese'')}} in funzione'
icon: mdi:lightbulb
icon_color: '{{ state_attr(''light.accendi_spegni_luci'', ''rgb_color'')}}'
layout: vertical
tap_action:
  action: navigate
  navigation_path: luci_casa
hold_action:
  action: toggle
entity: light.accendi_spegni_luci
fill_container: true
double_tap_action:
  action: more-info

I tried to apply this, but nothing:

icon_color: '{{ state_attr(''light.accendi_spegni_luci'', ''rgb_color'')}}'

I wish it worked like this:

20221119_005826_AdobeExpress

some idea?

Try double quote " instead of two single quotes ''

after hours I managed to find the solution, here it is:

{{ state_attr("light.accendi_spegni_luci", "rgb_color")[0] }}  {{ state_attr("light.accendi_spegni_luci", "rgb_color")[1] }}  {{ state_attr("light.accendi_spegni_luci", "rgb_color")[2] }}

You still had your quotes wrong, just sayin’

1 Like
type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    primary: Master Bedroom
    secondary: |-
      {{ states('sensor.master_bedroom_button_temperature') }} °c 🌡
      {{ states('sensor.master_bedroom_temp_sensor_humidity') }} % 💧
    icon: mdi:bed-king
    tap_action:
      action: navigate
      navigation_path: /dashboard-mobile/master-bedroom
    hold_action:
      action: toggle
    icon_color: >-
      {% if is_state('light.master_bedroom_lights', 'on') %}

      {{ state_attr("light.master_bedroom_lights", "rgb_color")[0] }} {{
      state_attr("light.master_bedroom_lights", "rgb_color")[1] }} {{
      state_attr("light.master_bedroom_lights", "rgb_color")[2] }}

      {% endif %} 
    multiline_secondary: false
    fill_container: true
    double_tap_action:
      action: more-info
    badge_icon: |-
      {% if is_state('binary_sensor.master_bedroom_motion_motion', 'on') %}
      mdi:motion-sensor
      {% elif is_state('binary_sensor.master_bedroom_window_contact', 'on') %}
      mdi:window-open
      {% endif %} 
    badge_color: |-
      {% if is_state('binary_sensor.master_bedroom_motion_motion', 'on') %}
      green
      {% elif is_state('binary_sensor.master_bedroom_window_contact', 'on') %}
      yellow
      {% endif %} 
    entity: light.master_bedroom_lights
  - type: custom:mushroom-template-card
    primary: Master Bathroom
    secondary: '{{ states(''sensor.master_bathroom_motion_sensor_temperature'') }} °c 🌡'
    icon: mdi:shower
    entity: light.master_bathroom_lights
    tap_action:
      action: navigate
      navigation_path: /dashboard-mobile/master-bedroom
    hold_action:
      action: toggle
    icon_color: |-
      {% if is_state('light.master_bathroom_lights', 'on') %}
      orange
      {% endif %} 
    multiline_secondary: false
    fill_container: true
    double_tap_action:
      action: more-info
    badge_icon: >-
      {% if is_state('binary_sensor.master_bathroom_motion_sensor_motion', 'on')
      %}

      mdi:motion-sensor

      {% elif is_state('binary_sensor.master_bathroom_window_contact', 'on') %}

      mdi:window-open

      {% endif %} 
    badge_color: >-
      {% if is_state('binary_sensor.master_bathroom_motion_sensor_motion', 'on')
      %}

      green

      {% elif is_state('binary_sensor.master_bathroom_window_contact', 'on') %}

      yellow

      {% endif %} 

1 Like