Creating a alarm clock

If you understand HA, you can use my sample to create all kinds of automations using components that are already supported by HA, not just Hue.

I don’t know python but you know and you can create custom components. I’m sure it is easy for you to learn HA.

I know It can be done using YAML in HA but I think making a custom_component is a better way.

And yes, it can be made for all kinds of components, I just haven’t figured out which method is the best yet :slight_smile:

Good job masterkenobi (and thanks for the code!)! Works excellent with my system!

Implementing it gave me good reason for cleaning up my sensors/automations :slight_smile:

Hi,

I just want to go further the processus to create an alarm on a specific time. I want to get an alarm on weekend day at a specific time only if weather outside is OK to go running / biking or skiing :slight_smile:

Do I need to create another alarm or modify this to get a more complex automation script ?

Thanks :slight_smile:

you can duplicate the existing alarm clock and add new condition in the automation. for example…

  - condition: state
    entity_id: sensor.owm_rain
    state: 'not raining'

Hello!

This topic inspired me to my first HA project. I’m new to YAML but not really to coding in general and I can’t get my natural wakeup to work. My light cannot use “transition” so I decided to make a script out of it.

My setup in the dashboard looks like this (don’t mind 23:01, it’s for testing :grin: ):

I want to be able to choose for how long the light will transition into full brightness!
I’m going to do it in 10 steps with 10% brightness, 20% brightness etc… so the script has to fetch from the slider, how long time the delay between every increment is.

The script right now looks like this and are being called succesfully from the trigger. For the purpose of testing, I’m putting the value of the slider directly as the delay time:

script:
  wakeuplight_script_fade:
    alias: Wakeup Light Fading
    sequence:
      - alias: Wakeup Light 10
        service: light.turn_on
        entity_id: light.light1
        data:
          brightness: 40
      - delay:
          minutes: '{{ states.input_slider.wakeuplight_fade.state | int }}'
      [and then repeat the brightness increment]

The “wakeuplight_fade” is the fading time slider shown in the dashboard.
This script runs through without problem if I use an integer instead of the slider state.

Why can’t delay understand the slider state?

Best regards

2 Likes

After digging around some more I actually found out how to do it!

- delay: '00:{{ states.input_slider.wakeuplight_fade.state | int }}:00'

That’s the key! :slight_smile:

Thanks @masterkenobi . I kind of used your codes by a shameless copy into my system ; working great so far :smile:

could u post your whole code? nice functio with fade.:eyes:

Please post your finished code, I’m a zombie in the morning :slight_smile:

Any chance you can release this? Would love to use the fading feature.

You can find my alarm clock here: https://github.com/Danielhiversen/home-assistant_config/search?utf8=✓&q=alarm

3 Likes

@thundergreen @bluenote73 @itsamenathan
Hey guys, sorry for the late reply. I recently moved to a new place and just got internet. Which also means my raspi and HASS is not up yet. Before I moved out, the function was only working for fixed times. I would like it to work for any time specified (setting the alarm to 08:10 should automatically calculate -30min for the fade to start at 07:40). I never got this to work though… so my code atm is only working with my normal wakup time.

The code is on my raspi which is not packed up yet… :sweat:
As soon as I get plugged in I will post it to you guys! Hang tight!

1 Like

I’ve also implemented the alarm by picking up some bits here and there, here is the complete configuration:
(also available on PasteBin: http://pastebin.com/TnJGQhtf )

homeassistant:
  customize:
sensor.relative_alarm_time:
  hidden: true
automation.alarm_executor:
  hidden: true
automation.enable_alarm_on_time_change:
  hidden: true
automation.alarm_is_activated:
  friendly_name: Activated
  icon: mdi:alarm-multiple
sensor.alarm_time:
  friendly_name: Set time
  icon: mdi:alarm
  
# Track the sun
sun:

sensor:
  - platform: template
sensors:
  alarm_time:
    friendly_name: 'Alarm'
    value_template: '{% if states.input_slider.alarmhour.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_slider.alarmhour.state|round(0)|string }}:{% if states.input_slider.alarmminutes.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_slider.alarmminutes.state|round(0)|string }}'
    entity_id:
      - input_slider.alarmminutes
      - input_slider.alarmhour
  relative_alarm_time:
    value_template: '{{ states.input_slider.alarmhour.state|float|multiply(60) + states.input_slider.alarmminutes.state|float - (now().hour|float|multiply(60) + now().minute)}}'
    unit_of_measurement: "min"
    entity_id:
      - sensor.time
  - platform: time_date
display_options:
  - 'time'

group:
  alarmclock:
name: Wake Me Up
entities:
  - sensor.alarm_time
  - input_slider.alarmhour
  - input_slider.alarmminutes
  - automation.alarm_is_activated

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

automation:
  - alias: alarm_executor
trigger:
  - platform: time
    minutes: '/5'
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: device_tracker.one_device
      state: 'home'
    - condition: state
      entity_id: device_tracker.another_device
      state: 'home'
    - condition: state
      entity_id: automation.alarm_is_activated
      state: 'on'
    - condition: numeric_state
      entity_id: sensor.relative_alarm_time
      below: 5
      above: -5
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 8
action:
  service: light.turn_on
  entity_id: light.ikea_boy
  - alias: 'alarm_is_activated'
initial_state: False
trigger:
  - platform: time
    minutes: '/1'
condition:
  - condition: template
    value_template: '{{ now().hour == (states.input_slider.alarmhour.state  | round(0))  and  now().minute == (states.input_slider.alarmminutes.state  | round(0) )  }}'
action:
  - service: homeassistant.turn_off
    data:
      entity_id: automation.alarm_is_activated
  - alias: "enable_alarm_on_time_change"
trigger:
  platform: state
  entity_id: input_slider.alarmhour, input_slider.alarmminutes
action:
  - service: homeassistant.turn_on
    data:
      entity_id:
        - automation.alarm_is_activated

This alarm will only be triggered if someone is home (device_tracker in alarm_executor automation).
When the alarm “ring” it while turn on the light call “light.ikea_boy” in my system, of course you’ll have to adapt it according to your light/group/etc…

A group is created showing the alarm settings:

I thanks all the participant to this topic from which i took part of code to assemble this alarm clock :grinning:

4 Likes

thanks @masterkenobi excelent job.

Thank you, looking forward to trying it.

Would you mind posting your code to paste bin? I don’t know if its just me, but this forum seem to mangle indents continually anytime I’m around.

thanks :slight_smile:

It’s not just you, I also realized that… maybe there is a way to format code, I used “Preformated text”.

Anyway here is the code in PasteBin :slight_smile:
http://pastebin.com/TnJGQhtf

I have same situation as @Fnykis
Currently in process of building led lamp with ESP8266 which will emulate the sunrise, so I need the automation to be triggered about 30 minutes before the actual wake up.

So here is my version:
http://pastebin.com/zQkhSdXN

No additional sensors used in this setup.

Tried to follow the example of masterkenobi with no luck. Doesn’t trigger. Does it work with HA 0,3++?

booleans

  alarmclock_status:
    name: Wake Me Up
    initial: off
    icon: mdi:alarm-check
  alarmclock_weekday:
    name: Weekdays Only
    initial: off
    icon: mdi:calendar

input_slider: 
  alarmclock_hour:
     name: Hour
     icon: mdi:timer
     initial: 7
     min: 4
     max: 12
     step: 1
   alarmclock_minutes:
     name: Minutes
     icon: mdi:timer
     initial: 0
     min: 0
     max: 55
     step: 5

sensor.yaml

    - platform: template
      sensors:
        alarmclock_time:
          friendly_name: 'Alarm Clock Time'
          value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.alarmclock_hour") | int, states("input_slider.alarmclock_minutes") | int) }}'

automation:

- alias: 'Alarmclock'
  trigger:
    platform: template
    value_template: '{{ states.sensor.time.state == states.sensor.alarmclock_time.state }}'
  condition:
    condition: or
    conditions:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.alarmclock_weekday
        state: 'on'
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
  - condition: state
    entity_id: input_boolean.alarmclock_weekday
    state: 'off'
  action:
  - service: notify.telegram
    data_template:
      title: "Alarm"
      message: "Working"