How to assign a enum state a numeric value?

Looking to assign a numeric value to a enum state

STATES > Numeric Value
none > 1
very_low > 2
low > 3
medium > 4
high > 5
very_high > 6

Any help or hints???

template sensor?

The conversion from an integer value to a string value can be done easily with a Jinja2 template. So, as suggested by finity, create a Template Sensor that converts the value.

Unless of course, what you had in mind can’t use a Template Sensor. Where were you intending to use this integer-to-string conversion? What’s the source of the integer value?

Know nothing about Jinja2 template! Docs on templating are sparse, saw nothing for my case!

The source is for tree, grass, weed pollen. The states are “enum” listed as text under states in developer tools. I need to assign a numeric value so the circle gauge in the dashboard change color based on a numeric scale.

I need to change from text to numeric so I thought mapping would be a better solution.
the exact sensor:

options: high, low, medium, none, very_high, very_low

It’s what is employed by a Template Sensor. Home Assistant employs it to allow the user to compute a result (among other things).

For example, you could create three Template Sensors, one for each pollen index, that converts a string value (like “high”) to an integer value (like 5). Display each Template Sensor’s value using a Gauge card.

Actually learned how to use Jinja2 watching this video: Create your OWN Template Sensor with Home Assistant Coding Tutorial - YouTube

So I have my 3 sensors return the data as needed. Now have a conflict in yaml between Sunrise/SunSet code and my sensor for each of my new sensors. :angry:

It’s not the community’s custom to mark one’s own post with the Solution tag if it simply applies/duplicates ideas/solutions suggested to you.

If everyone did that in their topics, it would appear that all users ultimately answer/solve their own question/problem.

What you posted, I had found before, felt like I was caught in a temporary causality loop. So went looking for a possible Youtube video on templating in HA which I found in insightful and helped solved my issue.

The solution was in the video which is in that post. Only way to show it as I know of

Apparently the so-called solution produced the configuration mess you reported in another post:

Do you want my help or will you ultimately solve that one yourself as well?