card_mod:
style:
ha-tile-image$: |
.image {
{% set zones = states.zone|map(attribute='name')|list %}
filter: {{'grayscale(100%)' if not is_state(config.entity,'home') and
states(config.entity) not in zones else 'none'}};
}
Sorry, I always come back to bother you who are so kind. With the same principle I tried to set a color for the C02, but without success:
icon_color: >-
{% set co2 = states('sensor.cucina_co2') %} {% if co2 <= '700' %} green
{% elif co2 <= '1000' %} yellow {% elif co2 <= '1300' %} amber {% elif
co2 <= '1600' %} orange {% elif co2 <= '2000' %} deep-orange {% else %} red {% endif %}
As soon as the c02 value exceeds approximately 750, it turns red. It should become above 2000. I also tried with this code, but the result is the same:
icon_color: >-
{% set co2 = states('sensor.cucina_co2') %} {% if co2 <= '700' %} green {%
elif co2 <= '1000' %} yellow {% elif co2 <= '1300' %} amber {% elif co2 <=
'1600' %} orange {% elif co2 <= '2000' %} deep-orange {% elif co2 > '2000'
%} red {% endif %}
Everything works fine with values up to 999, from 1000 onwards the filter does not work. what could it depend on? Where am I wrong?
{% set co2 = states('sensor.cucina_co2') | float %}
but where? sorry i dont’ understand, i try it, now not work all color:
icon_color: >-
{% set co2 = states(entity) | float%} {% if co2 <= '700' %} green {%
elif co2 <= '1000' %} yellow {% elif co2 <= '1300' %} amber {% elif co2 <=
'1600' %} orange {% elif co2 <= '2000' %} deep-orange {% elif co2 > '2000'
%} red {% endif %}
I have done other tests by changing the reference values and everything always works until the test refers to a number compared with 100o or a larger value, in which case it will become red without returning the correct value
When you wrap something in quotes it is a string like this: '100' you can compare '200' to '100'but it wont have the outcome you expect all of the time. Your temp probably works only by coincidence.
You have correctly converted your sensor value to a float (or a number) here:
icon_color: |-
{% set co2 = states(entity) | float %}
{% if co2 <= '700' %}
green
{% elif co2 <= '1000' %}
yellow
{% elif co2 <= '1300' %}
amber
{% elif co2 <= '1600' %}
orange
{% elif co2 <= '2000' %}
deep-orange
{% elif co2 > '2000' %}
red
{% endif %}
So co2 is now a number which is great. But you are comparing it to a string. Because of the quotes. So you are doing this now: if 999 <= '1000' which doesnt make sense. It makes as much sense as asking if 999 <= Cake
Do you see what i mean? So you need to remove the quotes and convert your sensor output to a number like this:
icon_color: |-
{% set co2 = states(entity) | float %}
{% if co2 <= 700 %}
green
{% elif co2 <= 1000 %}
yellow
{% elif co2 <= 1300 %}
amber
{% elif co2 <= 1600 %}
orange
{% elif co2 <= 2000 %}
deep-orange
{% elif co2 > 2000 %}
red
{% endif %}
You were very helpful and very clear, I corrected all the code also for temperatures and humidity, before having other errors. Thanks so much for your help
Color of the chip or color of the icon? If you mean the chip itself have a look at the guide in my profile. If you mean the icon just use a template chip and make a template with your states like this for example: