Google Calendar to Voice

Hi,
I am very new to Home Assistant and YAML so I need help and ChatGPT didn’t help. xD

I have a boolean helper named “Sleep”
When I turn off “Sleep” I want to start an automation which lets my Home Assistant Voice read out my appointmets for today from my Google Calendar.

I think in the “easy” automation tool it’s not possible to do this so can someone help with a quick YAML script?

Kindest regards
Brian

This is do-able in the graphic Automation Editor, but the notification step will require some templating.

You will need to use the calendar.get_events action. There is an explanation of the action as well example of using the response at the bottom of the following page:

Hi, thanks for your help.
It kinda works now. It reads out the appointments and speaks with me.
But another problem came up.
It doesn’t form a real sentence but some data jibberish which contains what I want to know.

Why is that and how can i fix that?

Post the automation YAML or download and share the debug trace’s .json file so we can see how your automation is designed and what is failing.

I have this Script

say the next 5 days of my calendar events

script_playing:
  alias: Speak My Shift Pattem
  sequence:
  - action: calendar.get_events
    metadata: {}
    data:
      end_date_time: '{{ now().date() + timedelta(days=5) }} 03:01:00 '
    target:
      entity_id: calendar.stephan_shift
    response_variable: agenda
  - action: tts.speak
    metadata: {}
    data:
      cache: false
      media_player_entity_id: media_player.cuckoo_clock
      message: '{% for event in agenda["calendar.stephan_shift"]["events"] %} {{ event.summary
        }},  starts on {{ as_datetime(event.start | string).strftime(''%A %-d %B'')
        }}.

        {% endfor %}

now you could just call the script in side an automation.

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
    - input_boolean.sleep
   to: "on"

conditions: []
actions:
  - action: script.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: script.script_playing

yes you could put it in to one

alias: test 3
description: “”
triggers:

  • trigger: state
    entity_id:
    • input_boolean.sleep
      to: “off”
      conditions:
      actions:
  • action: calendar.get_events
    metadata: {}
    data:
    duration:
    hours: 24
    target:
    entity_id: calendar.my_calendar
    response_variable: appointments
  • action: tts.speak
    metadata: {}
    data:
    cache: true
    media_player_entity_id: media_player.home_assistant_voice_095b2a_media_player
    message: >-
    Appointments for today {% for event in
    appointments[“calendar.my_calendar”][“events”] %} {{ event.start}}
    {{ event.summary }}
    {% endfor %}
    target:
    entity_id: tts.home_assistant_cloud
    mode: single

Is the “gibberish” just it reading out the datetime string?

If you let us know how you want it to relay the time information, we can probably help you finesse the template to get the correct output. For example, do you want hours as 24hr or 12hr with AM/PM?

Yes, sounds like it.
But not like
“Appointments for today: football at 3PM”
but like
“Appointments for today: …” and then year, month, date and time but all in single digits with some additional zeros and the word football in between.

And my goal is for it to read the appointments for today with their starting time in an easy to understand sentence.

Ok, you’ll need to adjust the message template:

Appointments for today 
{% for event in appointments["calendar.my_calendar"]["events"] %}
  {{- (event.start|as_datetime|as_local).strftime("%H:%M") }}: {{ event.summary }},
{% endfor %}

EDIT: Updated to 24hr

Ah, my bad. The AM/PM part is not really needed. I am from Germany and we use the 24 hour system.
I will try it out tomorrow.
Thanks for your help so far! :slight_smile:

Works well, thank you. :slight_smile:
Still don’t know why but YAML understanding comes with time I hope. :smiley: