Create a new sensor as an integer based on the latest string of another?

I have a sensor (blood glucose trend) that reports as one of 7 text strings which I want to rank/score so that I can then do other stuff with the info. The sensor, updated every 5 mins, can be one of:
rising quickly
rising slightly
falling slightly
falling quickly.

I’d like to somehow update a custom sensor to a numeric value, in the same order such as:


This will allow me to analyse the previous x updates and “do stuff” with it :slight_smile:

What’s the easiest way of accomplishing the initial conversion?

You can create a template sensor

 - platform: template
      friendly_name: 'Blood Glucose Numeric'
      value_template: >
         {% if (states('sensor.your_sensor') != 'rising quickly') %}
          {{ 3 }}
        {% elif (states('sensor.your_sensor’) == ‘rising') %}
          {{ 2 }}
        {% elif (states('sensor.your_sensor')
        {% endif %}

Many thanks! Looks like what I need, what’s the best way to set something if the original sensor is offline/unavail etc. i.e. what’s the correct failsafe way to handle such a template?

You should just be able to just add a default value to the end of the “If/Else” statements to output “Unavailable” or “Unknown”