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:
- Philips Hue smart bulbs – I’ve set this script up to work with any dimmable bulb – even those that don’t support transitions
- Amazon Echo – for TTS & radio
- Mr. Coffee WeMo – coffeemaker that reports state
- Hank Simple Z-Wave Button – for snooze button
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
Here’s the nifty custom Lovelace time-input-row pictured above.
THE AUTOMATION
This alarm clock has 3 parts:
- The trigger, which starts the alarm sequence 10 minutes before the actual alarm time
- The loop, which gradually increases the brightness / volume
- 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
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.
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;
Now for the fun part, which is the loop logic which transitions the light and the volume of the radio.
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.
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.
[…] https://diyfuturism.com/index.php/2018/12/16/my-node-red-smart-alarm-clock-with-snooze/ […]
This was helpful! I’ve been debating between getting a standalone wake-up light alarm clock and getting smart bulbs. I really want to be able to use the snooze function, and I want to be able to program different alarms for different days (on Sundays I always get up at 10 but on Mondays I always get up at 9). I haven’t found smart bulb apps with those two things, although most apps you have to pair with a bulb before you can see all the settings. This is making me think maybe the bulbs will work.
Hi Brad – Thanks for the massively detailed tutorial on the alarm clock. I’m trying to get it working on my system, but I’m running into a NodeRed issue with the variable. It’s giving me the error “Entity could not be found in cache for entity_id: variable.house_state”.
Any idea what could be going wrong here?
[…] post My Node-Red Smart Alarm Clock with Snooze appeared first on DIY […]