I am trying to create a blueprint for the Magister alarm clock automation. This is my first attempt at a blueprint, but I’m in over my head I’m afraid. So I’m turning for help to my fellow community members
This does not seem to work, can anyone help me out here? I can create an automation from this, but when I activate it nothing happens. The automation trace is empty.
blueprint:
name: Magister alarm clock
description: Trigger an alarm based on the starting time of the next lesson in Magister
domain: automation
author: Emphyrio
input:
ical_suffix:
name: Name for iCal calendar entities
description: This is the (unique) name you enter when you add the iCal Sensor. Suggestion is to use a format like magister_john
default: ""
alarm_offset:
name: Alarm offset
description: The input_number helper that contains the offset. The offset is the number of minutes before the first lesson that the alarm should sound. Think of it as the time needed to wake up, prepare and travel to school.
selector:
entity:
filter:
domain: input_number
alarm_toggle:
name: Alarm toggle
description: The input_boolean helper that toggles this alarm on or off.
selector:
entity:
filter:
domain: input_boolean
wakeup_song:
name: Wake up song
description: Audio file to be played when it is time to wake up.
selector:
media:
mode: single
trigger_variables:
ical_suffix: !input ical_suffix
alarm_offset: !input alarm_toggle
alarm_time: >-
{% set y = expand('group.'~ical_suffix) | map(attribute='entity_id') | list | join(', ') %}
{% set x = states.sensor
| selectattr('object_id', 'match', 'ical_'~ical_suffix)
| rejectattr('attributes.location', 'in', ('','verborgen','verborgen (persoonlijk)'))
| rejectattr('attributes.all_day', 'eq', true)
| sort(attribute='attributes.start')
| map(attribute='attributes.start') | list %}
{{ (as_timestamp(x|first if x != [] else '') - (states(alarm_offset)|int(default=90) * 60) )|timestamp_custom('%H:%M', true) }}
alarm_date: >-
{% set x = states.sensor
| selectattr('object_id', 'match', 'ical_'~ical_suffix)
| rejectattr('attributes.location', 'in', ('','verborgen','verborgen (persoonlijk)'))
| rejectattr('attributes.all_day', 'eq', true)
| sort(attribute='attributes.start')
| map(attribute='attributes.start') | list %}
{{ (as_timestamp(x|first if x != [] else '') - (states(alarm_offset)|int(default=90) * 60) )|timestamp_custom('%Y-%m-%d', true) }}
# The seemingly random 'expand' is my attempt to force a refresh when one of the 50 iCal entities is changed.
variables:
current_date: "{{ states('sensor.date') }}"
alarm_toggle: "{{ states('input_boolean.alarm_enabled')}}"
triggers:
- trigger: template
id: sound_the_alarm
value_template: "{{ alarm_time == states('sensor.time') }}"
condition:
- condition: state
entity_id: !input alarm_toggle
state: 'on'
- condition: template
value_template: "{{ alarm_date == states('sensor.date') }}"
actions:
- action: media_player.play_media
data: >-
!input wakeup_song