Dongle Jungle

Creating a Smart Sleep Mode for Your Home

Cover Image for Creating a Smart Sleep Mode for Your Home
Marc
Marc

Creating a Smart Sleep Mode for Your Home

Sleep! It's so important, but more than once, my automations have woken me up in the middle of the night with unintended light effects or by playing music that was meant for daytime. In this post, I’ll dive into my sleep mode and morning alarm setup in Home Assistant.

Sleep Status History

What is Sleep Mode?

So, sleep mode—what’s the deal? In the realm of home automation, sleep mode signifies a state where your home shifts gears to cater to your sleep needs. It’s not just about turning off lights; it’s about creating an environment conducive to rest and keeping you asleep. Though many call it Sleep Mode, I think of it as my Sleep Status.

The Three Phases of Sleep

I’ve set up an input select in Home Assistant that features three distinct modes: "Awake," "Asleep," and "Waking Up."

Why three? I used to have just an input boolean that indicated sleep on or off, and that wasn't enough. I also had an additional "Falling Asleep" status for a while, but it turns out that did not add any value over the "Asleep" status, so I nixed it. Here’s how I’ve categorized the remaining three:

  • Awake: This is your everyday mode where everything is on and working as you programmed it when you thought of all your nifty automations and voice assistant notifications.

  • Waking Up: This is a transitional state. It’s meant for the period of time when your alarm is ringing but you are not necessarily awake yet.

  • Asleep: This is where the magic happens. Activated when everyone in the house is falling asleep, this mode signals various automations to enhance our nighttime experience and prevents others from running.

Sleep Status Configuration

The Sleep Mode Automation

When “Asleep” is activated, a series of actions kick in that completely take my nighttime routine off my hands:

  1. Blinds Down: If no other trigger has done so yet, this is when bedroom blinds and those in other rooms take their night-time positions.

  2. Lights Out: Lights fade off in the bedroom and turn off everywhere else.

  3. Systems Off: If the TV isn't off, it will be now, and the A/V receiver as well as selected appliances and all wall tablets are turned off too.

  4. Temperature Control: The thermostat adjusts to a cool, comfortable temperature for sleep.

  5. Security Check: Cameras become active, and all intruder alarms are set.

  6. Windows and Doors Verification: All relevant door and window sensors are checked for their closed states; if any of them are open, a notification is spoken in the bedroom.

  7. White Noise On: The little speaker on the nightstand slowly fades in white noise to help with falling and staying asleep—no matter what the neighbors are doing with their garbage bins at 6 am.

  8. Air Purifier On: The Zigbee air purifier in the bedroom also starts gently blowing so that the air keeps moving for better CO2 levels and thus better sleep.

Sleep Status Automation Trigger

Moreover, the status of sleep mode serves as an essential condition in many of my automations. For example, when sleep mode is active, motion sensors won’t trigger lights in the bedroom. It’s very disorienting to have lights blasting when you’re trying to sleep—ask me how I know.

Conversely, bathroom or hallway lights can still activate, but only to a dimmed state, gently guiding me without ripping me out of my dreams. Other automations that, e.g., trigger at sunrise only execute when I'm awake—ensuring no one wakes up who doesn't want to.

The Waking Mode Automation

When Sleep Status switches to "Waking Up," it triggers the nightstand lights to come on slowly, and my morning playlist starts to fade in. It opens the blinds a bit and, after a while, turns on that annoying ceiling lamp to make sure I don't oversleep. Hitting snooze keeps Home Assistant in this state until I finally confirm that I'm "Awake."

My bed occupancy sensor status is also taken into account here.

The Awake Mode Automation

When Sleep Status finally switches to "Awake," everything starts to really wake up. The blinds open fully, that ceiling lamp turns off, and a voice notification tells me about the weather and what's on my calendar and to-do list today. It also triggers a few kitchen automations, turns off the indoor security cameras, and generally kicks the house into gear.

Triggering Sleep Status Changes

The triggers for the sleep status changes are not manual, either—although that is always an option. Instead, I’m using the fantastic Sleep as Android app to automatically adjust the sleep status based on my sleep tracking and alarm.

Sleep Status History

When the Sleep app starts tracking my sleep, it activates a webhook in Home Assistant that changes Sleep Status to “Asleep.” And when the app reports to Home Assistant that the alarm has gone off, Sleep Status switches to "Waking Up." When I dismiss the alarm, Sleep Status switches to "Awake," reintegrating the automations into the morning routine. This seamless integration minimizes the need for manual input and ensures the home environment aligns perfectly with my sleep patterns.

Sleep as Android has many more events that can be used to trigger automations related to your sleep, like entering REM phase, snoring, or the configurable smart period before the alarm starts. For me, the Bedtime, Tracking Started, Tracking Stopped, and Alarm Started events are sufficient.

Navigating the Challenges

Now, let’s be real—automations aren’t flawless, and neither are the people that write them. False triggers can affect the cozy vibe you’re working so hard to create or even ruin a whole night's sleep. Before I had a proper sleep mode, accidental occupancy triggers woke me up plenty of times in the middle of the night with bright lights, blasting music, or both.

This is why I would recommend a Sleep Mode as one of the first helpers in any home automation setup. Making sure that the occasional bug doesn't affect your and your partner's(!) sleep is critical to being able to enjoy this fun hobby.

Conclusion

Sleep mode is not just a “nice-to-have” feature; in my opinion it’s a necessity for your sleep routine and one of the cornerstone experiences in home automation. It’s a thoughtful piece of the smart home puzzle that acknowledges your need for comfort, rest, and security—and makes sure your home stays cozy and quiet when you need it to.