Dynamic icon color for mqtt sensor

Hi,
Sorry to bother, but I skimmed the forum without finding a complete solution to my problem.
I have defined an mqtt sensor which has 0, 1, 2 and 4 as possible values. The sensor is defined in configuration.yaml

I created a button card to display the value and to change it (through mqtt publish). The icon I use is mdi:traffic-light. Publishing script works fine. But I can’t figure out how to have the icon color changed according to the status. I tried multiple solutions, but can’t get it to work. Also, I would like that the message in the button card (activated with show_state: true) displays a derived value rather than the numeric one.

Could anyone help me with that? Provide a working solution (or pointer to) including where to integrate it (in a config file? elsewhere?)

Thanks a lot

Jean-Noël

You probably need the custom-button-card for that and then use the label attribute for the derived value you want to show.

Thanks a lot. It took me a while to install the component, since I did not want to install HACS, and the install instructions only refered to ui-locelave.yaml. But in the end, I could add and use the resource, which was my main issue. Thanks again