Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automation which uses schedules to set two indicators (booleans): a morning schedule and a home indicator. Also provides schedule/calendar overrides. See description for usage.
#Blueprint by Klaas Leussink / hnldesign.nl (c) 2022
blueprint:
name: Set schedule-related booleans
source_url: https://gist.github.com/c-kick/b4dcdae9d9fa85ca8c51cdedd7293bf5
description: >-
This automation uses schedules to set two indicators (booleans): a morning schedule (useful for short morning routines on working days) and a home indicator (useful for indicating people are home, until they go to bed). It also includes an option to use a holiday calendar, which sets the home indicator on the specified start and end times if the current day is a holiday. Another option is a vacation override, which - when set to active - ignores *all* schedules/calendars and uses the specified 'vacation schedule' instead.
domain: automation
input:
morning_routine_schedules:
name: Morning schedule(s)
description: Select the schedule(s) to use as on/off indicators for the <em>'morning indicator'</em> (see below).
selector:
entity:
domain: schedule
multiple: true
morning_routine_boolean:
name: Morning indicator
description: The indicator (boolean) that indicates if one of the <em>'morning schedules'</em> is active.
selector:
entity:
domain: input_boolean
multiple: false
home_routine_schedules:
name: Home schedule(s)
description: Select the schedule(s) to use as on/off indicators for the <em>'home indicator'</em> (see below).
selector:
entity:
domain: schedule
multiple: true
home_routine_boolean:
name: Home indicator
description: The indicator (boolean) that indicates if one of the <em>'home schedules'</em> is active.
selector:
entity:
domain: input_boolean
multiple: false
holiday_calendar:
name: Holiday calendar (optional)
description: Use a calendar with (local) holidays, and set the <em>'home indicator'</em> on/off, based on the start and end times (see below), if the current date is a holiday.
default:
selector:
entity:
domain: calendar
multiple: true
holiday_start_time:
name: Holiday schedule start time (optional)
description: The start time for the <em>'home indicator'</em> when the current date is a holiday.
default:
selector:
time:
holiday_end_time:
name: Holiday schedule end time (optional)
description: The end time for the <em>'home indicator'</em> when the current date is a holiday.
default:
selector:
time:
vacation_override:
name: Vacation mode (enable vacation override)
description: Override morning and home routines through a separate vacation schedule (see below).
default:
selector:
boolean:
vacation_override_schedule:
name: Vacation schedule (optional)
description: >
Select the active vacation schedule to use. <strong>Note:</strong> the vacation scheme will
<strong>only</strong> set the 'home routines' boolean on or off; the 'morning routines' boolean
will <strong>not</strong> be set at all as long as the vacation override is active. Tip: use an
<em>empty</em> schedule if you're away on vaction.
default:
selector:
entity:
domain: schedule
multiple: true
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input morning_routine_schedules
id: morning_routine
- platform: state
entity_id: !input home_routine_schedules
id: home_routine
- platform: time
at: !input holiday_start_time
id: holiday_check_start
- platform: time
at: !input holiday_end_time
id: holiday_check_end
action:
- variables:
vacation_override_active: !input vacation_override
vacation_override_active_schedules: !input vacation_override_schedule
active_holiday_calendar: !input holiday_calendar
#set the appropriate routine boolean as per the triggered schedule state
- choose:
- conditions:
- condition: template
value_template: '{{ vacation_override_active }}'
sequence:
# Vacation override is on
- service_template: "{% if expand(vacation_override_active_schedules) | selectattr('state', 'eq', 'on') | list | count > 0 %} input_boolean.turn_on {% else %} input_boolean.turn_off {% endif %}"
entity_id: !input home_routine_boolean
- conditions:
- condition: template
value_template: '{{ not vacation_override_active }}'
sequence:
# Vacation override is off
- choose:
# Check if morning
- conditions:
- condition: trigger
id: morning_routine
sequence:
- service_template: "input_boolean.turn_{{ trigger.to_state.state }}"
entity_id: !input morning_routine_boolean
# Check if home
- conditions:
- condition: trigger
id: home_routine
sequence:
- service_template: "input_boolean.turn_{{ trigger.to_state.state }}"
entity_id: !input home_routine_boolean
# Holiday start time - Check if holiday
- conditions:
- condition: trigger
id: holiday_check_start
sequence:
- choose:
# Check if a holiday calendar is set and if today is a holiday (set home if it is)
- conditions:
- condition: template
value_template: "{{ active_holiday_calendar|length > 0 }}"
sequence:
- service_template: "input_boolean.turn_{{ states(active_holiday_calendar) }}"
entity_id: !input home_routine_boolean
- service: notify.notify
data:
message: "Is holiday? {{ is_state('active_holiday_calendar', 'on') }}"
# Holiday end time - Unset home if holiday calendar is set and if today was a holiday
- conditions:
- condition: trigger
id: holiday_check_end
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ active_holiday_calendar|length > 0 and is_state('active_holiday_calendar', 'on') }}"
sequence:
- service_template: "input_boolean.turn_off"
entity_id: !input home_routine_boolean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment