Date/time helper into Calendar Event

I have a date time helper (input_datetime.return_from_holiday) I want to create an automation that creates an event in the Holiday calendar 1 day before we arrive home (which another automation will run when the event starts which will then automate a few things around the house in prep for arriving home) But this isn’t working. I’ve checked these forums and tried various suggestions but none work. What am I missing?

alias: CREATE Return Home Event
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_datetime.return_from_holiday
conditions: []
actions:
  - data:
      start_date_time: "{{ (states('input_datetime.return_from_holiday') - timesdelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') }}"
      end_date_time: "{{ (states('input_datetime.return_from_holiday')).strftime('%Y-%m-%d %H:%M:%S') }}"
    action: calendar.create_event
    target:
      entity_id: calendar.holiday
mode: single

All states are strings, you need a datetime object to use timedelta() (and strftime(), but those aren’t actually necessary for what you are doing).

action: calendar.create_event
target:
  entity_id: calendar.holiday
data:
  start_date_time: |
    {{ states('input_datetime.return_from_holiday')|as_datetime - timedelta(days=1) }}
  end_date_time: |
    {{ states('input_datetime.return_from_holiday')|as_datetime }}
1 Like

Ah perfect thanks!