I am updating a blueprint originally created by bruxy70.
The blueprint is designed to work with 3 calendars and based upon a holiday, shift an event (such as trash collection) when a holiday falls before the event that week.
Originally the blueprint was written with calendar.list_events - which is going away in the June timeframe.
I have been able to successfully convert to calendar.get_event, however I can’t figure out the proper syntax to use a passed field (which is a calendar) to be used in the script.
Below is an excerpt of the blueprint (not the whole thing), but it does show the passed fields…
fields:
source_calendar:
name: Source calendar
description: Calendar with the events to be copied from
required: true
selector:
entity:
filter:
integration: local_calendar
destination_calendar:
name: Destination calendar
description: Calendar for the events to be copied to
required: true
selector:
entity:
filter:
integration: local_calendar
public_holidays:
name: Public Holidays
description: Calendar with the public holidays to be avoided
required: true
selector:
entity:
filter:
integration: holidays
sequence:
- service: calendar.get_events
data:
duration:
days: 365
target:
entity_id: '{{ source_calendar }}'
response_variable: source
- service: calendar.get_events
data:
duration:
days: 365
target:
entity_id: '{{ destination_calendar }}'
response_variable: destination
- service: calendar.get_events
data:
duration:
days: 365
target:
entity_id: '{{ public_holidays }}'
response_variable: holidays
- variables:
holiday_dates: |-
{%- set ns = namespace(dates={}) %}
{%- if holidays["calendar.us_holidays"]["events"] %}
{%- for event in holidays["calendar.us_holidays"]["events"] %}
{%- set ns.dates = dict(ns.dates, **{event.start:event.summary}) %}
{%- endfor %}
{%- endif %}
{{ ns.dates}}
destination_dates: |-
{%- set ns = namespace(dates={}) %}
{%- if destination["calendar.trash_days_offset_for_holidays"]["events"]%}
{%- for event in destination["calendar.trash_days_offset_for_holidays"]["events"] %}
{%- set ns.dates = dict(ns.dates, **{event.start:event.summary}) %}
{%- endfor %}
{%- endif %}
{{ ns.dates}}
- repeat:
for_each: '{{ source["calendar.trash_days"]["events"] }}'
sequence:
- variables:
Above, when reverencing the three calendars, I can’t determine the proper syntax to actually use the passed calendar.
For example, above,
{%- for event in holidays[“calendar.us_holidays”][“events”] %}
is having a hard coded calendar, when I would like to use the passing field (which contains the calendar. I would like to do something like this:
{%- for event in holidays[“‘{{ public_holidays }}’”][“events”] %}
where
‘{{ public_holidays }}’ actually contains “calendar.us_holidays”
I have tried various quoting. and options but every time I either get an error, or when there isn’t an configuration error, I get a runtime error where when I call the script based upon the blueprint I get a message similar to:
public_holidays not found within the calendar.
I am sure it is a pretty simple syntax issue on my side, but after several attempts, I am thinking it is time for help.
Thanks