My Node-Red Smart Alarm Clock with Snooze

ConfigHardwareHome AssistantNode-RedSmart Home

Written by:

Definitely one of my very favorite features of my smart house is my alarm clock. Which is funny because I am not a morning person at all and hate getting up. But the daily grind is made a little better by having my house gently wake me by fading in lights and the local radio station instead of a screeching me out of my slumber.

Here’s a detailed guide to setting up a smart alarm clock with snooze using Home Assistant & Node-Red.

THE ALARM CLOCK

It would be simple enough to just turn the lights and radio on with a transition but that’s not that cool. What I really wanted was an alarm clock with a snooze feature, and I also wanted to bring in some other components of my smart home. So before I get into the nitty gritty, here’s the outline of the sequence:

  • 10 minutes before alarm time, begin to fade in the lights and radio volume from 0%
  • 3 minutes later, begin brewing coffee
  • Alarm time reached – Alexa reads the current time, weather, etc.
  • Morning radio resumes, the coffee is now done
  • Morning scene for the house is set

If I hit the snooze button before this sequence is complete:

  • Lights and radio are turned off
  • 3 minutes of darkness/silence
  • Lighting and radio volume transition begin again, starting at 30%
  • Continues the sequence to it’s conclusion

Shout out to the now discontinued (but still available on Amazon / Ebay sometimes) Mr. Coffee WeMo coffee maker. I love that thing. If your routine involves coffee, a coffee machine that reports it’s state is surprisingly useful.

If you know of another ‘smart’ coffee maker, I would like to know, please comment below.

THE HARDWARE

To accomplish this I am using:

To control the Amazon Echo from Home Assistant I am using this custom component, which works extremely well. One neat feature is that sending TTS to it will pause the currently playing media and resume it automatically when finished.

HOME ASSISTANT CONFIG

First step to getting this going is I’m going to create a couple of entities in Home Assistant to control the state of the alarm clock. These are pretty self-explanatory.

input_boolean:
  # Switch to Enable Alarm Clock
  house_option_alarmclock:
    name: Alarm Clock
    initial: off
    icon: mdi:alarm
  # Used by Automation to enable Snooze
  house_alarmclock_snooze:
    name: Snoozing
    initial: off
    icon: mdi:alarm-snooze
  # Used by Automation to track if alarm clock is running
  house_alarmclock_active:
    name: Snoozing
    initial: off
    icon: mdi:alarm-snooze
  # Optional: Enable radio for sequence
  house_alarmclock_radio:
    name: Alarm Radio
    initial: on
    icon: mdi:radio

input_datetime:
  # The Alarm Time input by the User
  alarmclock_time:
    name: Alarm Time
    has_date: false
    has_time: true
Alarm Clock in Lovelace UI

Here’s the nifty custom Lovelace time-input-row pictured above.

THE AUTOMATION

This alarm clock has 3 parts:

  1. The trigger, which starts the alarm sequence 10 minutes before the actual alarm time
  2. The loop, which gradually increases the brightness / volume
  3. The snooze, which pauses and resets the loop

The entire Node-Red flow is here if you want to import it in one go.

TRIGGERING THE ALARM

The trigger logic in Node-Red
Check the alarm time, turn alarm on 10 minutes before

I want my sequence to end at the alarm time, which means I need it to start 10 minutes before the actual alarm the user entered. To do this I use the moment node to subtract 10 minutes and then compare the 2. When they match, the input_boolean.house_alarmclock_active is turned on.

RELATED >>  Hardware: Odroid XU4 as Plex Media Server

Flipping that switch starts the rest of the automation.

THE LOOP

The way this flow works is by storing the brightness and volume values in flow variables. If you’re not familiar with how variables work in Node-Red, see their documentation here. By storing the values within the context of the flow, any node can access or change them as needed.

I begin the alarm clock sequence by initializing those variables to 0, and also setting up some easy automations to make coffee and prepare the Alexa media player.

To set variables in the context of this flow, use a function node like this:

flow.set("brightness", 1);
flow.set("volume", 0.0);

newmsg = {"payload":"variables initialized"}
return newmsg;
Beginning the start of the Alarm Clock sequence
First step is to initialize the flow variables for brightness / volume

Now for the fun part, which is the loop logic which transitions the light and the volume of the radio.

The Loop Logic in Node-Red
The loop

The flow variables for brightness and volume are injected  into traffic lights. The traffic lights block these messages until the alarm clock is turned on, which opens the gate for the messages to pass through. 

When that happens, the variable values for brightness and volume are sent to the appropriate service calls, and the values are incremented for the next injection.

If I don’t hit the snooze, this sequence will run until the light hits 100%. Then the traffic is closed again, and the loop exits.

THE SNOOZE

Smashing the snooze button in my half-awake state will interrupt the above loop by closing off the traffic lights, turning off the radio / lights, and resetting the flow variables to 30% (so when the loop restarts, it will run for ~7 minutes instead of the full 10).

This gets me 3 glorious minutes of silence and darkness, before the loop is started up again when the snooze switch turns off. Here’s what the loop looks like with the snooze logic attached.

The loop to set brightness and volume together with the snooze function logic.
The loop + snooze logic

FINISHING UP

The loop is done and exits when the lights reach 100% – I use a link node to continue the logic elsewhere (not shown here). All that’s left to do is flip that alarmclock_active boolean back to off, and run the rest of your sequence to finish.

In mine morning routine, this is the point I have Alexa read off a quick weather update. Here’s a simple template that I send as a TTS message to my Echo:

Good morning

The time is now {{ now().hour }} {{ now().minute }}

{{ states.sensor.dark_sky_daily_summary.state }}

The current temperature is {{ states.sensor.dark_sky_temperature.state }} degrees.

A scene for the house turns on, and my coffee is done by this point.

You can import the entire flow for the alarm clock by copying and pasting from this Pastebin link.

RESOURCES

Leave a Reply

Your email address will not be published. Required fields are marked *