Run automation 15 min before a calender event ends

I have used to have a template to start an automation 15 min before the event ends. This do not work anymore. I know there was a breaking change on this in 2021…

The trigger in my automation is

{{ ((as_timestamp(states.calendar.MY_CALENDAR.attributes.end_time) - as_timestamp(now())) < 900) }}

This will fail, but I can’t see how this should be :slight_smile: Anyone?

Why do you say it will fail?

I used that code in dev tools (substituting my cal info) and it seemed to work fine.

I get this message in dev tools:

TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘float’

And in the log file i get:

WARNING (MainThread) [homeassistant.helpers.template] Template warning: ‘as_timestamp’ got invalid input ‘’ when rendering template ‘{{ ((as_timestamp(states.calendar.MY_CALENDAR.attributes.end_time) - as_timestamp(now())) < 900) }}’ but no default was specified. Currently ‘as_timestamp’ will return ‘None’, however this template will fail to render in Home Assistant core 2022.1

Those messages are likely because there is no calendar entry for “MY_CALENDAR”.

if the calendar entry doesn’t exist then there is no “end_time” attribute so the template doesn’t render properly.

you can get rid of the warning by supplying a default for the “as_timestamp” conversion (see here for how to do that) but if the calendar entry doesn’t exist then you still won’t get a valid trigger since it will always default to the default value.

I think you need to see why you aren’t getting the calendar entry to populate first and go on from there.