Create calendar events from completed task

Hi community, can you help me create an automation so that every time I complete a task from the local task list, an event is created in the calendar with the date, time and name of the task completed. I have been using Chatgpt but I can’t get it.

Triggering off of ToDos is still kind of limited and template-heavy… and ChatGPT is a bullshit engine that is really bad at Home Assistant configuration and templating.

alias: ToDo Completion to Calendar Event
description: ""
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: todo
      service: update_item
    variables:
      list_name: |
        {% set ent = trigger.event.data.service_data.entity_id[0] %}
        {{ state_attr(ent, 'friendly_name') }}
conditions:
  - alias: Test if the list that was edited was one of the specified lists
    condition: template
    value_template: "{{ list_name in ['MY EXAMPLE TODO LIST']}}"
  - alias: Test if this is a completion event
    condition: template
    value_template: "{{ trigger.event.data.service_data.status == 'completed' }}"
  - alias: Test if this is a description change event
    condition: template
    value_template: "{{ trigger.event.data.service_data.description is not defined }}"
actions:
  - variables:
      task: "{{ trigger.event.data.service_data.rename }}"
      timestamp: "{{ now() }}"
  - action: calendar.create_event
    data:
      start_date_time: "{{ timestamp }}"
      end_date_time: "{{ timestamp + timedelta(minutes=1) }}"
      summary: To Do Item Completed
      description: |
        ToDo List: {{ list_name }}
        Task: {{ task }}
        Timestamp: {{ timestamp }}
    target:
      entity_id: calendar.EXAMPLE
mode: single

First thank you very much for the return.
I tried the automation but it doesn’t work for me, I leave you the code with the parameters I changed and the error

alias: ToDo Completion to Calendar Event
description: ""
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: todo
      service: update_item
    variables:
      list_name: |
        {% set ent = trigger.event.data.service_data.entity_id[0] %}
        {{ state_attr(ent, 'friendly_name') }}
conditions:
  - alias: Test if the list that was edited was one of the specified lists
    condition: template
    value_template: "{{ list_name in ['todo.tareas']}}"
  - alias: Test if this is a completion event
    condition: template
    value_template: "{{ trigger.event.data.service_data.status == 'completed' }}"
  - alias: Test if this is a description change event
    condition: template
    value_template: "{{ trigger.event.data.service_data.description is not defined }}"
actions:
  - variables:
      task: "{{ trigger.event.data.service_data.rename }}"
      timestamp: "{{ now() }}"
  - action: calendar.create_event
    data:
      start_date_time: "{{ timestamp }}"
      end_date_time: "{{ timestamp + timedelta(minutes=1) }}"
      summary: To Do Item Completed
      description: |
        ToDo List: {{ list_name }}
        Task: {{ task }}
        Timestamp: {{ timestamp }}
    target:
      entity_id: calendar.familia
mode: single

error:
Detenido porque se ha producido un error a las 10 de octubre de 2024, 16:01:57 (tiempo de ejecución: 0.00 segundos)

UndefinedError: ‘dict object’ has no attribute ‘event’

That error means it failed at setting up the first variable after the trigger. Most often this type of error is caused when a user attempts to test an automation that relies on the trigger variable by using the “Run” option from the automation menu or by calling the automation.trigger action… neither of those will populate the trigger variable.

Also the value in the first condition should be the Name of the entity, not its entity ID. So it should likely be "{{ list_name in ['Tareas']}}"

Thanks for the help! I wouldn’t have done it without you.
When running the automation I had some errors which I corrected with the help of claude.ai and it worked as follows

alias: ToDo Completion to Calendar Event - Tareas
description: ""
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: todo
      service: update_item
    variables:
      list_name: |
        {% set ent = trigger.event.data.service_data.entity_id[0] %}
        {{ state_attr(ent, 'friendly_name') }}
conditions:
  - alias: Test if the list that was edited was one of the specified lists
    condition: template
    value_template: "{{ list_name in ['Tareas']}}"
  - alias: Test if this is a completion event
    condition: template
    value_template: "{{ trigger.event.data.service_data.status == 'completed' }}"
  - alias: Test if this is a description change event
    condition: template
    value_template: "{{ trigger.event.data.service_data.description is not defined }}"
actions:
  - variables:
      task: "{{ trigger.event.data.service_data.rename }}"
      timestamp: "{{ now().isoformat() }}"
  - action: calendar.create_event
    data:
      start_date_time: "{{ timestamp }}"
      end_date_time: |
        {{ (now() + timedelta(minutes=1)).isoformat() }}
      summary: "{{ list_name }}: {{ task }} Completada!!!"
      description: |
        ToDo List: {{ list_name }}
        Task: {{ task }} Completa!
    target:
      entity_id: calendar.tareas
mode: single

Thanks for the help! I wouldn’t have done it without you.
When running the automation I had some errors which I corrected with the help of claude.ai and it worked as follows.

The errors were in the sum of date and time and time zone… just that line but the rest worked!! Thank you very much