How to get the "descriptive" sensor state in jinja template?

I don’t understand where does the word “Ozone” come from when I use the sensor.u_s_main_pollutant entity from the AirVisual integration, in basically any Lovelace card?

image

When I try to get the state using template, I get “o3” instead of “Ozone”.

So, how do I make for example a custom notification using template where I get the descriptive name of the sensor state, as in Ozone instead of o3?
Where do Lovelace cards get this value from?

The integration, whichever one it is (you did not tell us), probably has an enum device class that interprets the state. See: Sensor - Home Assistant

You would have to define your own enum device class for your template sensor. See: "options" for sensor device_class: enum - #3 by karwosts

Wouldn’t state_translated() work in this case?

1 Like

I guess that depends if the enum options are local to the integration?

Not really sure how it works. Work a try in the template editor though.

I get:

But that may be because I don’t have the integration.

state_translated() needs more than just the string. There has to be some logic in the integration.

Yah, that’s what I thought:

I did, the integration is AirVisual Cloud

You learn something every day :slight_smile:
I didn’t know about state_translated(). It works!