Icon color depending on brightness

if I dim up my lights in the UI, the icon color changes according to the brigness.

But now I wonted to use this in a template card. Yes, I can do it manually, but this means i have to configure a lot of values. Is there a way to use the default mechanism from HA here without defining 255 values for each step?

Brightness and color are two different attributes.

Is your bulb RGB of only white? If so remove the icon_color code. You can base the opacity off the brightness with the following code.

type: custom:mushroom-template-card
entity: light.pc_spot
primary: test
  action: more-info
icon_color: |
  {{"#%02x%02x%02x" % state_attr(config.entity, "rgb_color") }}
icon: mdi:lightbulb
    mushroom-shape-icon$: |
      .shape {
        --shape-color: none !important;
    .: >
      ha-state-icon { opacity: {{ ((state_attr(config.entity, "brightness")|
      float(0)/ 255 *100)
        //5)*5 }}%


I checked this out and it is really working!
But it is unfortunately not practical because the brightness is in the lower %. area is too weak
Here at 10%