Help Request - Sensor convertion to number

hello
i have a sensor that gets values from internet site.
the values that it gets are 5

  • REDUZIDO
  • ALTO
    etc

i wish to use the values as a gauge, for that i have to convert the value of the sensor, for example
if sensor.riscoincendio=REDUZIDO then gives value 1
if sensor.riscoincendio=ALTO then gives value 4

so that i can add the gauge with this values
after that the sensor can be refreshed for example each 4 hours.

can someone please help me?
thanks

create a template sensor:

sensor:
- platform: template
  sensors:
    riscoincendiogauge:
      value_template: >-
        {% if is_states('sensor.riscoincendio', 'REDUZIDO') %}
        1
        {% elif is_states('sensor.riscoincendio', 'ALTO') %}
        4
        {% else %}
        0
        {% endif %}
1 Like

great ! thanks
will try it

hi. i have added like this but still says it is not numerical…

  - platform: template
    sensors:
      riscoincendiogauge:
        value_template: >-
          {% if is_states('sensor.riscoincendio', 'REDUZIDO') %}
          1
          {% elif is_states('sensor.riscoincendio', 'BAIXO') %}
          2
          {% elif is_states('sensor.riscoincendio', 'MODERADO') %}
          3
          {% elif is_states('sensor.riscoincendio', 'ALTO') %}
          4
          {% elif is_states('sensor.riscoincendio', 'CRĂŤTICO') %}
          5
          {% else %}
          0
          {% endif %}

in alternative, is there a way to have for example
if sensor is “ELEVADO” then show image_x
if sensor is “fsdfdfd” then show Image_y

Sorry don’t know what card you are trying to create.

Just a gauge card…so this means that i 1, 2 3 4 and 5 must be a number

It should be a number. You may need to add a unit of measurement for it to work.