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.