Hello together,
I am usingf the openweathermap integration to get some forecast data.
I figured out that there is some forecast data available all 3 hours:
I would have for the current day always the value at 15:00.
I did not get it managed and need your support.
I get it managed to get all the values, but not the dedicated I want:
"{{ state_attr('weather.openweathermap', 'forecast') }}"
I need to know how to get exactly that one value from example
datetime: '2023-05-26T15:00:00+00:00'
Thank you.
aceindy
(Aceindy)
2
Not sure if it is always the same list, but in the knmi weather i use it is, so i always use attribute [1]:
min: {{state_attr("weather.knmi","forecast")[1].templow|round}}.
if so, in your forecast to get 15:00 you could use something like this
"{{ state_attr('weather.openweathermap', 'forecast')[2] }}"
1 Like
{% set day = (today_at('00:00') + timedelta(days=0)).strftime('%F') %}
{{ state_attr('weather.openweathermap','forecast') | selectattr('datetime', 'match', '^'~day) | selectattr('datetime', 'match', '^.*(15:00)') | map(attribute='temperature') | list }}
this is a bit more than needed but note that ‘day’ you can change by altering the timedelta …e.g. if you want to know for tomorrow
1 Like
Thank you both!
I tested both variants in my template:
"{{ state_attr('weather.openweathermap', 'forecast')[2].datetime }}"
"{{ state_attr('weather.openweathermap', 'forecast')[2].temperature }}"
{% set day = (today_at('00:00') + timedelta(days=0)).strftime('%F') %}
{{ state_attr('weather.openweathermap','forecast') | selectattr('datetime', 'match', '^'~day) | selectattr('datetime', 'match', '^.*(15:00)') | map(attribute='temperature') | list }}
Current output:
"2023-05-26T15:00:00+00:00"
"21.8"
[21.8]
Will see if the first option always dfelivers the 15:00 value.
And for further usage I will check if I have to remove the brakets for the second try.
Thanks.
To complete:
Solution 1 always delivers the second value in the array, so it might switch from 15:00 to 18:00 based on the time of the day.
Solution 2 seems to be the best! I only have to replace the brackets.