Change sensor values display names

Hi All

I am quite new to this ESPHome and Home Assistant world, and definately NOT a YAML programmer…

I have managed to get HA and ESPHome running, and with great help form examples on this forum gotten an ESP32 to talk to my heatpump, and give back variuos information.

One of the things I get back is the compressor status, in the form of a 0-10 numerical value. I would like to present this status on my dashboard in text form, but I can’t get it to work.

I have seen and tried several examples found on the forums on how to convert these numbers into text, but I can’t get any of them to work on my environment…

My sensor:

- platform: modbus_controller
    modbus_controller_id: epever
    name: "Kompressor Status"
    id: compressor_status
    register_type: read
    address: 0x0000F241
    value_type: S_WORD

Any assistance would be appreciated

once the value is showing up in HA (use Developer Tools / States to see it) then you can use a template sensor to create what ever you want …as a completely different example I have shows (i copied and pasted from somebody else but have learnt how to use templates with scripts

  - platform: template
        friendly_name: Wind force
        icon_template: " mdi:weather-windy"
        value_template: "{% set wind = states('sensor.wind_speed_2')|float %}
        {% set wind_round = wind|round(1) %}
        {% if wind <= 1 %}Bft: 0, Calm, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 3 %}Bft: 1, Light air, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 6 %}Bft: 2, Light breeze, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 10 %}Bft: 3, Gentle breeze, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 16 %}Bft: 4, Moderate breeze, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 21 %}Bft: 5, Fresh breeze, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 27 %}Bft: 6, Strong breeze, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 33 %}Bft: 7, Near gale, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 40 %}Bft: 8, Gale, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 47 %}Bft: 9, Severe gale, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 55 %}Bft: 10, Storm, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% elif wind <= 63 %}Bft: 11, Violent storm, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {% else %} > 64 %}Bft: 12, Hurricane, {{wind_round}} Knts, {{states('sensor.cardinal_wind_direction')}}
        {%- endif %}"

Thank you, for you input.

I have the numerical value of the original sensor showing up just fine, but putting your suggestion into configuration.yaml, imidiately throws these errors (using the Visual Studio Code plugin)

@Spangsberg. I am really sorry but I have confused everything . The yaml I posted was not an answer for you. It will not work for you; as it is using two sensors from my esp which measure wind strength 15 knots) and wind bearing ( 195 degrees). The template converts those numbers into text, for example “Bft: 4, Moderate breeze, 15knts, WSW”which is then displayed on a display card on my dashboard.

I however posted it to see whether it is what you are trying to achieve. The best place to start is YouTube video tutorials on HA template and script. I used this to help me understand how to write the script. Sorry for confusion, but let me know if there is a specific question I can help with

@JulianDH Your script actually does exactly what I am trying to achieve, just with wind in stead of status.
My sensor also returns a number that I would like to display as text on card on the dashboard.
I am aware that I need to modify your script to read my sensors in stead of yours etc. but should the script put in configuration.yaml or in a custom card, or where do I start?

I don’t have experience with a modbus controller, but did you already looked at the modbus text_sensor Modbus Controller Text Sensor — ESPHome.

Another ESPHome solution would be the use of a template text_sensor Template Text Sensor — ESPHome.

add a on_value: tag to the modbus sensor and in that on_value: use the text_sensor.template.publish: action to publish with the help of a lambda the right text value.

@Spangsberg in the configuration.yaml.

The place to read about templates

Having just taken a look, I see that the code I pasted is legacy and not recommended, but there are many recommended up to date examples on the page. This has made me realise I need to update my code! I strongly recommend Developers Tools / Template editor to test all you script first.

I also recommend a video; something like this … I got me going!

He has a few other relevant videos to watch