I would like to share an interesting information I found these days. I was monitoring the output of 4 weather integrations: Accu, OpenWeatherMap, DWD Wetterdienst (fl550) and DWD Wetterdienst (hg1337).
I found that depends on different integrations, the responsed list of weather.get_forecasts action changed the forecast date at different time. Here is a picture of history chart. Iâll explain below.
The picture shows 8 sensors I create with Template. For example, the first sensor template is
- trigger:
- platform: time_pattern
hours: "/1"
action:
- action: weather.get_forecasts
data:
type: daily
target:
entity_id:
- weather.accu
- weather.openwm
- weather.dwd_hg1337
- weather.dwd_fl550
response_variable: daily_forecasts
sensor:
- name: accu_forecast_datetime
state: "{{ daily_forecasts['weather.accu'].forecast[0].datetime }}"
I used forecast[0]
to show the first forecast of the list, which I supposed to be TODAY. From the first 4 rows in the picture we can see, the forecast[0]
is not always changed to today at 0:00. We can see Accu is the latest one, it changes first forecast to today at 5:00. OpenWeatherMap at 1:00.
This means for example if you use forecast[0]
to get a forecast value at 0:00 from Accu or OpenWeatherMap, the value you get is still for yesterday.
Then I adjust the template of sensor to always get the right value of today as below:
- name: openwm_forecast_datetime_today
state: "{{ daily_forecasts['weather.openwm']['forecast']|selectattr('datetime', 'match', states('sensor.date_time')[:10])|map(attribute='datetime')|join }}"
I use the date string splitted from sensor.date_time, filter the right forecast I need. The row 5 to 8 are new sensors. Now they are always updated at 0:00.
These datetime sensors are only used to confirm my template, based on that if we want to have a forecast precipitation value of today, we can then change the attribute
in the map()
filter.
- name: openwm_forecast_precipitation_today
state: "{{ daily_forecasts['weather.openwm']['forecast']|selectattr('datetime', 'match', states('sensor.date_time')[:10])|map(attribute='precipitation')|join }}"
Now we can get the right precipitation value for today, from no matter what integration.