Hi - is this currently the best/most developed wake up alarm for Home Assistant? I couldn’t really find a great deal else.
I’m interested in using your code (thank you) is there any way to repair the YAML idents or is it just a case of going through it line by line and adding? Happy to do so if that’s the way!
I think you might like this : Universal Persistent Timer
It can add a timer to anything including multiple scripts, lights etc. with separate start and stop actions, and will resume in the event of downtime and requires no programming skills once installed. All lights, switches etc can be accessed from auto populated lists; and you can specify days of the week, repetitions, intervals, and much more. Timers can be paused, backed up and give activation notifications etc. https://youtu.be/rUeTIU1uAP0
@skalavala, I could not load your package, I get the following error:
Invalid config for [automation]: required key not provided @ data['action']. Got None
required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
I added the custom component input_label.py, what could I be doing wrong?
i’m getting errors on the sensor from @bott0r
when checking the config i get these messages.
what can i do about it?
Invalid config for [sensor.template]: [friendly_name] is an invalid option for [sensor.template]. Check: sensor.template->friendly_name. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
Invalid config for [sensor.template]: [entity_id] is an invalid option for [sensor.template]. Check: sensor.template->entity_id. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
I’m looking for a script similar to this… but I’m wondering how often does this check to see when the alarm goes off or if the configuration of alarms.yaml is changed. Because I’m a shift worker and my shifts are ALWAYS different, I wrote a script to calculate what time I need to leave (depending on my current location). Because this changes frequently and sometimes with little notice, my script outputs it to MQTT and a webpage with JSON, with a UNIX timestamp and the actual 24hr clock time. I was wondering if it were possible to modify this to be able to read this and trigger an alarm, then I would be able to install this into my HA.
Thanks a lot for this post! I took your idea and made some changes/additions. Figured I’d share in case anyone is interested. The biggest difference is that I got rid of the offset. I didn’t see any use for it in my scenario. I also made some automations that automatically increases the hour when the minutes reach 60. The reason for this is to create a snooze function. I can snooze the alarm and increase the time incrementally. The hour needed to increase automatically for this to work.
I also have a couple of automations in there that checks my work schedule if I haven’t set an alarm and I have to work in less than 8 hours. Since I’m stupid and forget all the time.
input_number:
#This sets the hour value for the alarm clock. Set to max 24 to allow for automatic advancing by minutes.
alarm_1_hour:
name: Hours
icon: mdi:timer
min: 0
max: 24
step: 1
#This sets the minutes value for the alarm clock. Advances hour upon reaching 60
alarm_1_minutes:
name: Minutes
icon: mdi:timer
min: 0
max: 60
step: 1
input_boolean:
#Alarm clock on/off switch
alarm_1_enable:
name: "Enable Alarm"
sensor:
#Returns the time the alarm is set for in hh:mm
- platform: template
sensors:
alarm_1_time:
friendly_name: 'Alarm Time'
value_template: >-
{{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
#Basic time/date sensors for Home Assistant
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
#Returns time in local hh:mm AM/PM format
- platform: template
sensors:
local_time:
friendly_name: "Local Time"
entity_id: sensor.time
value_template: "{{ as_timestamp(now()) | timestamp_custom('%-I:%M %p') }}"
#Returns today's date in a compact format (Jun10)
- platform: template
sensors:
formatted_date:
friendly_name: "Formatted Date"
entity_id: sensor.date
value_template: "{{(now().strftime('%a%b') ~ now().day)}}"
#This sensor returns the number of minutes until my next shift at work starts. the +300 is to adjust to local time and will need to be adjusted when DST starts/ends.
- platform: template
sensors:
time_til_work:
entity_id: sensor.time
value_template: >-
{% if states.calendar.work_schedule.attributes.start_time %}
{{((as_timestamp(states.calendar.work_schedule.attributes.start_time) - as_timestamp(now())) / 60 +300 ) | default(99) | int }}
{%- else -%}
0
{%- endif %}
automation:
#Two automations to advance the hour if minutes go over 59
- alias: advance hour once minnute reaches max
trigger:
platform: state
entity_id: input_number.alarm_1_minutes
to: '60.0'
action:
- service: script.turn_on
entity_id: script.advance_hour
- alias: reset hour to zero when it reaches max
trigger:
platform: state
entity_id: input_number.alarm_1_hour
to: '24.0'
action:
- service: script.turn_on
entity_id: script.reset_hour
#Work starts in 70 minutes but I am still in bed
- alias: time until work warning
trigger:
platform: numeric_state
entity_id: sensor.time_til_work
below: 70
condition:
condition: state
entity_id: sensor.home_mode
state: 'Sleep Mode'
action:
- service: script.turn_on
entity_id: script.time_til_work_warning
#If work starts in less than 8 hours and there is no alarm, run the script
- alias: work is soon but alarm is off
trigger:
platform: numeric_state
entity_id: sensor.time_til_work
below: 479
condition:
condition: state
entity_id: input_boolean.alarm_1_enable
state: 'off'
action:
- service: script.turn_on
data:
entity_id: script.work_soon_alarm_warning
#This is the actual alarm clock automation. Compares set time to the current time and triggers when they are equal.
- id: alarm_1
alias: 'Work Alarm'
trigger:
- platform: time_pattern
minutes: '/1'
seconds: 00
condition:
- condition: template
value_template: "{{ states.sensor.time.state == states.sensor.alarm_1_time.state }}"
- condition: state
entity_id: input_boolean.alarm_1_enable
state: 'on'
action:
- service: script.turn_on
entity_id: script.bedroom_sunrise
#Turn off the alarm when I wake up
- alias: alarm turn off
trigger:
platform: state
entity_id: sensor.home_mode
to: 'Home Mode'
action:
- service: script.turn_on
entity_id: script.alarm_clock_off
#Warn if I enable sleep mode without having an alarm set within 2 minutes
- alias: alarm warning sleep mode
trigger:
platform: state
entity_id: sensor.home_mode
to: 'Sleep Mode'
condition:
condition: state
entity_id: input_boolean.alarm_1_enable
state: 'off'
action:
- service: script.turn_on
data:
entity_id: script.alarm_off_warning
script:
#Sleep mode is on but the alarm clock is not enabled
alarm_off_warning:
sequence:
- wait_template: "{{ is_state('input_boolean.alarm_1_enable', 'on') }}"
timeout: '00:02:00'
continue_on_timeout: 'true'
- condition: state
entity_id: input_boolean.alarm_1_enable
state: 'off'
- service: tts.amazon_polly_say
data:
entity_id: media_player.volumio_mpd
message: "Warning: Sleep mode is on but the alarm clock is not enabled."
#Work starts in less than 8 hours but no alarm has been set
work_soon_alarm_warning:
sequence:
- service: switch.turn_on
data:
entity_id: switch.home_speakers
- service: notify.tasker
data:
message: "Pausepod"
- service: media_player.media_stop
data:
entity_id: media_player.spotify
- service: media_player.media_pause
data:
entity_id: media_player.shield2019
- delay: '00:00:03'
- service: tts.amazon_polly_say
data:
entity_id: media_player.volumio_mpd
message: "Warning: Work starts in less than 8 hours but no alarm has been set."
#Alarm sounding script
bedroom_sunrise:
sequence:
- service: light.turn_on
data:
entity_id: light.master_bedroom
brightness: 30
- delay: '00:00:45'
- service: media_player.turn_on
data:
entity_id: media_player.spotify
- delay: '00:00:03'
- service: media_player.select_source
data:
entity_id: media_player.spotify
source: Speakers
- service: media_player.select_source
data:
entity_id: media_player.spotify
source: Speakers
- service: media_player.volume_set
data:
entity_id: media_player.spotify
volume_level: 0.9
- delay: '00:00:02'
- service: spotify.play_playlist
data:
media_content_id: spotify:playlist:37i9dQZF1DWWEJlAGA9gs0
random_song: true
- service: light.turn_on
data:
entity_id: light.master_bedroom
brightness: 90
- delay: '00:00:45'
- service: light.turn_on
data:
entity_id: light.master_bath
brightness: 255
- delay: '00:00:30'
- service: media_player.volume_set
data:
entity_id: media_player.spotify
volume_level: 0.3
- delay: '00:00:01'
- service: tts.amazon_polly_say
data:
entity_id: media_player.volumio_mpd
message: "Kyle, it is time to wake up. Please enable Home Mode to stop the alarm."
- service: media_player.volume_set
data:
entity_id: media_player.spotify
volume_level: 0.9
- wait_template: "{{ is_state('media_player.spotify', 'playing') }}"
timeout: '00:00:10'
continue_on_timeout: 'true'
- service: light.turn_on
data:
entity_id: light.master_bedroom
brightness: 255
- condition: state
entity_id: media_player.spotify
state: 'idle'
- service: media_player.select_source
data:
entity_id: media_player.spotify
source: Speakers
- delay: '00:00:02'
- service: spotify.play_playlist
data:
media_content_id: spotify:playlist:37i9dQZF1DWWEJlAGA9gs0
random_song: true
#Snooze the alarm: turn lights back off, stop music, add 7 minutes to the alarm time.
alarm_clock_snooze:
sequence:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.alarm_1_enable
- service: script.turn_off
data:
entity_id: script.bedroom_sunrise
- service: light.turn_off
data:
entity_id: light.master_bedroom
- service: light.turn_off
data:
entity_id: light.master_bath
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
# - delay: '00:00:01'
- service: input_number.increment
data:
entity_id: input_number.alarm_1_minutes
- service: input_boolean.turn_on
data:
entity_id: input_boolean.alarm_1_enable
- service: media_player.media_pause
data:
entity_id: media_player.spotify
#Disable the alarm clock when I wake up
alarm_clock_off:
sequence:
- service: media_player.media_pause
data:
entity_id: media_player.spotify
- service: input_boolean.turn_off
data:
entity_id: input_boolean.alarm_1_enable
- service: script.turn_off
data:
entity_id: script.bedroom_sunrise
#Advance the hour when the minutes reach 60 and reset the minutes to 0
advance_hour:
sequence:
- service: input_number.set_value
data:
entity_id: input_number.alarm_1_minutes
value: 0
- service: input_number.increment
data:
entity_id: input_number.alarm_1_hour
#Reset hour to 0 if the alarm hour goes past 11pm
reset_hour:
sequence:
- service: input_number.set_value
data:
entity_id: input_number.alarm_1_hour
value: 0
#Wake me up if I have snoozed too many times and work is starting soon
time_til_work_warning:
sequence:
- service: light.turn_on
data:
entity_id: light.master_bedroom
brightness: 255
- service: tts.amazon_polly_say
data:
entity_id: media_player.volumio_mpd
message: "Warning! Sleep mode is still enabled but Work starts in less than 70 minutes. You must wake up now!"
- delay: '00:00:03'
- service: media_player.select_source
data:
entity_id: media_player.spotify
source: Speakers
- service: media_player.select_source
data:
entity_id: media_player.spotify
source: Speakers
- service: media_player.volume_set
data:
entity_id: media_player.spotify
volume_level: 1.0
- delay: '00:00:02'
- service: spotify.play_playlist
data:
media_content_id: spotify:playlist:186HKLGj6De3DNSsVPjL3p
random_song: true
Sure! One of my favorite packages actually. I set the mode using a mix of manual switches on kiosks and automations tied to other things in other parts of my config. The automations ensure that once one mode is activated the others are deactivated, which allows the sensor to always return only one value. Here’s the home mode package:
I wrote this a while back and looking at it now you may be able to do it without using the input booleans and instead only use switches. The reason I need the switches at all is so I get the color coding on my kiosks for which mode is active.
button card for the next alarm and an icon (template sensor)
input booleans for alarm on/off, wake-up lights and input booleans for each day of the week.
load of template sensors for determing the next alarm, determing if its on, showing a notification from 9 hours before the alarm is on
Nodered is used for the automation part. My setup doesnt rely on HA, everything is set to global vars in nodered. The schedex-node is what is really controlling this thing.