I have OpenWeatherMap integration set up, which has attributes as:
... visibility_unit: km precipitation_unit: mm forecast: - condition: cloudy precipitation_probability: 0 datetime: '2022-12-20T18:00:00+00:00' wind_bearing: 16 temperature: -0.3 pressure: 1024 wind_speed: 1.01 precipitation: 0 - condition: cloudy precipitation_probability: 0 datetime: '2022-12-20T21:00:00+00:00' wind_bearing: 123 temperature: -1.7 pressure: 1021 wind_speed: 1.87 precipitation: 0 ...
Now I want to filter the array “forecast” on datetime = today (datetime.strftime(%f) == now().strftime(%f) would do), select temperature, and get max value.
This is not only for this specific date, but to learn how to work with arrays where you want to filter on one property, select another, and then run some function on it to return single value. I will then use this logic on different sensors than weather, too.
In C# LINQ, I’d do something like
states.weather.openweathermap.forecast.Where(item => item.datetime.Date == DateTime.Today).Select(item => item.temperature).Max(),
but with templates/jinja2, I’m lost.