Lockie
February 16, 2023, 4:21pm
1
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
petro
(Petro)
February 16, 2023, 4:37pm
2
end_date_time: "{{ (now() + timedelta(minutes=1)).isoformat() }}"
Lockie
February 17, 2023, 12:37pm
3
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.
Lockie
February 17, 2023, 1:47pm
5
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.
123
(Taras)
February 17, 2023, 4:20pm
8
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
1 Like
Lockie
February 17, 2023, 4:49pm
9
This worked perfectly, thank you.
1 Like