I have defined a sensor that tells me what tomorrow’s weather conditions will be by extracting it from the weather integration and have its history recorded. This is part of a bigger initiative but for now I’d just like to display this in a history card in Lovelace.
When displaying a weather sensor in a history card, the conditions get mapped e.g. partlycloudy
becomes “Partly cloudy” and so forth. It seems like this is based on what’s in translations/backend/en.json
in the frontend project.
Since my new sensor is in the sensor domain and not the weather domain, the mapping won’t be used and partlycloudy
will just be displayed as “partlycloudy”.
I know I can just create my own mapping in the sensor like in this post but then the actual states of the weather integration and the new sensor isn’t consistent.
Is there perhaps another way or trick to map it in the UI?
- platform: template
sensors:
weather_forecast_conditions_tomorrow:
friendly_name: "Weather Conditions Tomorrow"
value_template: >-
{{ state_attr('weather.home', 'forecast')[0]['condition'] }}
icon_template: >-
{% if state_attr('weather.home', 'forecast')[0]['condition'] == 'partlycloudy' %}
mdi:weather-partly-cloudy
{% else %}
mdi:weather-{{ state_attr('weather.home', 'forecast')[0]['condition'] }}
{% endif %}
![Screenshot 2021-03-11 at 21.41.25](https://community-assets.home-assistant.io/original/3X/f/7/f7a2605f59e38b6d7c6b6236860f59cdabcfa7ae.png)
![Screenshot 2021-03-11 at 21.41.33](https://community-assets.home-assistant.io/original/3X/f/6/f6efcf628de07d576d3eb4fef1dbb4363913f73f.png)
I found a neat workaround for this (old) problem, because I really didn’t want to hardcode the mappings in a template. I missed that since 2021.3 (coincidentally the month I posted this) there’s existed a template weather integration.
The trick is to take the next day forecast of an existing weather integration, e.g.:
weather:
- platform: template
name: "Forecast Tomorrow"
condition_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1]['condition'] }}"
temperature_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1]['temperature'] }}"
temperature_unit: "°C"
# workaround: https://github.com/home-assistant/core/issues/91620
humidity_template: "{{ 0.0 | float(0) }}"
pressure_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1]['pressure'] }}"
pressure_unit: "hPa"
wind_speed_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1]['wind_speed'] }}"
wind_speed_unit: "km/h"
wind_bearing_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1]['wind_bearing'] }}"
precipitation_unit: "mm"
# forecast_template: "{{ state_attr('weather.openweathermap_daily', 'forecast')[1:] }}"
attribution_template: "{{ state_attr('weather.openweathermap_daily', 'attribution') }}"
Note the bug in parsing the humidity though.
It’s a pity that there’s no field for precipitation
even though there’s one for precipitation_unit
(the omission seems odd). I could use that, but alas.
What do I use this all for? I want dedicated sensors to know what tomorrow’s conditions will be like (e.g. rainy, and the amount of rain expected), for better automation of my irrigation (my original template sensors are good enough for that part), but I’m also displaying this on a dashboard (and that’s where the mapping then matters. For the purpose of automation and using sensors, if I mapped “partlycloudy” (an actual state) to “Partly Cloudy” in a template sensor, then you can’t compare without extra logic. You had to choose between putting displayed states or internal states as the sensor value.
1 Like