Hello, I’m trying to automate my blinds in a script. I want them to automatically raise based on a rain forecast (precipitation amount), and lower again when no precipitation is predicted.
For this, I’m using openweathermap.get_minute_forecast
, which returns suitable data. The response contains 60 entries, and I’d like to filter these by a specific time range. However, this is where I’m stuck, since it seems I can’t directly compare the datetime values.
Maybe someone can help me with this.
This is a code-snippet I am using
sequence:
- alias: Minutenvorhersage abrufen
target:
entity_id: weather.openweathermap
response_variable: minute_forecast
action: openweathermap.get_minute_forecast
data: {}
- alias: Forecast extrahieren
variables:
forecast: "{{ minute_forecast['weather.openweathermap'].forecast }}"
minute_forecasts returns something like this:
minute_forecast:
weather.openweathermap:
forecast:
- datetime: '2025-06-24T21:29:00+00:00'
precipitation: 0
- datetime: '2025-06-24T21:30:00+00:00'
precipitation: 0
- datetime: '2025-06-24T21:31:00+00:00'
precipitation: 0
I extracted the forecast data (a snippet of variable forecast):
forecast: >-
[{'datetime': datetime.datetime(2025, 6, 24, 21, 29,
tzinfo=datetime.timezone.utc), 'precipitation': 0}, {'datetime':
datetime.datetime(2025, 6, 24, 21, 30, tzinfo=datetime.timezone.utc),
'precipitation': 0},
and tried to select just some data that is in a specific time-range. This is were I got stuck.
- alias: Regenmenge in 5 Minuten berechnen
variables:
regen_5min_summe: >
{% set jetzt = now().utcnow() %}
{% set werte = forecast
| selectattr('datetime', 'defined')
| selectattr('datetime', '>=', jetzt)
| selectattr('datetime', '<=', (jetzt + timedelta(minutes=5))
| map(attribute='precipitation')
| list %}
{{ werte | sum }}
It seems that I can’t compare the datetime-objects in that way, but I was not able to find out how to compare them.
Maybe someone could help me here.
Thanks so far!