How to show only current calendar appointment

Hi, I would like to show upcomming and active calendar appointments on my lovelace dashboard.
I tried custom:atomic-calendar-revive, but the hideFinishedEvent: true does not seem to work. So I tried to make a template sensor myself omitting all-day events
But how do I also omit events where end<now() → ???

template:
  - trigger:
      - platform: time_pattern
        minutes: "/10"
      - platform: event
        event_type: event_template_reloaded
    action:
      - service: calendar.get_events
        target:
          entity_id: calendar.samen
        data:
          start_date_time: "{{today_at()}}"
          duration:
            days: 1
        response_variable: agenda
      - variables:
          samen_all: >
            {{ agenda["calendar.samen"].events | selectattr('start', 'match', '.*T.*' ) | rejectattr(???) | list }}
          samen_next: >
            {{ samen_all | first }}

Or does anybody know a better solution?

Instead of today_at() as your start date time, use now().

1 Like

Happy to be proved otherwise, but wouldn’t that cause it to hide events that are >10 minutes from now?

No, with start_date_time set to use now() the calendar.get_events service will return all events that are currently active or that start at any time up to the end of the observaed time span, as defined by the duration or end_date_time variable.

1 Like

Well, that’s about misleading. Thanks for clarifying!

Can you explain what you mean? If there’s something wrong in the docs or another source, then that needs to be fixed.

I meant the parameter name itself is a bit misleading. I naturally understood that start_date_time meant when the event starts, not whether it’s active up till the current time. It’s the “start” part that’s misleading.

I haven’t yet looked at the related docs so can’t really comment whether they explain this clearly or not. If this isn’t clear in the docs, maybe a change to clarify this would be a good idea.

Happy to send an edit myself if you could shoot me a link to the docs, but would rather run it by you first given I’m not very familiar with Calendar.

The start_date_time is the start of the period you want to check on (it defaults to now(), so you could just remove it, and only provide end_start_time or duration.

The service calls returns all events which are active in the period, so that will include all events which either start or end in that period, and not necessarily totally fall in the period set.

Ah, now it makes sense! Start & End refer to the period you’re checking, not the actual event. Gotcha.