Creating a alarm clock

This is pretty cool! Any ideas why when I copy this section into my config:

input_boolean :
  reveil:
    name: Reveil positionné
    initial: off
    icon: mdi:alarm
  lightreveil:
    name: Reveil Naturel
    initial: off

I get a box with the name “Input Boolean” like this:

How did you get the outer box with the name “Reveil Martin”?

Thanks!

You have to ‘customize’ your items.

thanks for sharing this. but i cannot understand the automation.

The time is suppose to be dynamic, right? Shouldn’t it follows the time I select in the input_select dropdown? The automation seems to work only on 6.20.

Please correct me if I am wrong.

@masterkenobi You’ll have to write an “automation rule” for every item on the input_select option.

ah… that’s what I am afraid of. it seems impractical to repeat the block of codes for every input_select options. Imagine, if I have 50 options, I have to repeat the same automation rule (with changes to the time) for 50 times! The most practical way to approach this is via loop but I can’t figure out how to do so in HASS.

Do you have any idea?

Not a perfect way but… triggering an automation every…5 min. and having a condition comparing actual time with input_select state:

automation:
  - alias: "Alarm clock"
    trigger:
      platform: time
      minutes: '/5'
    condition:
      platform: template
      # this will report true if time in input_select (in format HH:MM ) is equal to actual time
      value_template: '{{ now.time().strftime("%H:%M") == states.input_select.alarm_clock.state }}'
    action:
#your action here

If you wanna try, report if it works.

1 Like

thanks a lot. i have tried it. for action, i just made it to send notification via pushbullets. when the alarm is triggered, I received countless notifications non-stop. any idea what went wrong?

Can you post some logs from alarm triggering? I haven’t tested the code on my config, as I have only 3 options in my input_select, but tested the condition on template editor from hass page and it return False almost all the time, so in theory shouldn’t trigger so often.

somehow i manage to fix it by adding seconds: 0 under the trigger.

By the way, in my input_select, the time option is using 15 minutes steps. For example…

alarmclock:
  name: "Alarm Clock"
  icon: mdi:alarm
  initial: "09:00"
  options:
    - "05:00"
    - "05:15"
    - "05:30"
    - "05:45"
    - "06:00"
    - "06:15"
    - "06:30"
    - "06:45"
    - "07:00"
    - "07:15"
    - "07:30"
    - "07:45"
    - "08:00"
    - "08:15"
    - "08:30"
    - "08:45"
    - "09:00"
    - "09:15"
    - "09:30"
    - "09:45"
    - "10:00"
    - "23:15"
    - "23:30"
    - "23:45"
    - "00:00"

Is it correct if I change the automation trigger to minutes: '/15' ?

Sure! As you have mostly 15 minutes intervals, /15 should be ok.

it works like a charm this morning. I have modified the script to add another input_boolean of “Weekdays Only” so that the alarm only runs on weekdays if it is ‘On’. Here is what i did…

input_boolean:
  alarmweekday:
    name: Weekdays Only
    initial: off
    icon: mdi:alarm

automation:
  - alias: 'Alarm Clock'
    trigger:
      platform: time
      minutes: '/15'
      seconds: 0
    condition:
      - platform: state
        entity_id: input_boolean.alarmstatus
        state: 'on'
      - platform: template
        value_template: '{% if is_state("input_boolean.alarmweekday", "on") %}{{ now.time().strftime("%H:%M") == states.input_select.alarmclock.state and (now.time().strftime("%a") == "Mon" or now.time().strftime("%a") == "Tue" or now.time().strftime("%a") == "Wed" or now.time().strftime("%a") == "Thu" or now.time().strftime("%a") == "Fri") }}{% else %}{{ now.time().strftime("%H:%M") == states.input_select.alarmclock.state }}{% endif %}'
    action:
      service: notify.notify
      data:
        message: 'Time to Wake Up'
        title: ""

Yeah ! thanks to you two for that i experiment that tomorrow.

any idea for that

  - alias: "aurora 06h00"
    trigger:
      - platform: time
        after: "05:50:00"
    condition:
      - platform: state
        entity_id: input_boolean.reveil
        state: 'on'
      - platform: state
        entity_id: input_boolean.lightreveil
        state: "on"
      - platform: state
        entity_id: input_select.choixreveil
        state: "06:00"
    action:
      service: light.turn_on
      entity_id: light.chambre
      data:
       transition: 600
  - alias: "aurora 06h05"
    trigger:
      - platform: time
        after: "05:55:00"
    condition:
      - platform: state
        entity_id: input_boolean.reveil
        state: 'on'
      - platform: state
        entity_id: input_boolean.lightreveil
        state: "on"
      - platform: state
        entity_id: input_select.choixreveil
        state: "06:05"
    action:
      service: light.turn_on
      entity_id: light.chambre
      data:
       transition: 600

I think thatr is impossible to substract minutes to time in a value_template …

How do you like this version

input_slider:
  slider_houres:
    name: Houres
    initial: 6
    min: 0
    max: 23
    step: 1
  slider_minutes:
    name: Minutes
initial: 0
min: 0
max: 55
step: 5

Automation:

- alias: Alarm Clock Slider
   trigger:
      platform: time
      minutes: '/5'
      seconds: 0
   condition:
    - platform: state
      entity_id: input_boolean.alarm
      state: 'on'
    - platform: template
      value_template: '{{ now.time().strftime("%H") == states.input_slider.slider_houres.state and now.time().strftime("%M") == states.input_slider.slider_minutes.state }}'
   action:
      service: light.turn_on
      entity_id: light.ground_light
2 Likes

Slider seems neater way to do it. Thanks. Will try it out.

It seems there is a problem with the code. The slider value for below 10 is only one digit, whereas the below 10 value for now.time().strftime("%H") or now.time().strftime("%M") are zero-padded. So, the above conditional statement for hour or minute below 10 will always return false.

To rectify this, just change to this…

now.time().strftime("%-H")
or
now.time().strftime("%-M")

Refering to http://strftime.org/

1 Like

Yes. morning noticed that too . In the evening, everything worked perfectly :slight_smile:

1 Like

I believe you could just move the value template line into the trigger section. That way you don’t need the part that checks the time every 15 minutes. so far it works for me.

trigger:
  platform: template
  value_template: '{{ now.time().strftime("%-H") == states.input_slider.slider_houres.state and now.time().strftime("%-M") == states.input_slider.slider_minutes.state }}'
5 Likes

You are right! This is a neater way to trigger the alarm. Thanks.

Excellent solution. Thanks

Guys. I have improvised the automation to make use of the nested conditions…

- alias: 'Alarm Clock'
  trigger:
    platform: template
    value_template: '{{ now.time().strftime("%-H") == states.input_slider.alarmhour.state and now.time().strftime("%-M") == states.input_slider.alarmminutes.state }}'
  condition:
    condition: or
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: input_boolean.alarmstatus
            state: 'on'
          - condition: state
            entity_id: input_boolean.alarmweekday
            state: 'on'
          - condition: time
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
      - condition: and
        conditions:
          - condition: state
            entity_id: input_boolean.alarmstatus
            state: 'on'
          - condition: state
            entity_id: input_boolean.alarmweekday
            state: 'off'
  action:
    service: notify.notify
    data:
      message: 'Good morning. Time to Wake Up!'
      title: ""
6 Likes