Unsupported operand str and float

This is valid only if there is an upcoming vacation in calendar. If there is no entry, it throws this error. How to satisfy both conditions?

code:

{{ ((as_timestamp(state_attr('calendar.vacation', 'start_time'), '%Y-%m-%d')-as_timestamp(now())) | int(0) /60/1440) | round(0) }}

Error:

TypeError: unsupported operand type(s) for -: 'str' and 'float'

You need to give it a default value so that when there is no upcoming vacation it isn’t erroring.

e.g

as_timestamp(value, default)

where you have ‘%Y-%m-%d’ is meant to be the default value if the preceding value is incompatible. I’m not sure exactly what it needs to change to but definitely it needs a default

The approach you are using, testing the calendar entity’s start_time attribute, is not recommended because it can be unreliable.The entity’s attributes may not represent the actual next scheduled event, especially if there’s an all-day event (it overides all other events on that day) or concurrent events.

The developer of the Calendar integration recommends using a Calendar Trigger, with an offset, to be forewarned of a specific upcoming event.

ok. I understand. Something like this??

  trigger:
    - platform: calendar
      event: start
      entity_id: calendar.vacation
      offset: -96:0:0

Can you assist on how to get the description on that particular event?? The below will display the next event which would be incorrect. I want to display the event’s description let say 4 days from now.

 {{ state_attr('calendar.vacation', 'description') }}

trigger.calendar_event.description

Automation Trigger Variable for Calendar Trigger