Access Localized State Strings

Hi all,

I am collecting some values from different sensors into a new template sensor to be able to beautify the presented information. The sensors are coming from the Miele integration and provide localized state strings, here “Baumwolle” in German:

entity

I now have the issue that I cannot access those localized state strings in the template sensor. I can access either the original state (“cottons”) or the Localized attribute in English (“Cottons”) as it is shown in the Developer Tools States page:

My result:
tile

I guess I am missing something here, but I could not find anything to change the behaviour. Is the picking of the right Localized attribute happening within the frontend only?

    - name: washing_machine_program_info
      state: >
        {% if is_state('sensor.washing_machine_status', 'off') %}
          Ausgeschaltet
        {% else %}
          {{ state_attr('sensor.washing_machine_programm', 'Localized') }}
        {% endif %}
      icon: mdi:washing-machine
      attributes:
        icon_color: >
          {% if is_state('sensor.washing_machine_status', 'running') %}
            blue
          {% elif is_state('washing_machine_status', 'Program ended') %}
            green
          {% elif is_state('sensor.washing_machine_status', 'off') %}
            disabled
          {% else %}
            red
          {% endif %}
        program_stage: >
          {{ iif(has_value('sensor.washing_machine_programmabschnitt'), state_attr('sensor.washing_machine_programmabschnitt', 'Localized'), ' ')}}
        program_end: >
          {{ iif(has_value('sensor.washing_machine_ende_um'), 'Ende um ' + states('sensor.washing_machine_ende_um'), ' ')}}
        program_remaining: >
          {% if is_state('sensor.washing_machine_status', 'off') %}
            {{ ' ' }}
          {% else %}
            {{ iif(has_value('sensor.washing_machine_verbleibende_zeit'), states('sensor.washing_machine_verbleibende_zeit') + ' min verbleibend', ' ')}}
          {% endif %}

Servus,
I found the solution and wanted to add it since I could not find it easily by googling.
There is a method called “state_translated”. So just replace the states(“sensor.name”) call with state_translated(“sensor.name”) and it will use the locale you have configured for HA.
Hope this helps.

2 Likes