Template for weather conditions at fixed time of next day

Hi there,
I’m quite neq at templating. After lots of looking through this forum, I’ve got a working template and I was able to format the datetime accordingly but I can’t put it together correctly.
This is what I’ve got, so far. It gives out the correct result:

{{ state_attr('sensor.dwd_hourly', 'forecast') | selectattr('datetime', 'match', 2024-04-27T17:00:00Z | map(attribute='temperature') |first}}

Also, I tried to get the correct datetime like this

{{ now().strftime('%Y-%m') }}-{{ now().strftime('%d') | int +1}}T07:00:00Z

Can someone tell me how I can combine these two into one template. I’ve failed, so far.
Thanks a lot!

The function today_at() will return a datetime object for the supplied time on today’s date in your local timezone. You can add a day to that using timedelta().

{% set target_t =  '17:00' %}
{% set t_format = (today_at(target_t) + timedelta(days=1)).strftime("%Y-%m-%dT%H:%M:%SZ")  %}
{{ state_attr('sensor.dwd_hourly', 'forecast') | selectattr('datetime', 'match', t_format) 
| map(attribute='temperature') | first }}

@Didgeridrew please stop writing all this code, I have so many bookmarks for the cool code tricks you write that I’ll never find them :joy:. Today at is a very cool and useful snippet!

You don’t need to write it down… it’s in the docs :stuck_out_tongue:

1 Like

Thanks, so much. I found the docs quite confusing. So thanks for your help!

Unfortunately, though, your code results in the wrong formatting which doesn’t fit to the attribute.
I need 2024-04-27T07:00:00Z and yours gives 2024-04-27 07:00:00+02:00. I’ll try something else using timedelta and see if it works.

You can use the strftime() method to get the time in your desired format. I have edited my post above to use the format "%Y-%m-%dT%H:%M:%SZ".

That results in the following error:

‘datetime.timedelta object’ has no attribute ‘strftime’

Double check that you didn’t miss a parenthesis.

Must have mixed something up, works now, thanks!