Google say next day calendar events

Hi, I’ve been all over documentation and forums to crack this one, but I’m stuck.

In a script, I want to test if calendar events are happening tomorrow, and if they are, get google to TTS them in a certain format as part of an evening notification.

My problem is the else-statement. I want google to tell me if there is nothing planned for tomorrow if none of the above ifs are true. How can I structure or wrap the statements to get the described outcome?

Thanks in advance!

{% if general.general test%}

  {% if is_state_attr('sensor.ical_shared_activities_event_0', 'eta' , 1 ) %}
  {{state_attr("sensor.ical_shared_activities_event_0", "summary") }} 
  {{as_timestamp(state_attr("sensor.ical_shared_activities_event_0", "start")) | timestamp_custom 
  ('%H:%M') }}
  {% endif %}

  {% if is_state_attr('sensor.ical_shared_activities_event_1', 'eta' , 1 ) %}
  {{state_attr("sensor.ical_shared_activities_event_1", "summary") }} 
  {{as_timestamp(state_attr("sensor.ical_shared_activities_event_1", "start")) | timestamp_custom 
  ('%H:%M') }}
  {% endif %}

  {% if is_state_attr('sensor.ical_shared_activities_event_2', 'eta' , 1 ) %}
  {{state_attr("sensor.ical_shared_activities_event_2", "summary") }} 
  {{as_timestamp(state_attr("sensor.ical_shared_activities_event_2", "start")) | timestamp_custom 
  ('%H:%M') }}
  {% endif %}

  {% if is_state_attr('sensor.ical_shared_activities_event_3', 'eta' , 1 ) %}
  {{state_attr("sensor.ical_shared_activities_event_3", "summary") }} 
  {{as_timestamp(state_attr("sensor.ical_shared_activities_event_3", "start")) | timestamp_custom 
  ('%H:%M') }}
  {% endif %}

  {% if is_state_attr('sensor.ical_shared_activities_event_4', 'eta' , 1 ) %}
  {{state_attr("sensor.ical_shared_activities_event_4", "summary") }} 
  {{as_timestamp(state_attr("sensor.ical_shared_activities_event_4", "start")) | timestamp_custom 
  ('%H:%M') }}
  {% endif %}

{% else %}
Nothing is happening tomorrow
{% endif %}

Anybody got any ideas?

Hi, did you ever figure this one out? I know how to show a message if the calendar is completely empty (between now and x number of hours) but I’m on here now to try to find out how to set filters for windows of time starting in the future such as tomorrow, etc. Do tell if you cracked it!

Be aware that this thread has been dead for 3 years.The Calendar Integration has undergone a massive rewrite since this thread was opened.

Calendar Automation Examples

Example using calendar.get_events to get tomorrows events

Forums threads about using the calendar.get_events service

1 Like

This is a script I made to notify me if I have events scheduled in the following morning (I set it to check for events between 7:45 am and 11:00 am). An automation calls the script the night before.

alias: Get Tomorrow Events
sequence:
  - service: input_text.set_value
    metadata: {}
    data:
      value: none
    target:
      entity_id:
        - input_text.nevents
        - input_text.morning_calendar_events
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: calendar.get_events
    target:
      entity_id: calendar.*******_gmail_com
    data:
      start_date_time: "{{ now().date() + timedelta(days=1) }} 07:45:00"
      end_date_time: "{{ now().date() + timedelta(days=1) }} 11:00:00"
    response_variable: agenda
  - variables:
      num_evts:
        value: >-
          {%- set ns = namespace(Y = 0 | int) %} {%- for evt in
          agenda['calendar.**********_gmail_com']['events'] %} 
          {%- endfor %}  {{ ns.Y }}
      event_text:
        value: >-
          {%- set nvs = namespace(X = '') %} {%- for evt in
          agenda['calendar.********_gmail_com']['events'] %} 
          {%- endfor %}  {{ nvs.X }}
  - service: input_text.set_value
    metadata: {}
    data_template: "{{ num_evts }}"
    target:
      entity_id: input_text.nevents
  - service: input_text.set_value
    metadata: {}
    data_template: "{{ event_text }}"
    target:
      entity_id: input_text.morning_calendar_events
  - if:
      - condition: template
        value_template: "{{ int(num_evts.value) > 0 }}"
        enabled: true
    then:
      - service: script.notify_*****
        metadata: {}
        data:
          msg_title: Morning Calendar
          msg_message: >-
            You have {{num_evts.value}} morning meetings:<br> {{
            event_text.value }}
        enabled: true
    else:
      - service: script.notify_*******
        metadata: {}
        data:
          msg_title: Nothing scheduled tomorrow.
          msg_message: Free Morning!
        enabled: true
mode: single
icon: mdi:calendar

1 Like

Oh wow, thanks for this. Scripts are the next frontier for me. I’ve made 600-800 line blueprints and also lots of automations in the automations.yaml but need to research how scripts work in Home Assistant more. I’m going to try to delve into what you just posted this weekend. Thanks again!

Scripts are basically the same as automations, but only the action part.
Actually it’s more the other way around, the action part of an automation is a script.