Since two days I’m trying to find out, how I can change the color of an icon based on its state, but all information that I did find didn’t help me to write the right code.
I want to have a list of entities like this (doors and windows with contact sensors), but the icons shall be red when open and green when closed:
But I see that you were working with the state-binary_sensor as well. Did it work? I‘m not familiar with defining these variables (?); do you think, mine (state-binary_sensor-contact-open-color) is correct?
hehe, you get the answer to your search by Ildar in the post above, and now you make your own post as solution… it is customary in this Community to credit the post that brought you to your answer and mark that as solution.
besides that, you dont need card_mod at all, if you use the correct device_class, are they set on you binary_sensors contact entities?
The link I provided contains a description of using theme variables as well - and it was described which particular method should be used in a particular case (change by card-mod for a card / separate element, change in a theme).
This post contains general styles for Entities card. Actually, I meant a different post about using css variables (which in some cases may be used without card-mod as it was already noted by Marius).