Here’s a revised version of what I had suggested two years ago.
Create a Trigger-based Template Sensor to periodically get your daily weather forecast and save it in an attribute named forecast
. In the following example, replace weather.forecast_home
with the entity_id of your weather entity.
template:
- trigger:
- platform: time_pattern
hours: /1
- platform: event
event_type: event_template_reloaded
action:
- variables:
entity_id: weather.forecast_home
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: "{{ entity_id }}"
response_variable: daily
sensor:
- name: Daily Weather Forecast
unique_id: daily_weather_forecast
state: "{{ now().isoformat() }}"
attributes:
forecast: >
{% set ns = namespace(forecast=[]) %}
{% for d in daily[entity_id]['forecast'] %}
{% set ns.forecast = ns.forecast +
[{
"condition": d.condition,
"datetime": d.datetime,
"wind_bearing": d.wind_bearing,
"temperature": d.temperature | round(0, default=-99),
"templow": d.templow | round(0, default=-99),
"wind_speed": d.wind_speed | round(0, default=-99),
"precipitation": d.precipitation,
"humidity": d.humidity
}] %}
{% endfor %}
{{ ns.forecast }}
After you have added it to wherever you store Template entities (either in configuration.yaml
or perhaps in a separate file like templates.yaml
) execute Developer Tools > YAML > Reload Template entities. Confirm there are no related errors reported in the Log.
Confirm sensor.daily_weather_forecast
exists in Developer Tools > States and it contains a forecast
attribute.
Now add the following Template Weather entity to your configuration.yaml
file. Change name
to whatever you prefer and replace weather.forecast_home
with the entity_id of your weather entity.
weather:
- platform: template
name: "Forecast Home Rounded"
condition_template: "{{ states('weather.forecast_home') }}"
temperature_template: "{{ state_attr('weather.forecast_home', 'temperature') | round(0, default=-99) }}"
humidity_template: "{{ state_attr('weather.forecast_home', 'humidity') | round(0, default=-99) }}"
forecast_daily_template: "{{ state_attr('sensor.daily_weather_forecast', 'forecast') }}"
After you have added it, execute Developer Tools > YAML > Reload Template entities (or restart Home Assistant). Confirm there are no related errors reported in the Log.
Confirm weather.forecast_home_rounded
(or whatever you renamed it to) exists in Developer Tools > States.
Now you can use the Weather Forecast card to display the new weather
entity. In the following screenshot, the top weather card shows the original values from met.no (weather.forecast_home
) and the bottom weather card shows rounded values (weather.forecast_home_rounded
).