Change end time of an Event from calendar trigger

I have an automation that triggers 24h before an appointment and should create another appointment that ends 4.5h earlier than the triggered appointment.
I use the Google Calendar integration.

I managed to create an appointment on the same day as the triggering appointment, but only full day…

 service: google.create_event
     data:
       summary: Blocker
       in:
         days: 1
     target:
       entity_id: calendar.arbeit_blocker

I tried this, but it doesn`t work because the templates are always overwritten when the automation is saved…

  - service: google.create_event
    data:
      start_date_time: {{ trigger.calendar_event.start }}
      end_date_time: {{ trigger.calendar_event.end }} - 04:30:00
    target:
      entity_id: calendar.arbeit_blocker

It is overwritten because your templates are invalid.

- service: google.create_event
  data:
    summary: Blocker
    start_date_time: "{{ trigger.calendar_event.start }}"
    end_date_time: "{{ trigger.calendar_event.end|as_datetime - timedelta(hours=4.5)}}"
  target:
    entity_id: calendar.arbeit_blocker
1 Like

This code results in the following error:

Error rendering data template: TypeError: unsupported operand type(s) for -: ‘str’ and ‘datetime.timedelta’

Are all these events longer than 4.5 hours? If not, you’re going to get failures unless you modify the start time as well.

All these events from which the new events are to be created are all-day events!

Apparently I have made a copy paste error! Have the whole thing now entered again on the PC and it works perfectly. Thank you!

1 Like