Having trouble updating a blueprint that involves converting from calendar.list_event to calendar.get_event (more using of passed fields

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

Don’t nest templates inside templates… just use the variable

{%- for event in holidays[public_holidays][“events”] %}

Drew,

THANK YOU SO MUCH!

I find the syntax of templates overall confusing, very power, but confusing. Your recommendation worked like a charm. Very simple and I should have thought of it myself.

Thanks again!

Hi, since your question has been answered, please take the time to mark the answer as solution, you do that by selecting the three dots under the post:

image

Then select the check box:

image

By doing so this can be useful to other users as well and prevents that someone else steps in and still tries to help you.