Calendar service call response into markdown card

image

I was looking for a template that would show the next 50 days worth of events using the new service call return ability from my internal birthday calendar, and the next 50 days worth of events from my anniversary calendar. Format and show these events in a markdown card(s) in lovelace.
Most of this was generated by the UI, but here is the YAML for brevity. Hopefully this shortcuts your project needs! It is an automation that runs 3:00 am and fills two text helpers (BirthList and AnnList).

alias: Birthday Text
description: Build the birthday text to list next 6 weeks of BD
trigger:
  - platform: time
    at: "03:00:00"
condition: []
action:
  - service: calendar.list_events
    data:
      duration:
        hours: 1200
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.birthdays
    response_variable: BirthCal
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in BirthCal.events %}{{event.start[5:]}} {{ event.summary
        }}{{'\n'}} {% endfor %}
    target:
      entity_id: input_text.birthlist
  - service: calendar.list_events
    data:
      duration:
        hours: 1200
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.anniversary
    response_variable: AnnCal
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in AnnCal.events %}{{event.start[5:]}} {{ event.summary
        }}{{'\n'}} {% endfor %}
    target:
      entity_id: input_text.annlist
mode: single

In the markdown card use:

**----Birthdays----**
{{states('input_text.birthlist')}}
2 Likes

Tried implementing your automation but get the following error, any idea what’s wrong?

“Message malformed: extra keys not allowed @ data[‘action’][0][‘response_variable’]”

alias: List Calendar Events
description: List Calendar Events
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: calendar.list_events
    target:
      entity_id: calendar.gmail
    data:
      duration:
        hours: 24
    response_variable: agenda

Sorry, just saw this: I am not seeing where your template is… my whole script is in an automation. I have since done a minor change in that I am now feeding just one text helper that can then display in a card. doing and ‘edit yaml’ in the automation yeilds this:

alias: Birthday Text
description: Build the birthday text to list next 6 weeks of BD
trigger:
  - platform: time
    at: "03:00:00"
condition: []
action:
  - service: calendar.list_events
    data:
      duration:
        hours: 1200
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.birthdays
    response_variable: BirthCal
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in BirthCal.events %}{{event.start[5:]}} {{ event.summary
        }}{{'\n'}} {% endfor %}
    target:
      entity_id: input_text.birthlist
  - service: calendar.list_events
    data:
      duration:
        hours: 1200
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.anniversary
    response_variable: AnnCal
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in AnnCal.events %}{{event.start[5:]}} {{ event.summary
        }}{{'\n'}} {% endfor %}
    target:
      entity_id: input_text.annlist
  - service: ""
    data: {}
mode: single

This is the same automation, using the new Calendar service: outputs to two text helpers that I display on the first page of lovelace to remind me of anniversaries and birthdays for the next 60 days.

alias: Birthday2
description: ""
trigger:
  - platform: time
    at: "00:00:00"
    enabled: true
condition: []
action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.birthdays
        - calendar.anniversary
    data:
      duration:
        days: 60
    response_variable: testy
  - service: input_text.set_value
    target:
      entity_id: input_text.birthlist
    data:
      value: >-
        {% for event in testy["calendar.birthdays"]["events"] %}{{
        event.start[5:]}}: {{event.summary }}{{'\n'}} {% endfor %}
  - service: input_text.set_value
    target:
      entity_id: input_text.annlist
    data:
      value: >-
        {% for event in testy["calendar.anniversary"]["events"] %}{{
        event.start[5:]}}: {{event.summary }}{{'\n'}} {% endfor %}
    enabled: true
mode: single

Hey Michael,

I’m trying to implement your automation but instead of displaying the events title (or summary) I’d like to show the description field of the event.
Trying to adjust the {{event.summary }} bit of the script to {{event.description }} gives back a “unknown” value to the text input.

Any ideas what I’m doing wrong?

EDIT: I’m already using your new automation with the new calendar service.

EDIT 2: figured out that my description is longer than 255 characters so the text helper cannot save it as character limit on all entity states is 255.

How do you get properly formatted date in markdown card? I made exact copy/paste of configuration to create list of my garbage collection and using jsut {{states('input_text.bio')}} I got just timestamps, instead of properly formatted dates:

04-17T00:00:00+02:00: Bio
05-02T00:00:00+02:00: Bio
04-26T00:15:00+02:00: Paper
04-12T00:15:00+02:00: Plastic
04-24T00:15:00+02:00: Glass
04-05T00:15:00+02:00: Mixed
04-19T00:15:00+02:00: Mixed
05-03T00:15:00+02:00: Mixed

I found the text helper is limited to 255 characters. so I limited the number of days ahead from 60 to 35 to accommodate periods of ‘intense’ birthdays… Another way to accommodate would be to have a text helper for each smaller period (a week, a month) and show them together in Lovelace

The following code shows the formatting of the month/day with {{event.start[5:]}}

This code also puts the word TODAY underlined in the text to highlight that ‘today is the day’ something is happening…

alias: Birthday2
description: ""
trigger:
  - platform: time
    at: "00:00:00"
    enabled: true
condition: []
action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.birthdays
        - calendar.anniversary
    data:
      duration:
        days: 40
    response_variable: testy
  - service: input_text.set_value
    target:
      entity_id: input_text.birthlist
    data:
      value: >-
        {% for event in testy["calendar.birthdays"]["events"] %}{{
        event.start[5:]}}: {{iif(now().strftime('%m-%d')==event.start[5:],'
        <u>**TODAY**</u> ','')}}{{event.summary }}{{'\n'}} {% endfor %}
  - service: input_text.set_value
    target:
      entity_id: input_text.annlist
    data:
      value: >-
        {% for event in testy["calendar.anniversary"]["events"] %}{{
        event.start[5:]}}: {{iif(now().strftime('%m-%d')==event.start[5:],'
        <u>**TODAY**</u> ','')}}{{event.summary }}{{'\n'}} {% endfor %}
    enabled: true
mode: single