Duplicate calendar entries

Is there any easy way to check for the existence of a specific calendar event before creating a duplicate? I have an automation which creates an event in my local ‘maintenance’ calendar for next year when a boiler service is completed.

alias: 30. Maintenance Dates from Calendars
description: >-
  1. write from text.boiler_next_maintenance_date (check emsesp
  boiler/maintenancedate) to calendar. 2. Write from
  date.vallox_next_filter_change_date (check
  vallox/date.vallox_filter_change_date) to calendar
triggers:
  - entity_id:
      - text.boiler_next_maintenance_date
    id: boiler
    trigger: state
  - entity_id:
      - date.vallox_filter_change_date
    id: vallox
    trigger: state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - boiler
        sequence:
          - action: calendar.create_event
            data:
              summary: Boiler - next service
              start_date_time: >-
                {{states('text.boiler_next_maintenance_date')[6:12]}}-{{states('text.boiler_next_maintenance_date')[3:5]}}-{{states('text.boiler_next_maintenance_date')[0:2]}}
                08:00:00
              end_date_time: >-
                {{states('text.boiler_next_maintenance_date')[6:12]}}-{{states('text.boiler_next_maintenance_date')[3:5]}}-{{states('text.boiler_next_maintenance_date')[0:2]}}
                16:00:00
            target:
              entity_id: calendar.maintenance_plan
      - conditions:
          - condition: trigger
            id:
              - vallox
        sequence:
          - action: calendar.create_event
            data:
              summary: Vallox - next filter replacement
              start_date_time: >-
                {{(states('date.vallox_filter_change_date')[0:4]|int+1)}}{{(states('date.vallox_filter_change_date')[4:8])}}{{(states('date.vallox_filter_change_date')[8:10])}}
                08:00:00
              end_date_time: >-
                {{(states('date.vallox_filter_change_date')[0:4]|int+1)}}{{(states('date.vallox_filter_change_date')[4:8])}}{{(states('date.vallox_filter_change_date')[8:10])}}
                16:00:00
            target:
              entity_id: calendar.maintenance_plan
mode: single

The problem with this is that if the state of text.boiler_next_maintenance_date changes for any reason other that entering a new service date into the boiler, for example a restart of the ESP providing the data, it creates a new event. Over the course of the last year I managed to create 73 identical entries for the next service on 5th January 2026. Any ideas, please?

It just so happens that I was about to work on the same thing when I stumbled upon that question. I’m circling back with a suggestion here now that I solved it on my end.

What you can do is use the calendar.get_events action’s response to check for duplicates in a subsequent condition.

Here’s my script that tries to create a 4-hour block event if one doesn’t already exist:

alias: Add Event
description: ""
fields:
  input_timestamp:
    selector:
      datetime: {}
    name: Input Timestamp
    required: true
sequence:
  - variables:
      start_dt: "{{ as_datetime(input_timestamp) }}"
      end_dt: >-
        {{ as_datetime(input_timestamp) + timedelta(hours=4) }}
  - action: calendar.get_events
    target:
      entity_id: calendar.my_calendar
    data:
      start_date_time: "{{ start_dt }}"
      end_date_time: "{{ end_dt }}"
    response_variable: calendar_events
  - if:
      - condition: template
        value_template: |
          {{ calendar_events["calendar.my_calendar"]["events"] | length == 0 }}
    then:
      - action: calendar.create_event
        target:
          entity_id: calendar.my_calendar
        data:
          summary: Unique Event
          start_date_time: "{{ start_dt }}"
          end_date_time: "{{ end_dt }}"

Now this is a rather simple condition check that fits my use case but you can further inspect the calendar.get_events response for your needs. See documentation: Calendar - Home Assistant

Hope that helps!

It does, thank you. How does this look to you?

alias: 30a. Boiler Maintenance Dates from Calendars
description: >-
  1. read from text.boiler_next_maintenance_date (check emsesp
  boiler/maintenancedate). Check calendar for existing event. If not write to
  calendar to calendar. 
variables:
  test_date: >-
    {{states('text.boiler_next_maintenance_date')[6:12]}}-{{states('text.boiler_next_maintenance_date')[3:5]}}-{{states('text.boiler_next_maintenance_date')[0:2]}}
triggers:
  - entity_id:
      - text.boiler_next_maintenance_date
    id: boiler
    trigger: state
conditions: []
actions:
  - action: calendar.get_events
    target:
      entity_id: calendar.maintenance_plan
    data:
      start_date_time: "{{ test_date }} 00:00:01"
      end_date_time: "{{ test_date }} 23:59:59"
    response_variable: calendar_events
  - if:
      - condition: template
        value_template: |
          {{ calendar_events["calendar.my_calendar"]["events"] | length == 0 }}
    then:
      - action: calendar.create_event
        target:
          entity_id: calendar.maintenance_plan
        data:
          summary: Boiler - next service
          start_date_time: "{{ test_date }} 08:00:00"
          end_date_time: "{{ test_date }} 16:00:00"
mode: single

I’ll give it a go if you think I’m passing the date_times over OK.