I’m just starting and custom yaml is hard for me. I’d like a simple badge that shows me if there is a weather alert or not, which I was able to do. What I wasn’t able to do was making the color of the icon and state dependent on said state.
On the left is what I have, on the right what I want:
I haven’t installed card_mod: because I’m such a noob I’m afraid I’m gonna break stuff or a breaking change will be made in a future release of HA and I won’t know how to fix it. Can it be done without card_mod? (If it can’t, I’m still interested in a solution, but I wanted to try without it first)
I installed the mushroom cards, so I have the Custom: Mushroom Template if that’s better.
ChatGTP doesn’t know what the heck it’s talking about. That code is total nonsense. Always check the docs. If it’s not in the documentation it’s not a thing.
You need card mod. Once you have it installed it’s not much more difficult to use than what you tried to do there.
You just need to figure out what element you want to style (–paper-item-icon-color is often what you want for icon color, but not always) and if you want to get fancy you can create some custom css variables in your theme. (–entity-warning-color in my example)
Here’s an example of some code that colors an icon with card_mod from my configuration.
An auto-entities card at that now that I’m looking at it…lol. I grabbed the first example I came across in my config because I was just trying to demonstrate that card_mod is not that hard to use (for colouring icons anyway - I still struggle with the whole shadow dom thing for other stuff). Thanks for pointing him in the right direction to do what he actually asked for…
Badges do change color as appropriate, although you won’t be able to select the color, and it’s just the icon color, not the font too as in your example. The color and icon and dependent on the entity’s device class. For example, a device class of “problem” will show an exclamation mark in a red circle (on / problem) or a tick in a grey circle (off / no problem). Whereas if you have no device class it will show a tick in a yellow circle (on) or a hollow grey circle (off).
If your current entity doesn’t have the device class you want, an easy solution would be to create a template helper, and use that in your badge.
If you look at the documentation for badges, the properties are mostly strings, so they do not support templating.