Morning Routine Automation: Announcing Weather & Appointments via OpenAI and Speaker

Hey everyone!

I’ve set up a morning routine automation that triggers when my alarm goes off and a motion sensor detects movement. Now, I want to take it a step further:

:loudspeaker: My goal: My smart speaker should use OpenAI to announce the current weather and my appointments for today and tomorrow.

I’ve already tried and researched quite a bit, but so far without success. So my questions are:

:point_right: Is this even possible?
:point_right: If yes, how could I set this up?

Looking forward to your tips and experiences! :blush:

Maybe this can help you started:

Yes it’s possible. My approach was to create a template button that announces today’s events whenever it is pressed. This way I can manually trigger it from the UI or press the button in an automation or script.

- button:
    - name: "Announce Calendar Events Jason"
      unique_id: announce_calendar_events_jason
      icon: mdi:account-voice
      press:
        - action: calendar.get_events
          target:
            entity_id: calendar.jazzyisj
          data:
            duration:
              days: 2
          response_variable: agenda

        - variables:
            events: "{{ agenda['calendar.jazzyisj']['events'] }}"
            message: |
              {%- from 'schedule.jinja' import list_events %}
              Good {{ states('sensor.tod_greeting') }}!
              {%- if events | count > 0 %}
              Here are your upcoming calendar events.
              {{ list_events(events) }}
              {%- else %}
              There are no events on your calendar today!
              {%- endif -%}

        - action: script.tts_play
          data:
            media_player: media_player.inside_speakers
            min_volume: 50
            provider: "HASS"
            language: "English (Ireland)"
            voice: "Emily"
            always_play: true
            save_message: false
            message: "{{ message }}"

Hey mega! Thank you very much. However, I don’t understand what kind of sensor this is “sensor.tod_greeting”. You are also running a script (script.tts_play) Could you tell me what your settings are? Thank you very much :heart:

My config here was just an example to show you one way of tackling the issue in your system. It needs to be modified to fit your needs. But here is my TOD (time of day) greeting template sensor which you may find useful. My script.tts_play should be replaced with your own TTS action call.

What you really needed was my custom template list_events() and I forgot to link that!

BTW, I am obviously am not using OpenAI to do this.
If that’s what you really want, this won’t help you.

{%- macro list_events(events) -%}
{%- for event in events %}
  {%- if (event.start is defined) %}
    {%- if (event.start | as_datetime).day == now().day %}
      {{ event.start | as_timestamp | timestamp_custom('Today at %-I:%M %p') }}: {% if event.summary is defined %}{{ event.summary }}{% endif %}
    {%- else %}
      {{ event.start | as_timestamp | timestamp_custom('%A at %-I:%M %p') }}: {% if event.summary is defined %}{{ event.summary }}{% endif %}
    {%- endif %}
  {%- else %}{% if event.summary is defined %}{{ event.summary }}{% endif %}
  {%- endif %}
{%- endfor %}.
{%- endmacro -%}