Calendar Event Creation from Automation (times)

Hi All, been learning how to use HA to intergrate my security cameras, take a snapshot on event trigger, then analyze the image with Google AI then notify my phone. All working well except I also want to record an entry to a calender as the last step in the automation. Using LLM Vision Events i have it set up and creating the event, but it returns an error saying both start and end times need setting. So I added the end_date_time data to be the same as start_date_time but now it throws an error saying it expected at least 1sec difference.
The entries are being created but how do I stop this error?
Or
How do I add a few seconds or mins to the end time code?

Currently written as

- action: calendar.create_event
  metadata: {}
  data:
      description: "{{response_google.response_text}}"
      summary: Backyard
      start_date_time: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
      end_date_time: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
  target:
       entity_id: calendar.llm_vision_events

Thank you for any assistance

To reslove the error, add a few seconds to the end_date_time to ensure there’s at least a 1-second difference between start_date_time and end_date_time. Use the timedelta function in your script to add this difference. Here’s how your script should look: KMFusa

- action: calendar.create_event
  metadata: {}
  data:
      description: "{{response_google.response_text}}"
      summary: Backyard
      start_date_time: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
      end_date_time: "{{ (now() + timedelta(seconds=10)).strftime('%Y-%m-%d %H:%M:%S') }}"
  target:
       entity_id: calendar.llm_vision_events

This example uses timedelta(seconds=10) to add 10 seconds to the end_date_time, ensuring there’s a sufficient difference between the start and end times, resolving the error. Adjust the number of seconds or minutes as needed.

1 Like

Thank you. I had tried using timedelta in developer template testing but in a different way and it kept showing extra details (think it was the timezone etc).