Been searching through multiple posts and have tried a lot of different variations to no avail. I am trying to change an icon color based on the numeric value of the entity state. Here is what I have but the color does not change beyond the initial value. I understand there is an issue with the argument but I can’t seem to sort it out.
in my testing of this, i’m seeing two issues. one is the logic (which i’d edited above). the second is the display refresh. the ui is sometimes updating the color and sometimes i have to hit refresh on the page to get it updated. but clearly it’s trying t update it… but in editor mode, it’s updating right away…
Lol…Came back to post the solution with a face palm that I had the order of operations reversed…
This is the solution
try this…
entity: sensor.living_room_air_purifier_pm2_5
card_mod:
style: |
ha-card {
{% if states(‘sensor.living_room_air_purifier_pm2_5’) >‘115’ %}
–card-mod-icon-color: #ff4d4d;
{% elif states(‘sensor.living_room_air_purifier_pm2_5’) >‘75’ %}
–card-mod-icon-color: #ffcc00;
{% elif states(‘sensor.living_room_air_purifier_pm2_5’) >‘35’ %}
–card-mod-icon-color: #00e6ac;
{% elif states(‘sensor.living_room_air_purifier_pm2_5’) >‘0’ %}
–card-mod-icon-color: #3399ff;
{% endif %}
}
in my testing of this, i’m seeing two issues. one is the logic (which i’d edited above). the second is the display refresh. the ui is sometimes updating the color and sometimes i have to hit refresh on the page to get it updated. but clearly it’s trying t update it… but in editor mode, it’s updating right away…
It is unclear what card is used. A particular style depends on a card. Besides, these “—card-mod-xxx” variables may not work in some cases. Suggest to ask similar questions in a dedicated main card-mod thread.