Convert home assistant timestamp into human readable time

I have an automation that starts an even with my calendar, and here is the action:

service: notify.mobile_app_alexphone
data:
  title: "Calendar alert:"
  message: >-
    {{ trigger.calendar_event.summary }} starts at {{
    trigger.calendar_event.start }}

When I type this here is the result:

The when the even starts are not human readable to me, so I asked Google Gemini to fix the action and here is the new action:

service: notify.mobile_app_alexphone
data:
  title: "Calendar alert:"
  message: >-
    {{ trigger.calendar_event.summary }} starts at {{
    trigger.calendar_event.start.strftime("%I:%M %p") }}

Unfortunately it does not work. What am I doing wrong and how to fix it. In my trigger the automation sends notification to my phone 1 hour before the event starts. I want to receive time like (the even starts at 8:45pm) and not this nonsense.

Thanks

The value of trigger.calendar_event.start is a datetime string, not a datetime object, therefore it doesn’t have a strftime method.

Use as_datetime to convert it to a datetime object.

service: notify.mobile_app_alexphone
data:
  title: "Calendar alert:"
  message: >-
    {{ trigger.calendar_event.summary }} starts at {{
    (trigger.calendar_event.start | as_datetime).strftime("%I:%M %p") }}

Example

1 Like

Thank you. It works :slight_smile:

1 Like