Value-driven colour on Dashboard does not work

Hi all
I’m new to this community and new to HomeAssistant.
I’ve already managed to integrate some devices via ModBus.
Now I’m trying to “tune” a Dashboard visualization.
If a value of an entity is 0, the card should be “green”.

type: tile
entity: sensor.status_heizkessel
icon: mdi:dots-grid
card_mod:
  style: |
    :host {
    color:
    {% if sensor.status_heizkessel | int == 0} 
    greenyellow
    {% elif sensor.status_heizkessel | int > 0}
    red
    {% endif %}
    ;
    }

But, no matter how much I research or try, I can’t get this code working :frowning:
I tried various ways and snippets I’ve found on the web (e.g. states(config.entity)), etc.
Anyone here who can direct me towards a solution?

Thanks so much.

best

Uwe

Hi, if you want to change the background color you need to use ha-card and background


card_mod:
  style: |
      ha-card {
              
              background: red;

              }


card_mod:
  style: |
    ha-card {

    background:

      {% if  states['sensor.status_heizkessel_battery'].state | int == 0 %} 
      greenyellow
      {% elif states['sensor.status_heizkessel_battery'].state | int > 0} %}
    red
    {% endif %}

    }
        
        

No need for the elif. If there is a third option, elif is needed.

type: tile
entity: sensor.status_heizkessel
icon: mdi:dots-grid
card_mod:
  style: |
    ha-card {
      background:
       {% if states('sensor.status_heizkessel') | int(0) == 0 %} 
        greenyellow
       {% else %}
        red
       {% endif %}
        }
1 Like

Thank you so much - will try that now.
Say - can you let me know the best way to dig into YAML in general and the HomeAssistant concepts in special? The documentation seems to be rather functional, while I would prefer to dig into the topic more object-related (a complete processing of a certain exemplary device into HA).

Hm - interesting (sorry my basic questions - my last time with coding was somwhen around .NET 2.0…).
But even as I reduce the whole script to what D13g0m0nt3s suggested, nothing changes on the surface of my dashboard…

card_mod:
  style: |
      ha-card {
              
              background: red;

              }

image

Just to make sure, you do have card_mod installed?

1 Like

That was the right question… indeed.
While searching for solutions for my problem, I found many code snippets, but not a single hint that this is an add-on…
Guess that solved it… will try the next weekend

Thank you!