Sensor value friendly name

I’m wondering if there is a way to ‘template’ a sensor value. I’m not able to change the value that is published to mqtt, but I want to change the value that home assistant presents. Consider the following:

  • platform: mqtt
    state_topic: “thermostat”
    name: “Thermostat Operating Mode”
    value_template: “{{ value_json.tmode}”

The expected values, and the corresponding strings I am interested are:
0: OFF
1: HEAT
2: COOL
3: AUTO

Is it possible to convert the integer value received by mqtt message to a string?

On value_template, you can use an IF statement.

value_template: "{% if value_json.tmode == '0' %}OFF{% elif value_json.tmode == '1' %}HEAT{% elif value_json.tmode =='2' %}COOL{% elif value_json.tmode =='3' %}AUTO{% endif %}"
1 Like

Perfect, I knew it had to be something like that. The only change I had to make was to take the quotes out from the values. They are presented as integers in the mqtt message.

Thank you!

Any idea how to do this for a whole list of values?

Basically I want to change the output of the YR symbol to the actual weather type.

http://api.met.no/weatherapi/weathericon/1.1/documentation

Example, instead of “4”, I want to display “Cloud” (or even “Cloudy” to use proper english)

Sure! Just keep "elif"ing.

value_template: "{% if value_json.symbol == '1' %} Sun {% elif value_json.symbol == '2' %} Light Cloud {% elif value_json.tmode =='3' %} Partly Cloudy .. .. .. etc .. .. etc .. {% endif %}"

Where do you put the code?

I’ve tried to add an entry for the “sensor.weather_symbol:” under “customize:” in configuration.yaml but that did not work. After restart there were no visual effects.