Calendar.get_events next free 15 minutes and give the value to a script (or run O365 booking directly)

Hi,
I am trying to get an ePaper running, that shows the booking of a room (works), and I have an esp running with a button, which should trigger the booking of the next free 15 minutes (button press works, giving the button press back to HA works). What I am missing is to find the next free 15 minutes in a calendar and “book” those 15 minutes with the O365 integration. (I can book fixed dates in this calendar be manually running the script that needs to be enhanced.)
At the moment I have a template running every minute: (the “every minute” will be replaced by button press)

template:
  - trigger:
      - trigger: time_pattern
        minutes: "/1"
    action:
      - service: calendar.get_events
        data:
          duration:
            hours: 24
            minutes: 0
            seconds: 0
          start_date_time: "{{ today_at() }}"
        target:
          entity_id: calendar.kalender_framery_test

        response_variable: raw_events
      - variables:
          scheduled_events: "{{ raw_events['calendar.kalender_framery_test'] }}"

    sensor:
      - name: Calendar Scheduled Events
        unique_id: calendar_scheduled_events
        state: "{{ scheduled_events.events | count() }}"
        attributes:
          scheduled_events: "{{ scheduled_events.events }}"
        icon: mdi:calendar'

but I am stuck to find a way to find the next free 15 minutes slot in this calendar. (You can savely assume, that when the calendar is asked for a free slot, there will always be a free 15 minutes slot (even if it is after the workday ends).

Here the script that I want to trigger after finding the free slot, give the script the free slot, and let it “book” the slot in the calendar.

action: o365.create_calendar_event
metadata: {}
data:
  subject: Framery Buchung
  start: 2024-12-10T13:00:00+0100
  end: 2024-12-10T13:15:00+0100
target:
  entity_id: calendar.kalender_framery_test

If it makes more sense to directly call the o365.create_calendar_event directly from the template, I for sure would use this. The goal is to find the next free 15 minutes slot, and book it in the O365 calendar.

The scope above is way over my knowledge, I even cannot get the

    action:
      - service: calendar.get_events

correctly running with the new syntax.

thank you for any help
Juergen