Count events and tasks in local calendar

Hi all.

first of all, please be gently with me - cause im pretty new to this HA

How do i count and display number of events in local calendar in a template

can someone please help me with this?
I just want to display a number on how many events and tasks for today…
So i can use it in a notification on my mobile.
“You have 3 events and 2 task in your calendar today”…

i have search the web, but can’t find anything that does this for me…

best regards…

There’s no easy way to get this information into a template sensor currently. You can get this information in a notification without a template sensor.

calendar_events_today:
  alias: Calendar Events Today
  sequence:

  - service: calendar.list_events
    target:
      entity_id: "{{ calendar }}"
    data:
      start_date_time: "{{ today_at() }}"
      end_date_time: "{{ today_at() + timedelta(days=1) }}"
    response_variable: agenda

  - service: notify.your_mobile_device
    data:
      message: You have {{ agenda.events | count }} events in {{ state_attr(calendar, 'friendly_name') }} today

Then you can use this script anywhere

service: script.calendar_events_today
data:
  calendar: calendar.abc

Thank you so much, Mister.

It works like a charm :slight_smile:
Once again, thank you :slight_smile:

Apologies for bringing up an old thread, but I’m trying to do the same, but I’m struggling with the first block of code… is that an automation or a script?
I’ve added the code to both of those but when I run the second block of code as a script, I keep getting “UndefinedError: ‘calander’ is undefined”.
I’ve also tried to rename instances of calander to my local calander entity, but with the same ressult. :frowning:
I’d appreciate any additional guidance that you could provide.
Thanks in advance!

Script

The word calendar was misspelled as “calander”.

Thanks Taras for the response - got it working!

Hello everyone,

Sorry to dig up an old topic, but when I try the code you gave @petro , it throws an error : Message malformed: extra keys not allowed @ data[‘calendar_events_today’]

I must be missing something, but I can’t tell what… any idea ?

You put it in the script section of your configuration.yaml.