The new’ish Calendar Integration looks exciting but I don’t quite have a solid grasp on how to leverage it best. I am looking for guidance on a use-case which currently seems a little convoluted in execution and perhaps could leverage the new integration.
Requirement
Set a phone alarm tomorrow based on the following requirements;
- there is a meeting scheduled that starts on or after 8AM
- this alarm should be set the night before
Conditions
- I am set as required in the attendees
- it is a workday
Actions
- set the alarm 90 minutes prior to the meeting
The Challenge
I see that the Calendar Integration allows one to leverage trigger.calendar_event
but I am unclear how I would parse this compared to current template (below).
What I use today.
The below template sensor works to output the time tomorrow that is 90 minutes before the first call. It works. It just doesn’t seem like the best approach.
- name: "tomorrow_first_meeting_start"
unique_id: tomorrow_first_meeting_start
state: >-
{% set data = namespace(entities=[]) %}
{% set today_sec = 86400 %}
{% set eightAM_sec = 28800 %}
{% set fourtyEightHours_sec = 172800 %}
{% set tomorrowEightAM_sec = 115200 %}
{% for meeting in state_attr('calendar.calendar_me','data') %}
{% set meeting_start = as_timestamp( meeting.start ) - as_timestamp(now().date()) %}
{% if meeting_start > today_sec and meeting_start < fourtyEightHours_sec and
meeting_start >= tomorrowEightAM_sec %}
{% set data.entities = data.entities + [meeting] %}
{% endif %}
{% endfor%}
{% set tomorrow_meetings = namespace(entities=[]) %}
{% for entry in data.entities %}
{% for email in entry.attendees %}
{% if email.email == '[email protected]' and email.type == 'required' %}
{% set tomorrow_meetings.entities = data.entities + [entry] %}
{% endif %}
{% endfor %}
{% endfor %}
{{ (as_timestamp(tomorrow_meetings.entities[0].start) - 5400) | timestamp_custom ('%H%M') }}
Here is the automation that consumes it;
- id: '1655406948412'
alias: '[ALARM] Set work alarm tomorrow'
description: ''
trigger:
- platform: time
at: '23:00:00'
condition:
- condition: time
before: '23:05:00'
after: '22:59:00'
weekday:
- mon
- tue
- wed
- thu
- sun
action:
- if:
- condition: template
value_template: '{{ is_state(''binary_sensor.workday_tomorrow'',''on'') }}'
then:
- service: notify.mobile_app_pixel_4a
data:
message: command_activity
data:
channel: com.google.android.deskclock
tag: android.intent.action.DISMISS_ALARM
group: android.intent.extra.alarm.SEARCH_MODE:android.label,android.intent.extra.alarm.MESSAGE:Home
Assistant Alarm
- service: notify.mobile_app_pixel_4a
data:
message: command_activity
data:
channel: com.google.android.deskclock
tag: android.intent.action.SET_ALARM
group: android.intent.extra.alarm.HOUR:{{states('sensor.tomorrow_first_meeting_start')[1:-2]}},android.intent.extra.alarm.MINUTES:{{states('sensor.tomorrow_first_meeting_start')[2:]}},android.intent.extra.alarm.MESSAGE:Home
Assistant Alarm,android.intent.extra.alarm.SKIP_UI:true
else:
- service: notify.mobile_app_pixel_4a
data:
message: command_activity
data:
channel: com.google.android.deskclock
tag: android.intent.action.DISMISS_ALARM
group: android.intent.extra.alarm.SEARCH_MODE:android.label,android.intent.extra.alarm.MESSAGE:Home
Assistant Alarm
mode: single
Your thoughts on making this consumable via the Calendar Integration?
[edit] spelling/clarity