You can define variables in the action
block:
template:
- trigger:
- platform: time_pattern
seconds: /10
action:
- service: calendar.get_events
target:
entity_id: calendar.waste_collection
data:
duration:
days: 14
response_variable: waste_events
- variables:
all_events: "{{ waste_events['calendar.waste_collection'].events }}"
paper_ev: "{{ all_events | selectattr('summary', 'search', 'Paper', true) }}"
food_ev: "{{ all_events | selectattr('summary', 'search', 'Food', true) }}"
non_recycle_ev: "{{ all_events | selectattr('summary', 'search', 'Non-Recyclable', true) }}"
sensor:
- name: Food Waste Collection Events
state: |
{{ food_ev | list | count() }}
attributes:
scheduled_events: |
{{ food_ev | list }}
next_collection_date: |
{{ (food_ev | first).start }}
countdown: |
{{ int((as_timestamp((food_ev | first).start) - as_timestamp(today_at('00:00')))/86400)}}
# And so on for each waste type...