Creating a alarm clock

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"

Did you install the time sensor?

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
      - 'time_utc'
      - 'beat'

I did. Just didn’t include all of the parameters.

  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘time_date’

I think your condition indentations are off. Run it through the hass script checker.

That can be due to the copy paste on the board. The following never shows any errors

sudo -u homeassistant /srv/homeassistant/homeassistant_venv/bin/hass --script check_config
Testing configuration at /home/homeassistant/.homeassistant

ok, it just looked suspicious.

It has just triggered. The only i idea i have now - is that it is saturday which is not included in the rules. And i’m running on a different than english locale for the system. Wonder how can i check for the day naming in the system? Guess it is not

      - mon
      - tue

I like this topic a lot. I added a feature request here:

I think a simple way to input time would be a great addition and simplification for all these configurations posted here…

Edit:
And another related automation using the sunset event time, if someone is interested:

So I’ve been struggling madly to be able to set a custom time for turning on a device. I’ve tried every method so for I found, and even made some new approaches myself. Still I’ve not been able to get it to work.

#This is the sensor I store the time on (it shows up in correct format in the UI):
sensor:
- platform: template
   sensors:
   car_heat_time:
   friendly_name: Tid bilvärme
   value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.timmar") | int, states("input_slider.minuter") | int) }}'

#Three examples

#Does trigger, but time is not editable by user, which I do not want.
automation:
  - alias: 'Bilvärme timer'
  trigger:
    platform: time
        hours: 17
        minutes: 30
    action:
      service: switch.turn_on
      entity_id: switch.aeotec_dsc18103_micro_smart_switch_2nd_edition_switch_5_0


 #Does not trigger 
automation:
- alias: 'Bilvärme timer'
  trigger:
  platform: template
      value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.sensor.car_heat_time.state }}'
    action:
      service: switch.turn_on
      entity_id: switch.aeotec_dsc18103_micro_smart_switch_2nd_edition_switch_5_0


#Does not trigger (error in format, not sure why)
    automation:
      - alias: 'Bilvärme timer'
trigger:
    platform: time
        after: '{{states.sensor.car_heat_time.state }}'
    action:
      service: switch.turn_on
      entity_id: switch.aeotec_dsc18103_micro_smart_switch_2nd_edition_switch_5_0



#Does not trigger 
    automation:
      - alias: 'Bilvärme timer'
trigger:
      platform: template
      value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.sensor.car_heat_time.state 
}}'
    action:
      service: switch.turn_on
      entity_id: switch.aeotec_dsc18103_micro_smart_switch_2nd_edition_switch_5_0

Even in a condition when comparing current time with ‘car_heat_time’ does not work. I would guess it is something with the formatting, but everything gets so hard when I don’t know how to troubleshoot and debug YAML.

I know C++ very well, but I just cannot grasp Python and YAML.

Hi,
check my config on the link the post above.

You are looking for:

automation:
 - alias: 'auto_heat_on'
    initial_state: True
    trigger:
      - platform: time
        minutes: '/5'
        seconds: 14
    condition:
      - condition: template
        value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H:%M")) == states.sensor.auto_heat_time.state }}'
    action:
      - service: climate.set_temperature
        data:
          entity_id: climate.ethermostaat
          temperature: 19
  - alias: 'auto_heat_off'
    initial_state: True
    trigger:
      - platform: time
        minutes: '/5'
        seconds: 14
    condition:
      - condition: template
        value_template: '{{ ((now().strftime("%s") | int - (states("input_slider.auto_heat_duration") | int) * 60) | timestamp_custom("%H:%M")) == states.sensor.auto_heat_time.state }}'
    action:
      - service: climate.set_away_mode
        data:
          entity_id: climate.ethermostaat
          away_mode: True

The trigger can be adapted to ‘/1’ minutes depending on the resolution of your minutes input.

EDIT: if you are handy in programming, AppDeamon might be easier to wrap your head around. See for example this project: Appdaemon lightschedule it uses a csv file as input for a complete light schedule.

Hey Danny, thanks for your help!
But I forgot to mention I tried this approach too, and it also did not work. I think I reached a dead end.