I’m trying to create a custom button card. I use the grid configuration. I got almost where I wanted to be (will turn this into a template card once i’m done) but one thing doesn’t seems to work.
I have Custom fields in my card, (a button card but actualy I use it just for the icon left botton
I managed to change the color of the icon (bottom left, the toggle switch icon)
But I can’t use a {% if is_state on the card-mod-icon-color. to change the color according to the ste of the light.living entity.
Am I doing something wrong? what {% if is_state info should work here on this level?
full code of the button card (to be cleaned up)
name of the custom field ( bottom left) is “slider”
To change the color of the icon in a custom button card based on the state of an entity, you can use the {% if is_state() %} template tag in the icon section of the card definition. The is_state() function takes two arguments: the entity ID and the desired state.
For example, to change the color of the icon to green when the light.living entity is on, and to red when it is off, you could use the following code:
This code will change the color of the icon to green when the light.living entity is on, and to red when it is off. You can adjust the colors and entity ID as needed for your specific use case.
It’s also worth noting that the {% if is_state() %} template tag only works at the top level of the card definition. It cannot be used inside the custom_fields section of the card, as you are trying to do in your code. To change the color of the icon based on the state of an entity, you will need to use the {% if is_state() %} template tag inside the icon section of the card.
oh, so it’s not possible then?
Because I don’t want to change the icon of the custom button card (the one on the top left) but the custom_fields icon on the bottom left. so this is not possible then?
any other way to add (some) extra icons inside a custom button card that can change with the {% if is_state} ?
So I figured it out. Instead of embedding another card as Custom fields, I just added a field called “second” like in the example of sensor.raspi_temp in GitHub - custom-cards/button-card: ❇️ Lovelace button-card for home assistant and instead of adding info in the “style” part, I added this to the custom fields part: