Speaking list of calendar events from template

Hey all, templates seem to intimidate me and I can’t quite get my head wrapped around them. I have a template that is spoken on a speaker in the morning, giving me a daily rundown of the weather and calendar events. The problem is the calendar and todo events have never worked. The weather is now also broken due to a change in the way it gets reported, which is what spurred me to get this working right. That part I’m confident I can fix, but the calendar has eluded me for quite some time. I’ve tried multiple variations and followed multiple guides, but that section of the template is completely skipped. Could anyone tell me what I’m doing wrong here? Thank you in advance!

(Also, I didn’t see a category for “help”, if there is one and I missed it please let me know/feel free to move it)

alias: Announce Morning Overview on the Bathroom Sonos
trigger:
  - platform: state
    entity_id:
      - binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone_2
    to: "on"
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.75
    enabled: true
    target:
      device_id: [redacted]
  - service: calendar.get_events
    target:
      entity_id: calendar.personal_2
    data:
      duration:
        hours: 24
    response_variable: agenda
  - service: todo.get_items
    target:
      entity_id: todo.reminders
    data:
      status: needs_action
    response_variable: reminders
  - service: chime_tts.say
    data:
      chime_path: mp3_path_placeholder-whistle
      end_chime_path: ""
      delay: 450
      final_delay: 450
      tts_playback_speed: 100
      tts_platform: tts.piper
      message: >-
        Good morning! Here's a look at your day, {% for event in agenda.events
        %} You have an event titled {{ event.summary }}. {% endfor %} {% for
        task in reminders.task %} You have a reminder titled {{ task.summary }}.
        {% endfor %} Conditions are {{ states('weather.forecast_home') }}
        outside. The temperature is {{ state_attr('weather.kcmi_daynight',
        'temperature')  }} degrees, with a humidity of {{
        state_attr('weather.kcmi_daynight',       'humidity') }} percent. It
        should feel {{ states('sensor.relative_temperature_outdoor') }} outside.
        The high for today will be {{ state_attr('weather.forecast_home',
        'high') }}.
      volume_level: 0.75
      announce: true
      join_players: true
      unjoin_players: true
    target:
      entity_id: media_player.bathroom_sonos
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone_2
        to: "off"
        for:
          hours: 1
          minutes: 0
          seconds: 0
    continue_on_timeout: false
    enabled: true
mode: single

1 Like

I was able to copy a snippet of EverythingSmartHome’s video, and got this working! I have the automation set to “single” with a “wait for trigger” that waits for the bathroom motion sensor to be clear for an hour. This is to prevent it from making the announcement every time you go into the bathroom in the morning. Here’s my almost-complete (fill in the weather entities) automation yaml (at least, the “actions” part):

  - service: calendar.get_events
    target:
      entity_id: calendar.personal_2
    data:
      duration:
        hours: 24
    response_variable: agenda
  - service: todo.get_items
    target:
      entity_id: todo.reminders
    data:
      status: needs_action
    response_variable: reminders
  - service: chime_tts.say
    data:
      chime_path: mp3_path_placeholder-whistle
      end_chime_path: ""
      delay: 450
      final_delay: 450
      tts_playback_speed: 100
      tts_platform: tts.piper
      message: >-
        Good morning! Here's a look at your day...

        {% set list_length = reminders | count %} {% set ns = namespace(i = 0)
        %} {%- if reminders["todo.reminders"]["items"] %}
          You have the following active reminders...
          {% for item in reminders["todo.reminders"]["items"] %}
            {% if ns.i < list_length %}
              {{ item.summary }}
              {% set ns.i = ns.i + 1 %}
            {% else %}
              {{ item.summary }},
            {% endif %}
          {% endfor %}
        {% else %}
          You don't have any active reminders today!
        {% endif %}

        {% set list_length = agenda | count %} {% set nsa = namespace(i = 0) %}
        {%- if agenda["calendar.personal_2"]["events"] %}
          You have the following events scheduled today...
          {% for item in agenda["calendar.personal_2"]["events"] %}
            {% if nsa.i < list_length %}
              {{ item.summary }}
              {% set nsa.i = nsa.i + 1 %}
            {% else %}
               {{ item.summary }},
            {% endif %}
          {% endfor %}
        {% else %}
          You don't have any events today!
        {% endif %}

        Conditions are {{ states('weather.forecast_home') }} outside. The
        temperature is {{ state_attr('weather.****', 'temperature')  }}
        degrees, with a humidity of {{ state_attr('weather.****',      
        'humidity') }} percent. It should feel {{
        states('sensor.relative_temperature_outdoor') }} outside. The high for
        today will be {{ state_attr('weather.forecast_home',
        'forecast')[0].temperature }}.
      volume_level: 0.75
      announce: true
      join_players: true
      unjoin_players: true
    target:
      entity_id: media_player.bathroom_sonos