Calendar - new entitites or helper that show a list of calendar events within a certain scope

Yep! This is meant to address this problem, but in the works for awhile now and happy to get it out!

1 Like

Good job Allen. Thanks!

  • calendar.list_events - This service allows you to ask Home Assistant for a list of events on your calendar.

Yes! I scrolled all the way through this post hoping for an answer, and it’s just a few days from release! Very happy to see this added. :slightly_smiling_face:

Is there a way of merging responses from multiple calendars ?

You’ll have to send separate calls for each calendar. Perhaps you can merge the events lists? I have not tried this

I made this script, for german language, using the new calender.list_events feature, maybe it helps as a starting point for other people.
@ allenporter thx for this new feature. Unfortunately your featured Blueprint did not work correctly.

Start-End: {% if event.start is defined %}{{ event.start }} to {{ event.end }}{% else %}All Day{% endif %}

did not work, because event start and end is always defined, at least for google calendar. My workaround was to check whether an event lasts exactly 86400 seconds = 1 day, in this case it’s an “All Day” event.

alias: 24h_termine_NestTTS_de
sequence:
  - service: calendar.list_events
    data:
      duration:
        hours: 25
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.your_calendar
    response_variable: agenda
  - service: tts.google_translate_say
    data:
      entity_id: media_player.nest_room1, media_player.nest_mini_room2
      language: "de"
      message: >-
        {% set tage =
        ["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"]
        %} {% set months = ["Januar", "Februar", "März", "April", "Mai", "Juni",
        "Juli", "August", "September", "Oktober", "November", "Dezember"] %}

        {%- if agenda.events %}
          {%- for event in agenda.events %}
            {% if event.start is defined %}
              {% if (((as_timestamp(event.start)) - (as_timestamp(now())) < 86400) and ((as_timestamp(event.start)) - (as_timestamp(now())) > 0)) %}     
                Am {{ tage[as_datetime(event.start).weekday()] }}
                den {{ as_timestamp(event.start) | timestamp_custom ('%d/%m/%Y') }}
                  {% if (as_timestamp(event.end)) - (as_timestamp(event.start)) == 86400 %}
                    ganztägig
                  {% else %}
                    um {{ as_timestamp(event.start) | timestamp_custom ('%H:%M %p') }} bis {{ as_timestamp(event.end) | timestamp_custom ('%H:%M %p') }}
                  {% endif %}
                ist {{ event.summary }}
                  {%- if event.description is defined %}
                    Hinweise, {{ event.description }}
                  {% endif -%}
                  {%- if event.location is defined %}
                    Ort, {{ event.location }}
                  {% endif -%}
              {% endif -%}  
            {% endif %}
          {%- endfor %}
        {% endif -%}

OT: Feature Request to HA:
Please make strftime respect locale or integrate babel

1 Like

If you’re interested, you can simplify the template’s arithmetic if you convert the values of event.start and event.end to datetime objects.

{%- if agenda.events %}
  {%- for event in agenda.events if event.start is defined -%}
    {%- set start = event.start | as_datetime | as_local -%}
    {%- set end = event.end | as_datetime | as_local -%}
    {%- if start > now() and start - now() < timedelta(days=1) %}     
      Am {{ tage[start.weekday()] }} den {{ start.strftime('%d/%m/%Y') }}
      {%- if end - start == timedelta(days=1) %} ganztägig
      {%- else %} um {{ start.strftime('%H:%M %p') }} bis {{ end.strftime('%H:%M %p') }}
      {%- endif %} ist {{ event.summary }}
      {%- if event.description is defined %}
      Hinweise, {{ event.description }}
      {%- endif -%}
      {%- if event.location is defined %}
      Ort, {{ event.location }}
      {% endif -%}
    {% endif -%}  
  {%- endfor %}
{%- endif -%}
1 Like

I’m really at a loss for proper documentation, of how HA jinja2 works, seems very stupid to me, why not normal javascript. Whatever.

Start here:

I started reading that too.
This is yesterday’s version, which works with the ical HACS integration

action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.nest_esszimmer
      message: |-
        {% set tage = ["Montag",
          "Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"] %}

          {% for i in range(0, 9) %}
            {% if has_value('sensor.ical_tobi_event_' + i|string) %}
              {% if (((as_timestamp(state_attr('sensor.ical_tobi_event_' + i|string, "start"))) - (as_timestamp(now())) < 650) and
                ((as_timestamp(state_attr('sensor.ical_tobi_event_' + i|string, "start"))) - (as_timestamp(now())) > 0)) %}
                In 10 Minuten, am {{ tage[state_attr('sensor.ical_tobi_event_' + i|string, "start").weekday()] }}
                den {{ as_timestamp(state_attr('sensor.ical_tobi_event_' + i|string, "start")) | timestamp_custom ('%d/%m/%Y') }}
                um {{ as_timestamp(state_attr('sensor.ical_tobi_event_' + i|string, "start")) | timestamp_custom ('%H:%M %p') }}
                ist {{ state_attr('sensor.ical_tobi_event_' + i|string, "summary") }}
              {% endif %}
            {% endif %}
          {% endfor%}

Now that the service call provides a response is it possible to call the service from within jinja2.
i.e.

{% set agenda = service_call (calendar.list_events, calendar.birthday) %}

Obviously that’s not right, but something like that.

2 Likes