Automation for Alexa to read calendar

I’m trying to create an automation that will read the next calendar event (from a google calendar) and have Alexa speak it. I’ve reviewed the documentation for the calendar integration and have this so far.

service: calendar.list_events
data:
  duration:
    hours: 24
    minutes: 0
    seconds: 0
target:
  entity_id: calendar.public_school
response_variable: agenda

What I can’t figure out is how to get Alexa to speak the next notification. I’ve tried a bunch of things, but I can’t get it to work. I have several other automatons that include TTS and they work fine, but I can’t quite figure this one out.

What you have so far will store the data from the calendar in a variable agenda. That variable object will consist of a list named events which will contain any events that are currently happening as well as any that occur within the next 24 hours.

What do you want the notification to say? In order to help we need to know how you are defining “next calendar event” and what you want to happen if there isn’t a current event or one in the next 24 hours.

Thanks for the reply. The specific use case is as follows:

The calendar actually lists what is for lunch at school. I would like Alexa to speak the next days lunch menu at night. There is the issue that breakfast is also an event (my kids don’t eat breakfast at school), but I think I could figure that part out.

The call service for the above returns:

events:
  - start: "2023-11-06"
    end: "2023-11-07"
    summary: Breakfast - Breakfast Pizza/Cereal
  - start: "2023-11-06"
    end: "2023-11-07"
    summary: Lunch - Chicken Sandwich/Macaroni & Cheese
  - start: "2023-11-07"
    end: "2023-11-08"
    summary: Lunch - Pizza/Cheese Quesadilla
  - start: "2023-11-07"
    end: "2023-11-08"
    summary: Breakfast - Waffles/Cereal

I’d like for it just to speak the lunch for the next day.

You can use template filters to select just events that start tomorrow and contain the word “lunch”.

service: #whatever you use for tts
data:
  message: |
    Tomorrow's lunch will be {{ (agenda.events
    | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string )
    | selectattr('summary', 'search', 'lunch', ignorecase=1)
    | first).summary.replace('Lunch - ', '') }}

THANK YOU!! Works great.

1 Like