Files
Home-Assistant-Configs/packages/scheduling.yaml

759 lines
28 KiB
YAML

input_datetime:
good_morning:
name: Good Morning
has_date: false
has_time: true
icon: mdi:weather-sunset-up
good_night_routine:
name: Good Night Routine
has_date: false
has_time: true
icon: mdi:weather-night
input_boolean:
# Turned on when scheduling automations run, reset at midnight
# This tracks whether scheduling has already been run, to be used as conditions in automations/scripts
work_today_ran:
name: Work Today Ran
icon: mdi:clock-outline
school_today_ran:
name: School Today Ran
icon: mdi:clock-outline
kallen_scheduling_morning_ran:
name: Kallen Scheduling Morning Ran
icon: mdi:clock-outline
kallen_scheduling_evening_ran:
name: Kallen Scheduling Evening Ran
icon: mdi:clock-outline
house_scheduling_morning_ran:
name: House Scheduling Morning Ran
icon: mdi:clock-outline
house_scheduling_evening_ran:
name: House Scheduling Evening Ran
icon: mdi:clock-outline
emma_scheduling_morning_ran:
name: Emma Scheduling Morning Ran
icon: mdi:clock-outline
emma_scheduling_evening_ran:
name: Emma Scheduling Evening Ran
icon: mdi:clock-outline
master_bedroom_scheduling_morning_ran:
name: Master Bedroom Scheduling Morning Ran
icon: mdi:clock-outline
master_bedroom_scheduling_evening_ran:
name: Master Bedroom Scheduling Evening Ran
icon: mdi:clock-outline
# Overrides
# These will prevent certain schedules from being modified by the scripts, in case you want to set them yourself
kallen_wakeup_override:
name: Kallen Wakeup Override
icon: mdi:plus-circle-outline
kallen_bedtime_override:
name: Kallen Bedtime Override
icon: mdi:plus-circle-outline
emma_wakeup_override:
name: Emma Wakeup Override
icon: mdi:plus-circle-outline
emma_bedtime_override:
name: Emma Bedtime Override
icon: mdi:plus-circle-outline
master_bedroom_wakeup_override:
name: Master Bedroom Wakeup Override
icon: mdi:plus-circle-outline
tina_work_schedule_override:
name: Tina Work Schedule Override
icon: mdi:plus-circle-outline
house_briefing_times_override:
name: House Briefing Times Override
icon: mdi:plus-circle-outline
kallen_briefing_times_override:
name: Kallen Briefing Times Override
icon: mdi:plus-circle-outline
master_bedroom_climate_override:
name: Master Bedroom Climate Override
icon: mdi:plus-circle-outline
kallen_bedroom_climate_override:
name: Kallen Bedroom Climate Override
icon: mdi:plus-circle-outline
emma_bedroom_climate_override:
name: Emma Bedroom Climate Override
icon: mdi:plus-circle-outline
################################################
# Current order of operations is as follows: #
# #
# Morning: #
# - Work Today #
# - School Today #
# - Kallen Scheduling #
# - House Scheduling #
# - Emma Bedroom Scheduling #
# - Master Bedroom Scheduling #
# #
# Evening: #
# - Kallen Scheduling #
# - House Scheduling #
# - Master Bedroom Scheduling #
# - Emma Bedroom Scheduling #
################################################
automation:
- id: c772b54d-6448-4d74-a0c2-32998f49b17c
alias: Kallen Scheduling
trigger:
- platform: time
at: '04:01:00'
id: kallen-morning
- platform: time
at: '16:00:00'
id: kallen-evening
action:
- if:
- condition: trigger
id: kallen-morning
then:
- service: script.kallen_scheduling_morning
- if:
- condition: trigger
id: kallen-evening
then:
- service: script.kallen_scheduling_evening
- id: 1c9f7e4b-2d5a-4b95-bd80-d9aa2244a6db
alias: House Scheduling
trigger:
- platform: time
at: '04:01:10'
id: house-morning
- platform: time
at: '16:00:10'
id: house-evening
action:
- if:
- condition: trigger
id: house-morning
then:
- service: script.house_scheduling_morning
- service: script.security_scheduling
- if:
- condition: trigger
id: house-evening
then:
- service: script.house_scheduling_evening
- id: 89470712-f94d-4c01-8215-ed15b3bc799a
alias: Master Bedroom Scheduling
trigger:
- platform: time
at: '04:02:00'
id: mrbedroom-morning
- platform: time
at: '16:00:20'
id: mrbedroom-evening
action:
- if:
- condition: trigger
id: mrbedroom-morning
then:
- service: script.master_bedroom_scheduling_morning
- if:
- condition: trigger
id: mrbedroom-evening
then:
- service: script.master_bedroom_scheduling_evening
- id: a69d3d36-09d6-4ef3-a245-c564c7cb577c
alias: Emma Bedroom Scheduling
trigger:
- platform: time
at: '04:02:10'
id: emma-morning
- platform: time
at: '16:00:30'
id: emma-evening
action:
- if:
- condition: trigger
id: emma-morning
then:
- service: script.emma_bedroom_scheduling_morning
- if:
- condition: trigger
id: emma-evening
then:
- service: script.emma_bedroom_scheduling_evening
- id: 7350300d-94d3-4ea3-97bb-b0673eafd71f
alias: Scheduling Reset
description: "Reset all 'Briefing Ran' input booleans for the next day"
trigger:
- platform: time
at: "00:00:00"
action:
- service: script.scheduling_reset
script:
kallen_scheduling_morning:
alias: 'Kallen Scheduling Morning'
sequence:
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_school_day_start
data:
time: >
{% from 'time.jinja' import set_time_from_calendar %}
{% if is_state('input_boolean.two_hour_delay','on') %}
11:00
{% else %}
{{ set_time_from_calendar('calendar.kallen_school_days','start_time') }}
{% endif %}
- delay:
seconds: 1
- if:
- condition: state
entity_id: input_boolean.kallen_wakeup_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_wakeup_time
data:
time: >
{% if is_state('input_boolean.kallen_school_today', 'on') %}
{% if is_state('input_boolean.two_hour_delay','on') %}
09:30
{% else %}
{{ (state_attr('input_datetime.kallen_school_day_start','timestamp') - 5400) | timestamp_custom('%H:%M', false) }}
{% endif %}
{% else %}
10:00
{% endif %}
- service: input_select.select_option
target:
entity_id: input_select.kallen_morning_briefing_location
data:
option: >
{% if is_state('input_boolean.kallen_school_today','on') %}
{% if is_state('input_boolean.two_hour_delay','on') %}
Common Areas
{% else %}
Kallen Bedroom
{% endif %}
{% else %}
Common Areas
{% endif %}
- if:
- condition: state
entity_id: input_boolean.kallen_briefing_times_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_morning_briefing
data:
time: >
{% if is_state('input_boolean.kallen_school_today', 'on') %}
{% if is_state('input_boolean.two_hour_delay','on') %}
09:40
{% else %}
{{ (state_attr('input_datetime.kallen_school_day_start','timestamp') - 4800) | timestamp_custom('%H:%M', false) }}
{% endif %}
{% else %}
10:00
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_school_day_start_reminder
data:
time: >
{% if is_state('input_boolean.two_hour_delay','on') %}
10:00
{% else %}
{{ (state_attr('input_datetime.kallen_school_day_start','timestamp') - 3600) | timestamp_custom('%H:%M', false) }}
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_school_day_end_reminder
data:
time: >
{% if is_state('input_boolean.kallen_school_early_release','on') %}
13:30
{% else %}
14:00
{% endif %}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.kallen_scheduling_morning_ran
kallen_scheduling_evening:
alias: 'Kallen Scheduling Evening'
sequence:
- if:
- condition: state
entity_id: input_boolean.kallen_bedtime_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_bedtime
data:
time: >
{% if is_state('binary_sensor.kallen_school_tomorrow', 'on') %}
21:00
{% else %}
22:00
{% endif %}
- delay:
seconds: 1
- variables:
bedtime: "{{ state_attr('input_datetime.kallen_bedtime','timestamp') }}"
low: "{{ states('sensor.overnight_lowest_temperature') | int }}"
threshold: "{{ states('input_number.kallen_fan_threshold') | int }}"
- if:
- condition: state
entity_id: input_boolean.kallen_briefing_times_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.kallen_nightly_briefing
data:
time: "{{ (bedtime - 1200) | timestamp_custom('%H:%M', false) }}"
- if:
- condition: state
entity_id: input_boolean.kallen_bedroom_climate_override
state: 'off'
then:
- service: input_select.select_option
target:
entity_id: input_select.scheduled_climate_mode_kallen_fan
data:
option: >
{% if is_state('input_boolean.kallen_overnight','on') %}
N/A
{% elif low >= threshold %}
Fan
{% else %}
White Noise
{% endif %}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.kallen_fan
data:
time: >
{% if is_state('input_boolean.hot_day','on') %}
{{ bedtime - 3600 | timestamp_custom('%H:%M', false) }}
{% else %}
{{ bedtime | timestamp_custom('%H:%M', false) }}
{% endif %}
- if:
- condition: state
entity_id: input_boolean.kallen_late_bedtime
state: 'on'
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.kallen_bedtime
data:
time: "{{ bedtime + 3600 | timestamp_custom('%H:%M', false) }}"
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.kallen_nightly_briefing
data:
time: "{{ (state_attr('input_datetime.kallen_nightly_briefing','timestamp') + 3600) | timestamp_custom('%H:%M', false) }}"
- if:
- condition: state
entity_id: input_boolean.kallen_bedroom_climate_override
state: 'off'
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.kallen_fan
data:
time: "{{ (state_attr('input_datetime.kallen_fan','timestamp') + 3600) | timestamp_custom('%H:%M', false) }}"
- service: input_boolean.turn_on
target:
entity_id: input_boolean.kallen_scheduling_evening_ran
house_scheduling_morning:
alias: 'House Scheduling Morning'
sequence:
- variables:
kallen_school_start: "{{ state_attr('input_datetime.kallen_school_day_start','timestamp') }}"
tina_work_start: "{{ state_attr('input_datetime.tina_workday_start','timestamp') }}"
tina_work_end: "{{ state_attr('input_datetime.tina_workday_end','timestamp') }}"
high: "{{ states('sensor.todays_high_temp') | int }}"
- service: input_datetime.set_datetime
entity_id: input_datetime.audible_notification_on
data:
time: >
{% if is_state('input_boolean.kallen_school_today','on') %}
{{ kallen_school_start - 5400 | timestamp_custom('%H:%M', false) }}
{% else %}
09:00
{% endif %}
- variables:
audible_on: "{{ state_attr('input_datetime.audible_notification_on','timestamp') }}"
- if:
- condition: state
entity_id: input_boolean.house_briefing_times_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.morning_briefing
data:
time: >
{% if is_state('input_boolean.kallen_school_today','on') %}
{% if is_state('input_boolean.two_hour_delay','on') %}
10:20
{% else %}
{{ kallen_school_start - 2400 | timestamp_custom('%H:%M', false) }}
{% endif %}
{% elif is_state('input_boolean.work_today','on') and is_state('input_boolean.kallen_school_today','off') %}
{% if tina_work_start > 43200 %}
12:00
{% elif (tina_work_start - 1500) > audible_on %}
{{ tina_work_start - 1500 | timestamp_custom('%H:%M', false) }}
{% else %}
10:00
{% endif %}
{% else %}
12:00
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.daily_briefing
data:
time: >
{% if is_state('input_boolean.kallen_school_today','on') %}
{% if is_state('input_boolean.kallen_school_early_release','on') %}
13:15
{% else %}
14:15
{% endif %}
{% elif is_state('input_boolean.kallen_school_today','off') and is_state('input_boolean.work_today','off') %}
15:00
{% else %}
{% if tina_work_end > 61200 %}
16:00
{% else %}
{{ tina_work_end + 3600 | timestamp_custom('%H:%M', false) }}
{% endif %}
{% endif %}
- if:
- condition: template
value_template: "{{ high >= states('input_number.hot_day_threshold') | int }}"
then:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.hot_day
else:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.hot_day
- if:
- condition: template
value_template: "{{ high <= states('input_number.cold_day_threshold') | int }}"
then:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.cold_day
else:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.cold_day
- service: input_boolean.turn_on
target:
entity_id: input_boolean.house_scheduling_morning_ran
house_scheduling_evening:
alias: 'House Scheduling Evening'
sequence:
- variables:
kallen_bedtime: "{{ state_attr('input_datetime.kallen_bedtime','timestamp') }}"
- if:
- condition: state
entity_id: input_boolean.house_briefing_times_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.nightly_briefing
data:
time: >
{% if is_state('input_boolean.kallen_late_bedtime','on') %}
{{ kallen_bedtime - 7200 | timestamp_custom('%H:%M', false) }}
{% else %}
{{ kallen_bedtime - 3600 | timestamp_custom('%H:%M', false) }}
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.audible_notification_off
data:
time: >
{% if is_state('binary_sensor.kallen_school_tomorrow','on') %}
22:15
{% else %}
23:15
{% endif %}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.house_scheduling_evening_ran
master_bedroom_scheduling_morning:
alias: 'Master Bedroom Scheduling Morning'
sequence:
- if:
- condition: state
entity_id: input_boolean.master_bedroom_wakeup_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.master_bedroom_wakeup
data:
time: >
{% if is_state('input_boolean.kallen_school_today','on') %}
{% if is_state('input_boolean.kallen_school_early_release','on') %}
12:30
{% else %}
13:30
{% endif %}
{% else %}
13:00
{% endif %}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.master_bedroom_scheduling_morning_ran
master_bedroom_scheduling_evening:
alias: 'Master Bedroom Scheduling Evening'
sequence:
- variables:
low: "{{ states('sensor.overnight_lowest_temperature') | int }}"
high: "{{ states('sensor.todays_high_temp') | int }}"
- if:
- condition: state
entity_id: input_boolean.master_bedroom_climate_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.master_bedroom_cooling
data:
time: >
{% if is_state('input_boolean.hot_day','on') and is_state('binary_sensor.kallen_school_tomorrow','on') %}
20:00
{% elif is_state('input_boolean.hot_day','on') and is_state('binary_sensor.kallen_school_tomorrow','off') %}
21:00
{% elif low >= 56 and low <= 60 %}
22:30
{% elif low > 60 %}
21:30
{% else %}
00:00
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.master_bedroom_fan
data:
time: >
{% if low > 60 or is_state('input_boolean.hot_day','on') %}
22:30
{% elif low <= 60 and low >= 50 %}
23:30
{% elif low >= states('input_number.master_bedroom_fan_threshold') | int and high > 60 %}
00:00
{% else %}
06:00
{% endif %}
- service: input_select.select_option
target:
entity_id: input_select.scheduled_climate_mode_master_bedroom_aircon
data:
option: >
{% if is_state('input_boolean.master_bedroom_aircon_installed','off') %}
N/A
{% elif (states('sensor.overnight_lowest_temperature') | int) >= (states('input_number.master_bedroom_aircon_run_threshold') | int) %}
{% if (states('sensor.overnight_lowest_temperature') | int) >= (states('input_number.master_bedroom_aircon_mode_threshold') | int) %}
AC
{% else %}
Fan
{% endif %}
{% else %}
N/A
{% endif %}
- service: input_select.select_option
target:
entity_id: input_select.scheduled_climate_mode_master_bedroom_fan
data:
option: >
{% if (states('sensor.overnight_lowest_temperature') | int) >= (states('input_number.master_bedroom_fan_threshold') | int) %}
Fan
{% else %}
N/A
{% endif %}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.master_bedroom_scheduling_evening_ran
# For now, this just ties her wakeup time to the master bedroom wakeup time. In the future this will have more conditions and be independent of other rooms.
emma_bedroom_scheduling_morning:
alias: 'Emma Bedroom Scheduling Morning'
sequence:
- variables:
master_bedroom_wakeup: "{{ states('input_datetime.master_bedroom_wakeup') }}"
- if:
- condition: state
entity_id: input_boolean.emma_wakeup_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.emma_wakeup
data:
time: "{{ master_bedroom_wakeup }}"
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_scheduling_morning_ran
emma_bedroom_scheduling_evening:
alias: 'Emma Bedroom Scheduling Evening'
sequence:
- variables:
high: "{{ states('sensor.todays_high_temp') | int }}"
low: "{{ states('sensor.overnight_lowest_temperature') | int }}"
aircon: "{{ states('input_number.emma_aircon_threshold') | int }}"
- if:
- condition: state
entity_id: input_boolean.emma_bedtime_override
state: 'off'
then:
- service: input_datetime.set_datetime
entity_id: input_datetime.emma_bedtime
data:
time: >
{% if is_state('input_boolean.hot_day','on') %}
22:00
{% elif high >= 80 or low >= 60 %}
23:00
{% else %}
23:45
{% endif %}
- if:
- condition: state
entity_id: input_boolean.emma_bedroom_climate_override
state: 'off'
then:
- service: input_select.select_option
target:
entity_id: input_select.scheduled_climate_mode_emma_aircon
data:
option: >
{% if is_state('input_boolean.emma_bedroom_aircon_installed','on') %}
{% if low >= aircon %}
AC
{% else %}
White Noise
{% endif %}
{% else %}
White Noise
{% endif %}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_scheduling_evening_ran
security_scheduling:
alias: Security Scheduling
sequence:
- variables:
ct: "{{ ((now().hour * 60 + now().minute) * 60 ) }}"
kallen_school_start: "{{ state_attr('input_datetime.kallen_school_day_start','timestamp') }}"
# kallen_school_end:
# tina_work_start:
# tina_work_end:
#! IN PROGRESS
- service: input_datetime.set_datetime
entity_id: input_datetime.morning_alarm_disarm
data:
time: >
{% if is_state('input_boolean.work_today','on') and is_state('input_boolean.kallen_school_today','on') %}
{% if ct > kallen_school_start %}
{{ (state_attr('input_datetime.tina_workday_start','timestamp') - 1800) | timestamp_custom('%H:%M', false) }}
{% elif ct > state_attr('input_datetime.tina_workday_start','timestamp') and ct < kallen_school_start %}
{{ kallen_school_start - 2700 | timestamp_custom('%H:%M', false) }}
{% elif state_attr('input_datetime.tina_workday_start','timestamp') < kallen_school_start %}
{{ (state_attr('input_datetime.tina_workday_start','timestamp') - 1800) | timestamp_custom('%H:%M', false) }}
{% else %}
{{ kallen_school_start - 2700 | timestamp_custom('%H:%M', false) }}
{% endif %}
{% elif is_state('input_boolean.work_today','on') and is_state('input_boolean.kallen_school_today','off') %}
{{ (state_attr('input_datetime.tina_workday_start', 'timestamp') - 1800) | timestamp_custom('%H:%M', false) }}
{% elif is_state('input_boolean.kallen_school_today','on') %}
{{ kallen_school_start - 2700 | timestamp_custom('%H:%M', false) }}
{% else %}
11:00
{% endif %}
- service: input_datetime.set_datetime
entity_id: input_datetime.morning_alarm_rearm
data:
time: >
{% if is_state('input_boolean.work_today','on') and is_state('input_boolean.kallen_school_today','off') %}
{{ (state_attr('input_datetime.tina_workday_start','timestamp') + 900) | timestamp_custom('%H:%M', false) }}
{% elif is_state('input_boolean.kallen_school_today','on') and is_state('input_boolean.work_today','off') %}
{{ kallen_school_start + 3600 | timestamp_custom('%H:%M', false) }}
{% elif is_state('input_boolean.work_today','on') and is_state('input_boolean.kallen_school_today','on') %}
{% if ct > kallen_school_start %}
{{ (state_attr('input_datetime.tina_workday_start','timestamp') + 900) | timestamp_custom('%H:%M', false) }}
{% elif ct > state_attr('input_datetime.tina_workday_start','timestamp') and ct < kallen_school_start %}
{{ kallen_school_start - 2700 | timestamp_custom('%H:%M', false) }}
{% elif state_attr('input_datetime.tina_workday_start','timestamp') < kallen_school_start %}
{{ kallen_school_start + 1800 | timestamp_custom('%H:%M', false) }}
{% else %}
{% if (state_attr('input_datetime.tina_workday_start','timestamp') - kallen_school_start) > 5400 %}
{{ kallen_school_start + 1800 | timestamp_custom('%H:%M', false) }}
{% else %}
{{ (state_attr('input_datetime.tina_workday_start','timestamp') + 900) | timestamp_custom('%H:%M', false) }}
{% endif %}
{% endif %}
{% else %}
12:00
{% endif %}
rerun_all_scheduling_morning:
alias: 'Rerun All Scheduling - Morning'
sequence:
- service: script.kallen_scheduling_morning
- delay:
seconds: 1
- service: script.house_scheduling_morning
- delay:
seconds: 1
- service: script.emma_bedroom_scheduling_morning
- delay:
seconds: 1
- service: script.master_bedroom_scheduling_morning
- delay:
seconds: 1
- service: script.security_scheduling
rerun_all_scheduling_evening:
alias: 'Rerun All Scheduling - Evening'
sequence:
- service: script.kallen_scheduling_evening
- delay:
seconds: 1
- service: script.house_scheduling_evening
- delay:
seconds: 1
- service: script.master_bedroom_scheduling_evening
- delay:
seconds: 1
- service: script.emma_bedroom_scheduling_evening
- delay:
seconds: 1
- service: script.security_scheduling
scheduling_reset:
alias: 'Scheduling Reset'
sequence:
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.work_today_ran
- input_boolean.school_today_ran
- input_boolean.kallen_scheduling_morning_ran
- input_boolean.kallen_scheduling_evening_ran
- input_boolean.house_scheduling_morning_ran
- input_boolean.house_scheduling_evening_ran
- input_boolean.master_bedroom_scheduling_morning_ran
- input_boolean.master_bedroom_scheduling_evening_ran
- input_boolean.emma_scheduling_morning_ran
- input_boolean.emma_scheduling_evening_ran
- input_boolean.kallen_late_bedtime