I really hate doing scripts, I haven’t found anything that I can do in a script without being able to just put it in the automation.
The following is how I got it to work.
alias: Update - input_text - sudo - Work Alarms
description: ""
trigger:
- platform: time_pattern
minutes: /10
enabled: false
condition: []
action:
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 0 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_sunday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 1 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_monday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 2 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_tuesday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 3 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_wednesday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 4 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_thursday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 5 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_friday
- service: calendar.get_events
metadata: {}
data:
start_date_time: >
{% set next_dow = 6 %} {% set delta_days = 6 - now().weekday() +
next_dow %} {{ (now() + timedelta(days = delta_days)).date() | string +
" 00:00:00" }}
duration:
hours: 24
target:
entity_id: calendar.w2w_schedule
response_variable: day_events
- service: input_text.set_value
metadata: {}
data:
value: |
{% for event in day_events['calendar.w2w_schedule']['events'] %}
{{ event.start }}
{% endfor %}
target:
entity_id: input_text.sudo_work_saturday
- parallel:
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Sunday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:1:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_sunday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_sunday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Monday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:2:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_monday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_monday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Tuesday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:3:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_tuesday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_tuesday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Wednesday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:4:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_wednesday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_wednesday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Thursday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:5:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_thursday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_thursday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Friday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:6:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_friday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_friday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
- service: notify.mobile_app_pro23_ultra
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set messagetext = message | default('Saturday Wake Up') %}
android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.SKIP_UI:true,android.intent.extra.alarm.MESSAGE:{{
messagetext
}},android.intent.extra.alarm.DAYS:7:ArrayList<Integer>,android.intent.extra.alarm.HOUR:{{
as_timestamp(as_datetime(states.input_text.sudo_work_saturday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%H", true)
}},android.intent.extra.alarm.MINUTES:{{
as_timestamp(as_datetime(states.input_text.sudo_work_saturday.state)
- timedelta(hours=1,minutes=45)) | timestamp_custom("%M", true) }}
mode: single
I have one kink to work out though, how to delete alarms. I have tried to dismiss as per Set Android alarm clock from Home Assistant - #90 by zynth, but this just opens the Samsung Clock. I’d like to be able to delete alarms in my automation because my schedule can change and this way would allow for that. I am using Sleep As Android.