I’ve added two Ikea VINDRIKTNING air quality sensors to my HA using Esphome, and although I can see them on a gauge with the raw values, I would like the sensor to report as a word rather than the number readings to make it more user friendly and understandable, a bit like the LEDs on the front of the sensor itself- is this possible?
However the sensor is just returning ‘unknown’ - I initially thought it was due to the unit of measurement being in µg/m³ rather than a %, I changed sensor.bedroomairquality to a % but still no luck!
Had a quick look in template editor and can make it report good, medium and bad and error - provided the value is below 500.
Can you post a screenshot of the (source) sensor in the states page in developer tools?
Example in Developer Tools:
{% set airqual = 32 %}
{% if airqual < 0 %}
Error
{% elif airqual < 31 %}
Good
{% elif airqual < 101 %}
Medium
{% elif airqual < 500 %}
Bad
{% endif %}
Produces the result ‘Medium’
If i change airqual to ‘no’ it correctly produces ‘Error’
Thanks! I never thought to test it on template editor - in doing so I found a wrongly placed is_ on the first line that I added when trying something earlier, removing it has fixed this, thanks both!
Note in my example - you could just change the set line to: {% set airqual = states('sensor.bedroomairquality')|float(-1) %}
and then in the rest of the template you don’t have to keep using states and converting to float for each comparison.