I want to change the name of "weather condition"

I want to show a forecast using SMHI weather provider and so far mdi-icons show except for partlycloudy. I assume this is because the mdi-icon is named partly-cloudy. I have a mark down card with this code to display icons (the number inside [ ] is used to choose day(s) ahead):
<ha-icon icon="mdi:weather-{{state_attr('weather.smhi_home', 'forecast')[1].condition}}"></ha-icon></br>

As I can’t get the icon to show i am trying to replace the name of it with a template that I found in the forumi, but as my coding is incorrect I end up with the value “mdi:weather-sunny-alert”.

This is the code I’ve added to my configuration.yaml:

  - platform: template
    sensors:
      weather_smhi_icon:
        friendly_name: Jonne
        value_template: >
          {% set mapper =
            {'clear-day': 'sunny',
             'clear-night': 'night',
             'sunny': 'sunny',
             'rain': 'rainy',
             'snow': 'snowy',
             'sleet': 'snowy-rainy',
             'wind': 'windy',
             'fog': 'fog',
             'cloudy': 'cloudy',
             'partlycloudy': 'partly-cloudy',
             'partly-cloudy-day': 'partly-cloudy',
             'partly-cloudy-night': 'night-partly-cloudy',
             'hail': 'hail',
             'thunderstorm': 'lightning',
             'tornado': 'hurricane'} %}
          {% set state = state_attr('weather.smhi_home', 'forecast'[1].condition) %}
          {% set weather = mapper[state] if state in mapper else 'sunny-alert' %}
            mdi:weather-{{weather}}

I can get the value (partlycloudy) in my frontend using:
{{state_attr(‘weather.smhi_home’, ‘forecast’)[5].condition}}

and that’s the value I want to change.

take a look ath the parenthesis that you used here:

and the one that you used here:

What’s the difference from your working one and your non working one?

1 Like

Thank you so much! Now I get the correct value. I am trying to implement the value to show the icon but am missing something. This code gives me the correct value:
{{states(‘sensor.weather_smhi_icon’)}}
outputs: mdi:weather-partly-cloudy

but I’m trying to use that value as the icon and here’s something wrong:
<ha-icon icon={{states('sensor.weather_smhi_icon')}}</ha-icon></br>

Solved: i had missed a >, it should read:
<ha-icon icon={{states('sensor.weather_smhi_icon')}}></ha-icon></br>