Creating a alarm clock

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

So this all looks super cool, but do you think we can take everything here and combine it together? As a noob at this it’s a little hard to follow, but I’m getting there. If we could sum up that would be awesome though. Thanks!

Here is the sample of complete code in my configuration.yaml…

input_slider: 
  alarmhour:
    name: Hour
    icon: mdi:timer
    initial: 9
    min: 0
    max: 23
    step: 1
  alarmminutes:
    name: Minutes
    icon: mdi:timer
    initial: 0
    min: 0
    max: 55
    step: 5

input_boolean: 
  alarmstatus:
    name: Wake Me Up
    initial: off
    icon: mdi:alarm-check
  alarmweekday:
    name: Weekdays Only
    initial: off
    icon: mdi:calendar

sensor: 
  platform: template
  sensors:
    alarm_time:
      friendly_name: 'Time'
      value_template: '{{ states.input_slider.alarmhour.state }}:{% if states.input_slider.alarmminutes.state|length == 1 %}0{% endif %}{{ states.input_slider.alarmminutes.state }}'

group:
  default_view:
    view: yes
    entities:
      - group.alarmclock
  alarmclock:
    name: Wake Me Up
    entities: 
      - sensor.alarm_time
      - input_slider.alarmhour
      - input_slider.alarmminutes
      - input_boolean.alarmstatus
      - input_boolean.alarmweekday

automation
  - alias: 'Wake Me Up'
    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: ""

Which show this in my HASS home screen…

17 Likes

Thanks! Really appreciated. You just have a little mistake in your template sensor: you handled the case where the minutes were 0, and added another 0, but you didn’t handled the case where they were set to 5. A more generic template: {{ states.input_slider.alarmhour.state }}:{% if states.input_slider.alarmminute.state|length == 1%}0{% endif %}{{ states.input_slider.alarmminute.state }}

2 Likes

yes. you are right. thanks!

Fantastic, thanks for the sum up!

I have a question !
When i want to put a transition on my light for the morning like that
- alias: "aurora 07h00" trigger: - platform: time after: "06: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: "07:00" action: service: light.turn_on entity_id: light.chambre data: transition: 600

The light turn on but the transition doesn’t happen… the light is on with full brightness… it isn’t very peaceful to wake up…
Have you test that ?

1 Like

I updated my code to replace platform with condition in condition.
I think that my word transition was not good indented, a space was needed the T of transition had to be under the T of data.

I’ll try this tomorrow moring.

Working like a charm for me.

Thanks for sharing!!!

You’re welcome :smile:

This is awesome stuff guys! Thank you. As a noob of course I have at least one question! Would it be possible to add a duration slider? So that you can set how long the even triggers for? Obviously not useful as an alarm with notify, however, I’m thinking this would be amazingly useful as a timer module for a pool pump.
Im also not sure how to change the action to use a rpi_gpio switch… one thing at a time!
Thanks again for sharing!

Continuing the discussion from Creating a alarm clock:

I’ve tested the transition item as well, but unfortunately is not working for me.

Is there any limitation (as in plattforms,etc.) that might be impacting on it?

I’m working with custom Dimmers based on MySensors and I’m not sure if I’m missing anything.

When this triggers, the lights are going 100%, and I’d like to have a more progressive effect.

ideas?

thanks in advance