Use localized sensor value from Home Assistant text sensor

Hello everyone,

I think I read in the ESPHome release notes that the localized sensor value is no longer transmitted via the HomeAssistant API, but rather the internal status value.

I think that was sometime last summer. Now I have some time and wanted to solve the “problem” so that the localized values are displayed on my LVGL display again, but I can’t find any information about it. In Home Assistant Templating there is “state_translated”, is there something like that in ESPHome?

It would be tedious to have to translate every value for multiple sensors back in the code.

These values are now displayed in ESPHome.

sensor.oralb_mirco_mode
sensitive

options: gum_care, whitening, turbo, whiten, intense, settings, unknown, deep_clean, daily_clean, sensitive, super_sensitive, massage, tongue_cleaning, off
assumed_state: true
device_class: enum
friendly_name: OralB Mirco Putzmodus

Until a few months ago, these were the values

text_sensor:
  - platform: homeassistant
    name: "Mirco_Mode"
    entity_id: sensor.oralb_mirco_mode
    id: mirco_mode
    internal: true
    on_value:
      - lvgl.label.update:
          id: lvgl_mirco_mode
          text:
            format: "%s"
            args: [ 'id(mirco_mode).state.c_str()' ]

How can I display the localized values again?
Thank you very much for any help.

Same here. Looking how to send this two sensor types to the ESPHome with LVGL and display. In HA it shows the normal text. Struggling to display same text on the display.

ENUM:

and
Localized:

I was able to get it working. It seems that HA and ESPhome communicate using text strings to exchange data.
In such case, I have first set up a standard sensor, that can only display numbers.
like this:

 - id: susilc_job_state_widget_sensor
    platform: homeassistant
    entity_id: sensor.susilc_job_state
    on_value:
      - lvgl.label.update:
          id: susilc_job_state
          text:
            format: "%d"
            args: ['x']

end this was in the log:

#[20:49:40.518][W][homeassistant.sensor:015]: 'sensor.susilc_job_state': Can't convert 'cooling' to number!

so I tried with text_sensor:

  - id: susilc_job_state_widget_sensor
    platform: homeassistant
    entity_id: sensor.susilc_job_state
    on_value:
      - lvgl.label.update:
          id: susilc_job_state
          text: !lambda return x;

and voila, enumerated text appeared on the display.

I think your problem is in the code, how to pass text to the label. This works for me: text: !lambda return x;

So the Enum seems to be working fine now.
Next step is the Localized. That Raw value looks like this might behave differently. Let’s try.

Try this:

state_translated('sensor.waschmaschine_programm')

if you are not able to implement this in ESPHome, then alternative is to make a few new text entities in HA (Helpers + automations or template sensors) that convert text using the state_translated function.