How to rename states of an entity?

First of all I am a total coding noob. I created a template sensor of an weather integration using a subentity.

- sensor:
    - name: dailyconditionforecastffm
      state: "{{state_attr('weather.dwd_weather_frankfurt','forecast')[0].condition}}" 

That’s working. In the next step I tried to rename the states using different if-commands, but nothing worked.

So I need a little help. Thanks in advance.

What are all the states the attribute value could be?

And what do you want them renamed to?

partlycloudy, cloudy, rain, etc.

Just want to translate them

List the translation for each weather condition.

leicht bewölkt, bewölkt, Regen

- sensor:
    - name: dailyconditionforecastffm
      state: >
        {% set x = 
          { 'partlycloudy': 'leicht bewölkt',
            'cloudy': 'bewölkt',
            'rain': 'regen'
          } %}
        {% set y = state_attr('weather.dwd_weather_frankfurt','forecast')[0].condition %}
        {{ x.get(y, 'unknown') }}
2 Likes

That worked, thanks a lot. Tried and googled it for about a week. Never stumbled acroos this set command.

1 Like