How to use attributes to change colour of an icon?

Hi,

I am trying to change the colour of a fan icon based upon the “fan_mode” attribute of the entity. I have tried the below method to change the colour based upon the entity and that works.

I looked at Button-card icon colour and I find that it is not applicable to me because in my case, the entity of the card is not the same as the entity who’s attribute I want to check.

Using it in custom button card

            [[[
              if (states['climate.izone_controller'].state != 'off')
                return "green";
              else
                return "gray";
            ]]]

Need some guidance on how to change colour based upon attribute.

Regards,
AK

No response!

I did a work-around by creating a sensor out of the attribute and then checking the state of the attribute to change the colour.