How to list only weekends events from calendar entity?

I have linked my calendar with Home Assistant, and correctly got a calendar entity. I can nicely display a list of events within a certain range using the Calendar card.

However, I would like to display a list of events only on the upcoming weekends (e.g events on the next 4 weekends, saturdays and sundays). I know that I can run the calendar.get_events action:

action: calendar.get_events
target:
  entity_id: calendar.my_calendar
data:
  start_date_time: "{{today_at()}}"
  duration:
    days: 100
calendar.my_calendar:
  events:
    - start: "2026-02-19"
      end: "2026-02-21"
      summary: Nursery
    - start: "2026-02-19T18:00:00+00:00"
      end: "2026-02-19T19:00:00+00:00"
      summary: Cleaning

And I can use these events as a variable in templating:

    action:
      - action: calendar.get_events
        data:
          start_date_time: "{{ today_at() }}"
          duration:
            days: 60
        target:
          entity_id: calendar.my_calendar
        response_variable: agenda

      - variables:
          events: "{{ agenda['calendar.my_calendar']['events'] }}"

But I’m not sure how to select only events which fall on weekends.

Can anyone help me here?

I am not the best in jinja, but I would do something like this:

{% set events = agenda['calendar.my_calendar']['events'] %}
{% set ns = namespace(ev_weekend=[]) %}
{% for ev in events %}
{% if as_timestamp(ev.start)| timestamp_custom('%w')|int in (0,6) %}
{% set ns.ev_weekend=ns.ev_weekend + [ev] %}
{% endif %}
{% endfor %}
{{ ns.ev_weekend }}

I believe you need to add the end inside your if also given the first example.

{% if as_timestamp(ev.start)| timestamp_custom('%w')|int in (0,6) or as_timestamp(ev.end)| timestamp_custom('%w')|int in (0,6) %}

Obviously there is still the issue with friday to monday events. Not sure how to deal with that.

1 Like

By no means a good way of doing it but this could be used.

Loop through the individual days of the event and if that day is 0 or 6 then its true.

{% set start = as_timestamp("2026-02-19T18:00:00+00:00")| timestamp_custom('%w') | int %}
{% set end = as_timestamp("2026-02-24T18:00:00+00:00") | timestamp_custom('%w') | int %}
{{ start}}
{{end }}

if it's past the weekend two loops is needed 
{% if start > end %}
  {% for a in range(start, max(end+1,7)) %} 
    {{a in (0,6)}}
  {% endfor %}
  {% for a in range(0, end+1) %} 
    {{a in (0,6)}}
  {% endfor %}
{% else %}
  {% for a in range(start, end+1) %} 
    {{a in (0,6)}}
  {% endfor %}
{% endif %}

You could get any events that are active over the weekend by finding the weekend dates first then doing a Repeat for each to run calendar.get_events.

fields:
  number_of_days:
    name: Number of Days
    required: true
    default: 10
    selector:
      number:
        min: 1
        max: 300
  calendars:
    name: Calendars
    required: true
    selector:
      entity:
        multiple: true
        filter:
          - domain: calendar
sequence:
  - variables:
      first: |
        {% set d = today_at() %}
        {{ (d + timedelta(days = 5-d.weekday())).isoformat() }}
      last: |
        {% set l = today_at('23:59') + timedelta(days = number_of_days) %}
        {{ (l + timedelta(days = 6-l.weekday())).isoformat() }}
      dates: |
        {%- set ns = namespace(dates=[]) %}
        {%- for i in range(0, 2+(number_of_days//7)) %}
          {%- set sat = first|as_datetime + timedelta(days=i*7) %}
          {%- set sun = sat + timedelta(days=1, hours=23, minutes=59) %}
          {%- set ns.dates = ns.dates + [{'start':sat.isoformat(),'end':sun.isoformat()}] %}
        {%- endfor %}
        {{ ns.dates|rejectattr('start','gt',last) | list }}
  - repeat:
      for_each: "{{dates}}"
      sequence:
        - action: calendar.get_events
          metadata: {}
          target:
            entity_id: "{{calendars}}"
          data:
            start_date_time: "{{ repeat.item.start }}"
            end_date_time: "{{ repeat.item.end }}"
          response_variable: agenda
        - variables:
            combined_events: "{{ combined_events|default([],1) + merge_response(agenda) }}"
  - action: persistent_notification.create
    metadata: {}
    data:
      message: "{{ combined_events | sort(attribute='start') | list }}"
      title: Combining weekend events