Alarm clock component

Not so much a feature request as a poll for interest.

I looked at Creating an alarm clock ! updated but decided I wanted more; so I created a custom component. I’m planning on adding more functionality but if it’s something people would like, I’d be happy to send a pull request.

On top of the basic functionality (enable/disable the alarm; pick the time; trigger a light, a group or a scene when the alarm goes off) it supports an “additional” timer that can go off before / after the main one.

A typical use case: I want my alarm to play at 7am; but 15 minutes I want my Hue lights to start a “sunrise” transition that slowly turns them on. I could do that by setting up an extra automation at 6:45am, but then what if tomorrow I need to wake up 20 minutes earlier? I’d need to change both.

Future plans:

  • some kind of integration with the workday component;
  • log explicitly to logbook;
  • the component should probably create its own sensors instead of expecting the use to do so;
  • I currently support one “additional” timer before/after the main one; it might useful to generalize that to more;

To give you an example, this is what I currently have in my config:

alarm_clock:
  name: Enable Alarm
  icon: mdi:calendar
 
wake_up_time:
  name: Alarm time
  options:
    - "06:00"
    - "06:15"
    - "06:30"
    - "06:45"
    - "07:00"
    - "07:15"
    - "07:30"
    - "07:45"
    - "08:00"

alarm_clock:
  time: input_select.wake_up_time
  master_control: input_boolean.alarm_clock
  entity_id: scene.wakeup
  additional:
    time: -900
    entity_id: scene.sunrise

Looks good, may I suggest a snooze button configurable by extra mins and number of times you can repeat said extra mins :smiley: It sure would make my automations a bit smaller :smiley:

1 Like

How about different alarms for different days of the week? Or dynamic alarms based on calendar entries?

2 Likes

Yeah take makes sense, a snooze button sounds totally doable. I have kids and they don’t come with a snooze button which is why I didn’t think of that :smiley:

Totally! the configuration should actually support a list of alarms, e.g.:

alarm_clock:
  alarms:
    - time: input_select.wake_up_time
      master_control: input_boolean.alarm_clock
      entity_id: scene.wakeup
      additional:
        time: -900
        entity_id: scene.sunrise
    - time: 14:00
      entity_id: scene.do_something

As for making alarms configurable per day, I’m conflicted; I’d rather add arbitrary conditions, maybe reusing code from automations, i.e.:

alarm_clock:
  alarms:
    - time: 14:00
      entity_id: scene.do_something
      condition:
        condition: time
        weekday:
        - mon
        - wed
        - fri

@andreacampi I want to follow up the discussion here. I think this is more an use-case than a component. What we really need I think is to have templates for day/time values. In my point of view it would be a better solution if we can pass day/time parameters in a script component instance.

Then you can configure that script by input components and scenes/scripts.

1 Like

@tringler sorry for the late reply, I had a busy week at work + needed to fix my code that’s going into 0.60 :slight_smile:

I understand your point of view but really, the canonical Creating an alarm clock ! updated thread and the original post clearly show how creating a full featured alarm clock is far from trivial. It may be obvious (if tedious) for experienced people or developers, but it’s daunting to noobs.
Yet this is basic functionality that seems to be pretty popular!

To some extent this is not dissimilar from e.g. the device_sun_light_trigger: it may be only a convenience “virtual” component, but it makes it so much easier to get started.

To be honest: I’m gonna keep using this as a custom component and publish it on Github. I’m porting it onto the master tree simply because that’s the only realistic way of writing unit tests today. As a side effect that also lets me send a pull request; if it’s not accepted it’s not accepted, I won’t be slighted :slight_smile: but I hope it will as I think it would benefit others.

EDIT I didn’t mean to sound like an ass with the last paragraph. What I really wanted to say is: I’m doing it regardless and then we can discuss on the diff; code speaks louder than words.

I’d be interested in your custom component, can you post it?

Would be interested too!
At the moment it is relatively complicated to create a alarm clock.

@andreacampi

Don’t worry, It’s just my personal opinion, that instead of adding more and more platforms for different use-cases, we should take care of using the script component, which is a very powerful tool, but complicated for beginners. At the end this decision must be made by HASS dev core team and you are right then we need to refactor/elimate a lot of other components, which have the same approach.

I can imagine that as a long-term solution we would have a script editor, which has templates for use-cases. In example on the script editor you choose the template alarm clock compinent, defining your needs and the script editor is generating the script.

I’m pretty sure, that the PR will be accepted and your work is highly appreciated. :+1:

1 Like

@oakbrad here you go: https://github.com/andreacampi/dothomeassistant/blob/master/custom_components/alarm_clock.py

Here’s an example of how to configure it: https://github.com/andreacampi/dothomeassistant/blob/master/packages/alarm_clock.yaml

It doesn’t offer all features we discussed here, but it’s a start.

2 Likes

@tringler another thing that I can see long-term is a “marketplace” of packages such that you can download and install solutions to your needs. That would be neat :slight_smile:

1 Like

Excellent, thank you.

I’m totally new to home assistant, installed it yesterday. Not new to python etc.

What I need is something similar that I probably can build from your module.
I need to set a time when I plan to leave for work, which varies. Based on that time and outside temperature the car heater shall turn on the appropriate time before. .

@Flurken Not sure if this helps, but I created an ideal time to leave based on my google calendar and the current traffic. You could subtract 10 minutes from this and add a script to turn on your car if the temp is below a certain threshold

Hi. I have a newbie question, just learning home assistant and not yet friend
with the configuration. Got a alarm working with sliders for time setting.
However… It’s not clear to me how to have multiple alarms with separate controls, how do I do that? As I understand the root element alarm_clock: can only appear once, right?

Where can I read on how to do eval like things in configuration, like…
time: foo * 3
How can I cast stuff?
Works fine to have the additional time as seconds, but having a input_select does not work.

Fun, but still a bit confusing. At least the car was warm this morning.
Thanks in advance.
//Peter

Invalid config for [alarm_clock]: [alarms] is an invalid option for [alarm_clock]. Check: alarm_clock->alarm_clock->alarms.

Hello,
Great work !
I think I just did not understand where to put the custom_compents folder?
Could you help me please?

The custom_components folder goes under the HA config folder (where your yaml files are).