Calendar event - strftime current time +1 minute

Hey, I’ve got an automation and part of it is as follows:
end_date_time: "{{ now().strftime(\"%Y-%m-%dT%H:%M:%S\") }}"

This sets the end time of a calendar event to the current time/date. However, what I’d like to do is alter it so it’s + 1 minute from the current time.

How might I achieve this?

Many Thanks

end_date_time: "{{ (now() + timedelta(minutes=1)).isoformat() }}"

That code doesn’t appear to work when I substitue it out for what I had above resulting in the following:

service: calendar.create_event
data:
  summary: "Event"
  start_date_time: "{{ now().strftime(\"%Y-%m-%dT%H:%M:%S\") }}"
  end_date_time: "{{ (now() + timedelta(minutes=1)).isoformat() }}"
target:
  entity_id: calendar.cal

Error parsing event input fields

Try working on the expression is developer tools / templates. Easier to iterate and see what may be going wrong.

Putting just this into developer tools / templates appear to return no errors

{{ (now() + timedelta(minutes=1)).isoformat() }}

Result:

Result type: string

2023-02-17T13:48:23.498075+00:00

This template updates at the start of each minute.

So perhaps it doesn’t work within an automation for another reason?

Is it because it’s returning this at the end:

.498075+00:00

When I only need:

2023-02-17T13:48:23

Not sure how I would get that result?

In your automation you are using “ to quote the string and “ within the string. Change those inner ones to single quotes and it’ll start loading.

This was tested and confirmed to work:

service: calendar.create_event
data:
  summary: "Event"
  start_date_time: "{{ now() }}"
  end_date_time: "{{ now() + timedelta(minutes=1) }}"
target:
  entity_id: calendar.cal

This worked perfectly, thank you.

1 Like