Help creating a template sensor for the next event in the local calendar

Hello guys,

I wonder if you could help me, ive been searching around but can’t find anything to even begin to work out how to achieve this.

Im looking to set up a template sensor for a local calendar I have created called “Social” I would like the sensor to pull the name of the next event in the calendar and store it as the state, and I would like the date of the event stored as an attribute called “Event Date”

I would be most grateful for any help you could offer.


Have you looked at the home feed card from HACS?

Thanks for the reply, im not looking for a card. I need the information in a template as I want to use it in a button and markdown card, thanks anyway

1 Like

You will need to use a trigger-based template sensor that includes the calendar.get_events service.

At a minimum, you will want to use a Calendar trigger, but you may want to include additional triggers to cover cases like when events are added to the calendar or HA restarts.

I believe what you want is what I have here:

trigger off the calendar event (albeit in an automation, but you could also do that in a trigger based template like Didgeridrew suggests), and then store that value in an input_text

do some more stuff, even create a todo item and notification

  - id: create_todo_from_afvalwijzer_calendar
      - platform: calendar
        entity_id: calendar.afvalwijzer
        event: start
        offset: -06:00:00
      - platform: calendar
        entity_id: calendar.afvalwijzer
        event: start
        offset: 07:00:00
    condition: []
      - service: input_text.set_value
          entity_id: input_text.todo_afvalwijzer
          value: >
      - service: todo.add_item
          entity_id: todo.huishouden
          item: &item
              Saver: {{trigger.calendar_event.description}}
          description: &description
             Opgelet: {{trigger.calendar_event.description}} aan de straat zetten.
          due_date: &moment

      - service: notify.mobile_app_marijn
          title: *item
          message: *description

your template could be done based on the newly set input_text, or use that directly even in a markdown card, without even having to create the template sensor at all