Help extracting calendar information

I’m out of my depth and have no idea what I’m doing.

I’m looking to be able to have an automation where 1 hour before an event, it will populate a text helper with the summary of the event.

The use case is, I have different parking space allocations at work, and I want to be able to view this from Android Auto, which I believe should be straight forward by selecting the helper, and seeing the parking space number displayed.

I tried the following but I know I’m going very wrong, but don’t know where to go from here.

alias: Test parking
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-1:0:0"
    entity_id: calendar.parking
condition: []
action:
  - service: calendar.get_events
    metadata: {}
    data:
      duration:
        hours: 24
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.parking
    response_variable: input_text.next_parking
mode: single
alias: Test parking
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-01:00:00"
    entity_id: calendar.parking
condition: []
action:
  - service: input_text.set_value
    data:
      value: "{{ trigger.calendar_event.summary }}"
    target:
      entity_id: input_text.whatever
mode: single

References

Calendar trigger variables
Input Text services


The example assumes the calendar’s event’s summary field does not exceed 255 characters in length.

Thanks for your help. I’m having a little issue with this however. I’m getting an error when I test run the automation:

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘calendar_event’

It feels like I should be referencing my calendar somewhere, is that right?
(the automation also isn’t being triggered by the event an hour before. But i’ll cross that bridge later, I can work around that)

alias: Test parking
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-01:0:0"
    entity_id: calendar.parking
condition: []
action:
  - service: input_text.set_value
    data:
      value: "{{ trigger.calendar_event.summary }}"
    target:
      entity_id: input_text.next_parking
mode: single

If you are trying to test the automation by using the “Run” command it will fail (with an error message like the one you received).

The following variable exists only when the automation’s Calendar Trigger is triggered.

trigger.calendar_event.summary

The Run command doesn’t exercise the automation’s trigger(s) and only executes its actions.

Reference

Testing your automation

It’s designed to trigger one hour before the start of the next scheduled event.

Ah okay, understood. I’ve not had it trigger for an event happening in an hours time, but I’ve created the event for 1hr2m ahead. I will create one further in the future and see if that works

The calendar event trigger listener only updates on the quarter-hour or when an automation with a calendar event trigger is reloaded. When testing by creating a new calendar event make sure to either:

  • Create the test calendar event so that it will trigger the automation after the next quarter hour. In your example that would mean scheduling the event for approximately 1 hour 15 minutes from the current time.
  • Create the calendar event then edit the automation so that it requires a new save. One easy option for this is to add a short delay at the end of the automation.

For this automation, with a negative 1 hour offset, you need to create the test event farther in the future (for the reasons described by Didgeridrew).

That all makes sense. Putting a larger buffer helped and that’s working great. Thanks for your help @123 and @Didgeridrew

1 Like