Alarm Clock as a package

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! :slight_smile:

alarm_1.yaml (4.4 KB)

Here’s the yaml file. You need to make sure the platform time sensor is somewhere in your homeassistant setup.

  • platform: time_date
    display_options:
    • ‘time’
1 Like

FYI: For persistant Settings between HA restarts, just remove initial setting:

input_number:
  alarm_weekday_hour:
    name: Hours
    icon: mdi:timer
#    initial: 7            <--------------- disable me ;-)
    min: 0
    max: 23
    step: 1
#    mode: box

input_boolean:
  alarm_weekday_enabled:
    name: Weekdays
#    initial: off           <--------------- disable me ;-)

EDIT: It may also depend if you have recorder component enabled in HA configuration:

# https://www.home-assistant.io/components/recorder/
recorder:

Struggeled with this some time myself, here is copy and paste :wink:

sensor:
  - platform: time_date
    display_options:
      - 'time'

I’ve noticed the alarm is sometimes triggered on point but most of the time one minute late.

Even with:

automation:
  - id: 'alarm_clock_weekday'
    alias: Alarm Clock Weekday
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 1           <--------------------------- 0, 1 or 5 makes no differents
      ...

This is my Version. No fancy Fade. Alarm Setting for Weekdays and Weekend.

Works as a package.
Tested on HA 0.88.1 - 0.89.2 and Lovelace.

automation:
  - id: 'alarm_clock_weekday'
    alias: Alarm Clock Weekday
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 1
    condition:
    - condition: state
      entity_id: input_boolean.alarm_weekday_enabled
      state: 'on'
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_weekday_time.state }}'
    action:
      entity_id: switch.sonoffbasic1
      service: switch.turn_on
  - id: 'alarm_clock_weekend'
    alias: Alarm Clock Weekend
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 1
    condition:
    - condition: state
      entity_id: input_boolean.alarm_weekend_enabled
      state: 'on'
    - condition: time
      weekday:
      - sat
      - sun
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_weekend_time.state }}'
    action:
      entity_id: switch.sonoffbasic1
      service: switch.turn_on

input_number:
  alarm_weekday_hour:
    name: Hours
    icon: mdi:timer
#    initial: 8
    min: 0
    max: 23
    step: 1
#    mode: box
  alarm_weekday_minutes:
    name: Minutes
    icon: mdi:timer
#    initial: 0
    min: 0
    max: 59
    step: 1
#    mode: box
  alarm_weekend_hour:
    name: Hours
    icon: mdi:timer
#    initial: 10
    min: 0
    max: 23
    step: 1
#    mode: box
  alarm_weekend_minutes:
    name: Minutes
    icon: mdi:timer
#    initial: 0
    min: 0
    max: 59
    step: 1     
#    mode: box

input_boolean:
  alarm_weekday_enabled:
    name: Weekdays
#    initial: off
    icon: mdi:calendar
  alarm_weekend_enabled:
    name: Weekend
#    initial: off
    icon: mdi:calendar

sensor:
  - platform: template
    sensors:
      alarm_weekday_time:
          friendly_name: 'Alarm Time Weekdays'
          value_template: >-
              {{ "%0.02d:%0.02d" | format(states("input_number.alarm_weekday_hour") | int, states("input_number.alarm_weekday_minutes") | int) }}
      alarm_weekend_time:
          friendly_name: 'Alarm Time Weekend'
          value_template: >-
              {{ "%0.02d:%0.02d" | format(states("input_number.alarm_weekend_hour") | int, states("input_number.alarm_weekend_minutes") | int) }}
  - platform: time_date
    display_options:
      - 'time'

# Optional
#group:
#  alarm_1:
#    name: Alarm Clock
#    entities:
#      - input_boolean.alarm_weekday_enabled
#      - sensor.alarm_weekday_time
#      - input_number.alarm_weekday_hour
#      - input_number.alarm_weekday_minutes
#      - input_boolean.alarm_weekend_enabled
#      - sensor.alarm_weekend_time
#      - input_number.alarm_weekend_hour
#      - input_number.alarm_weekend_minutes
#      - sensor.time

# If not enabled elsewhere:
#  time:
#    name: Time
#    entities:
#      - time_date.time
1 Like

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?

Would please share your configuration on the last line of the alarm_1.yaml?

action:

  • data: {}
    service: script.bedroom_sunrise

I would like to use a similar setup whereby my light increases incrementally in brightness half an hour before the alarm :slight_smile:

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/

someone that can help me?

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.

can some past the link to all the code and package?

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       
      

      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

    
3 Likes

in a couple of the automations, you turn on sensor.home_mode , but i don’t see the code to create it…Could you please share that?/

thanks

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:

input_boolean:
  home_mode:
    name: Home Mode
    icon: mdi:home

  away_mode:
    name: Away Mode
    icon: mid:home-circle    

  tv_mode:
    name: TV Mode
    icon: mdi:television-classic

  pc_mode:
    name: PC Mode
    icon: mdi:desktop-classic

  sleep_mode:
    name: Sleep Mode
    icon: mdi:bed-empty

  guest_mode:
    name: Guest Mode
    icon: mdi:account-group    

sensor:
  - platform: template
    sensors:
      home_mode:
        friendly_name: "Home Mode"
        value_template: >-
          {% if is_state('input_boolean.home_mode', 'on') %}
            Home Mode
          {% elif is_state('input_boolean.away_mode', 'on') %}
            Away Mode  
          {% elif is_state('input_boolean.pc_mode', 'on') %}
            PC Mode
          {% elif is_state('input_boolean.tv_mode', 'on') %}
            TV Mode            
          {% elif is_state('input_boolean.sleep_mode', 'on') %}
            Sleep Mode            
          {% else %}
            Error
          {% endif %}

automation:
  - alias: home mode enable
    trigger:
      platform: state
      entity_id: input_boolean.home_mode
      to: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.away_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.tv_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.pc_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.sleep_mode

  - alias: away mode enable
    trigger:
      platform: state
      entity_id: input_boolean.away_mode
      to: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.home_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.tv_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.pc_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.sleep_mode
        

  - alias: tv mode enable
    trigger:
      platform: state
      entity_id: input_boolean.tv_mode
      to: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.home_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.away_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.pc_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.sleep_mode

  - alias: pc mode enable
    trigger:
      platform: state
      entity_id: input_boolean.pc_mode
      to: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.home_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.tv_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.away_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.sleep_mode

  - alias: sleep mode enable
    trigger:
      platform: state
      entity_id: input_boolean.sleep_mode
      to: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.home_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.tv_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.pc_mode
      - service: input_boolean.turn_off
        entity_id: input_boolean.away_mode
        
  - alias: notify on mode error
    trigger:
      platform: state
      entity_id: sensor.home_mode
      to: 'Error'
    action:
      service: persistent_notification.create
      data_template:
        notification_id: "kyle_{{  states.sensor.random_sensor.state }}"
        message: "Home Mode sensor is in Error state!"    
        
switch:
  - platform: template
    switches:
      home_mode:
        value_template: "{{ is_state('input_boolean.home_mode', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          data:
            entity_id: input_boolean.home_mode
        turn_off:
          service: input_boolean.turn_off
          data:
            entity_id: input_boolean.home_mode
            
  - platform: template
    switches:
      away_mode:
        value_template: "{{ is_state('input_boolean.away_mode', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          data:
            entity_id: input_boolean.away_mode
        turn_off:
          service: input_boolean.turn_off
          data:
            entity_id: input_boolean.away_mode       
            
  - platform: template
    switches:
      sleep_mode:
        value_template: "{{ is_state('input_boolean.sleep_mode', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          data:
            entity_id: input_boolean.sleep_mode
        turn_off:
          service: input_boolean.turn_off
          data:
            entity_id: input_boolean.sleep_mode     
            
  - platform: template
    switches:
      tv_mode:
        value_template: "{{ is_state('input_boolean.tv_mode', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          data:
            entity_id: input_boolean.tv_mode
        turn_off:
          service: input_boolean.turn_off
          data:
            entity_id: input_boolean.tv_mode    
            
  - platform: template
    switches:
      pc_mode:
        value_template: "{{ is_state('input_boolean.pc_mode', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          data:
            entity_id: input_boolean.pc_mode
        turn_off:
          service: input_boolean.turn_off
          data:
            entity_id: input_boolean.pc_mode                   

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.

Thanks for share

Hi, getting this error

expected a dictionary for dictionary value @ data[‘packages’][‘sensor’]

Here’s my code

input_number:
    alarm_1_hour:
        name: Hours
        icon: mdi:timer
        initial: 7
        min: 0
        max: 23
        step: 1
    alarm_1_minutes:
        name: Minutes
        icon: mdi:timer
        initial: 0
        min: 0
        max: 59
        step: 1
    alarm_1_offset:
        name: Transition
        icon: mdi:blur-linear
        initial: 15
        min: 0
        max: 60
        step: 15

input_boolean:
    alarm_1_weekday:
        name: Weekdays
        initial: on
        icon: mdi:calendar
    alarm_1_weekend:
        name: Weekends
        initial: off
        icon: mdi:calendar

sensor:
    - platform: template
      friendly_name: sensor.alarm_1_time
      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) }}
    - platform: template
      entity_id: sensor.alarm_1_time_minus_offset
      sensors:
         alarm_1_time_minus_offset:
              friendly_name: 'Offset Time'
              value_template: >-
                  {{ '%0.02d:%0.02d' | format( ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset'))| int)/60)| int),(((((((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)) - ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)| int))*100) | int)*60/100) | round) ) }}

group:
    alarm_1:
        name: Wake Me Up
        entities:
            - sensor.time
            - sensor.alarm_1_time
            - sensor.alarm_1_time_minus_offset
            - input_number.alarm_1_hour
            - input_number.alarm_1_minutes
            - input_number.alarm_1_offset
            - input_boolean.alarm_1_weekday
            - input_boolean.alarm_1_weekend





automation:
  - id: 'alarm_1_weekday'
    alias: Wake me up (weekday)
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 0
    condition:
    - condition: state
      entity_id: input_boolean.alarm_1_weekday
      state: 'on'
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}'
    action:
    #- data:
    #    message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    #  service: notify.zchat
    - data: {}
      service: script.wakeup_sequence
  - id: 'alarm_1_weekend'
    alias: Wake me up (weekend)
    trigger:
    - platform: time_pattern
      minutes: /1
      seconds: 0
    condition:
    - condition: state
      entity_id: input_boolean.alarm_1_weekend
      state: 'on'
    - condition: time
      weekday:
      - sat
      - sun
    - condition: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_1_time_minus_offset.state  }}'
    action:
    #- data:
    #    message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) test {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
    #  service: notify.zchat
    - data: {}
      service: script.wakeup_sequence 
      
      
script:
  'wakeup_dim':
    alias: wakeup_dim
    sequence:
    - data:
        brightness: '0'
        entity_id:
        - light.lamp_kitchen1
        - light.lamp_kitchen2
        - light.lamp_kitchen3
        - light.lamp_dinning1
        - light.lamp_dinning2
        - light.lamp_dinning3
        - light.office_lamp_new
        - light.lamp_couch
        - light.bedroom_lamp1
        - light.bedroom_lamp2
        - light.hallway_lamp_new
        kelvin: '2200'
        transition: '0'
      service: light.turn_on
    - data:
        brightness: '0'
        entity_id:
        - light.gateway_light_286c07fa2642
        - light.yeelight_rgb_34ce008d0d2f
        rgb_color:
        - 255
        - 169
        - 92
      service: light.turn_on
    - data:
        brightness_pct: '0'
        entity_id:
        - light.colour_bulb
        rgb_color:
        - 255
        - 169
        - 92
        transition: '0'
      service: light.turn_on
  'wakeup_bright':
    alias: wakeup_bright
    sequence:
    - data_template:
        brightness: '255'
        kelvin: '2700'
        transition: '{{(states(''input_number.alarm_1_offset'') | int ) *60}}'
        entity_id:
        - light.lamp_kitchen1
        - light.lamp_kitchen2
        - light.lamp_kitchen3
        - light.lamp_dinning1
        - light.lamp_dinning2
        - light.lamp_dinning3
        - light.office_lamp_new
        - light.lamp_couch
        - light.bedroom_lamp1
        - light.bedroom_lamp2
        - light.hallway_lamp_new
      service: light.turn_on
    - data_template:
        brightness: '255'
        transition: '{{(states(''input_number.alarm_1_offset'') | int ) *60}}'
        entity_id:
        - light.colour_bulb
        rgb_color:
        - 255
        - 169
        - 92
      service: light.turn_on
  'wakeup_sequence':
    alias: wakeup_sequence
    sequence:
    - data:
        message: Alarm ! Current time is {{ states.sensor.time.state }} and alarm is set to {{ states.sensor.alarm_1_time.state }} with an offset of {{ states.input_number.alarm_1_offset.state }} set to {{ states.sensor.alarm_1_time_minus_offset.state }} Weekdays ({{ states.input_boolean.alarm_1_weekday.state }} ) and Weekends ({{ states.input_boolean.alarm_1_weekend.state }} ) 00:{{ states.input_number.alarm_1_offset.state | int }}:00
      service: notify.zchat
    - data: {}
      service: script.wakeup_dim
    - delay: 00:00:02
    - service: script.wakeup_bright
    - delay: '00:{{ states.input_number.alarm_1_offset.state | int }}:00'
    - data: {}
      service: script.play_wakeup_music

Modify this section to include the dashes and remove the duplicate ‘friendly names’. (plus you can trim down the code a little)

sensor:
  - platform: template
    sensors:
      - alarm_1_time:
        friendly_name: 'Alarm Time'
        entity_id: sensor.alarm_1_time
        value_template: >-
          {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}

      -  alarm_1_time_minus_offset:
         entity_id: sensor.alarm_1_time_minus_offset
         friendly_name: 'Offset Time'
         value_template: >-
           {{ '%0.02d:%0.02d' | format( ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset'))| int)/60)| int),(((((((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)) - ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)| int))*100) | int)*60/100) | round) ) }}

thanks for the help. still getting that same error
expected a dictionary for dictionary value @ data[‘packages’][‘sensor’]

sensor:
    - platform: template
      sensors:
       - alarm_1_time:
         friendly_name: 'Alarm Time'
         entity_id: sensor.alarm_1_time
         value_template: >-
           {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
       -  alarm_1_time_minus_offset:
          entity_id: sensor.alarm_1_time_minus_offset
          friendly_name: 'Offset Time'
          value_template: >-
            {{ '%0.02d:%0.02d' | format( ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset'))| int)/60)| int),(((((((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)) - ((((states('input_number.alarm_1_hour') | int)*60 + (states('input_number.alarm_1_minutes') | int) - (states('input_number.alarm_1_offset')) | int)/60)| int))*100) | int)*60/100) | round) ) }}

There are still spacing issues in your code, unless that was just caused by pasting into the forum

Thanks for this great topic.

Here is what i created with it:
image

It’s a grid card with:

  • Time picker card
  • 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.



2 Likes