I would like to suggest a feature that’d allow users to work with the response variable from calendar.get_events
in developer-tools > template.
Let’s say I run this service
service: calendar.get_events
data:
start_date_time: "{{ today_at() - timedelta(days=2) }}"
end_date_time: "{{ now() }}"
target:
entity_id: calendar.test123
Then I’ll receive this data
calendar.test123:
events:
- start: "2024-05-20T06:20:59+02:00"
end: "2024-05-20T06:40:59+02:00"
summary:This is
description: ""
- start: "2024-05-21T12:54:22+02:00"
end: "2024-05-21T13:14:22+02:00"
summary: a test
description: ""
- start: "2024-05-21T15:01:46+02:00"
end: "2024-05-21T15:21:46+02:00"
summary: remember to hoard potatoes for the next potatoe famine
description: ""
Currently, there is no way to work with this data straight away. Perhaps, Home Assistant could store the most recent calendar.get_events
response variable, so that it would automatically be available for jinja2 testing in template.
For example, whatever the last manual service call (via developer-tools > service) returns could be saved to last_response
.
Then, one could use it like
{% set events = last_response['calendar.test123']['events']
| selectattr('summary', 'contains', 'potatoe') | list %}
{{ (today_at() - (events | selectattr("summary", "contains", "potate")
| sort(attribute='start', reverse=1) | first)['start']|as_datetime|as_local).days | default(0, 1) }}
Or did I miss something and this is possible already? I find it quite difficult to query the calendar (in fact, the code snippet above was 99% from this community, I just adapted it to my needs), and being able to have this data (= whatever the service calls returns) available in template would make things so much more simple.