Engineering a Wake up Routine

A cartoon astronaut sleeps on a bed with a blanket of stars and z's floating overhead.
Image by catalyststuff on Freepik

Somewhere in the past decade I went from being a chronic night-owl πŸ¦‰ to being a "morning person" πŸŒ…. I'm not sure what changed and caused me to come over to the dark side of early risers, but I guess I'm in that camp now.

But "early" is a relative statement.

There's early and then there's early.

Despite being a morning person, in order to get all the things done that I want to in a day, I often need to get up earlier than what even I'd prefer.

I still face the same problem as everyone else: How to actually get out of bed in the morning.

Root cause analysis

Alright engineering brain 🧠, we have a problem, how can we solve it?

First thing was to interrogate myself a bit more deeply. Why is getting out of bed hard?

A couple things immediately came to mind:

  1. The sun isn't up, it's dark, it's too easy to just drift back off to sleep.
  2. It's cold, I don't want to get out from the warm, toasty bed.
  3. I feel exhausted, like I didn't sleep at all.
  4. I don't want to do the thing I'm getting out of bed to do.

James Clear in Atomic Habits states that the first principle to establishing a new habit, or even getting started doing something, is to make it as easy as possible to do that thing.

So if these four things are making getting out of bed in the morning insurmountable to my weak brain, then what I could I do to remove these barriers? πŸ€”

πŸŒ™ The sun isn't up. So turn on the lights. πŸ’‘

Light is a trigger for your body on many different levels including waking you up in the morning. Without the sun there to help naturally guide your body out of its sleep phase we need to resort to artificial methods.

And on top of that, bright lights also make it harder to accidentally fall back sleep in the morning.

For me, the solution to creating my own artificial sunrise was to use smart lights that could be scheduled to fade on at a certain time. If you get up at relatively the same time every day then using a fixed schedule would be perfectly sufficient.

But I like to over-complicate things. 😈

In addition to the smart bulbs, I leveraged HomeAssistant and the HomeAssistant app on my phone to schedule when the lights should begin to fade in relative to the "Wake Up" alarm on my phone.

The app on my phone inspects my scheduled "Wake Up" alarm and let's the server know what time I plan to wake up. My automation for the lights begins 5min before my alarm is scheduled to go off, letting the lights slowly fade on, preparing me for my alarm.

To accomplish this I used some custom sensors and an automation.

Sensors

# Phone Next Alarm
next_alarm_5min_timestamp:
  value_template: "{{ ((state_attr('sensor.bailey_phone_s23_next_alarm', 'Time in Milliseconds') | int / 1000) - 5*60) | timestamp_custom('%a %h %d %H:%M %Z %Y') }}"
next_alarm_package: 
  value_template: "{{ state_attr('sensor.bailey_phone_s23_next_alarm', 'Package') }}"

Automation

alias: Alarm - Wake Up Alarm
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: >-
      {{now().strftime("%a %h %d %H:%M %Z %Y") ==
      states.sensor.next_alarm_5min_timestamp.state }}
  - condition: state
    entity_id: person.bailey
    state: home
  - condition: template
    value_template: >-
      {{ is_state_attr('sensor.bailey_phone_s23_next_alarm', 'Package',
      'com.sec.android.app.clockpackage') }}
action:
  - service: light.turn_on
    data:
      transition: 300
      brightness_pct: 100
      kelvin: 3500
    target:
      entity_id: light.master_bedroom_lamps
    enabled: true
mode: single

πŸ’€ I feel exhausted. So time your sleep cycle. ⏲

Science may be fuzzy on this one but I found it beneficial to schedule my wake up alarm near the end of a sleep cycle.

Throughout the night your body moves through several sleep cycles. Generally, at the beginning or end of a sleep cycle you are in the lightest phases of sleep meaning it will be easiest for you to wake up during these times. On the other hand, if you try to wake up in the middle of a deep sleep cycle, you'll feel heavy, groggy, and like you haven't had any sleep at all.

I chose to estimate around a 90min sleep cycle and set my alarm so that I would wake up near the end of one of these cycles. There are plenty of online calculators you can use to figure out what time to wake up based on sleep cycle.

But can I build my own calculator? πŸ‘·β€β™€

Turns out HomeAssistant can save the day again. For this task I made use of Helpers and Templating. Using the UI I created two input_datetime Helpers, one for AsleepBy and one for WakeUpBy.

Asleep By

The AsleepBy input_datetime helper (created via settings UI) gives you an input where you can change what time you think you will be asleep by. You can then pair this selected value with the below template calculations to determine what time you should set your alarm to get up.

{% set cycles = [3,4,5,6,7] %}
Asleep by {{ as_timestamp(states.input_datetime.asleepby.state) | timestamp_custom('%I:%M %p') }}
Get up at
{% for n in cycles -%}
   - {{ as_timestamp(as_datetime(states.input_datetime.asleepby.state) + timedelta(minutes=(n*90))) | timestamp_custom('%I:%M %p') }} - {{ (n*90) / 60 }} hours {{'\n'}}
{%- endfor %}

Output:

Asleep by 09:45 PM  
Get up at
- 02:15 AM - 4.5 hours
- 03:45 AM - 6.0 hours
- 05:15 AM - 7.5 hours
- 06:45 AM - 9.0 hours
- 08:15 AM - 10.5 hours

Wake Up By

The WakeUpBy input_datetime helper (created via settings UI) gives you an input where you can change what time you would like to wake up at. You can then pair this selected value with the below template calculations to determine what time you should try to be asleep by to get the desired amount of sleep.

{% set cycles = [7,6,5,4,3] %}
Wake up by {{ as_timestamp(states.input_datetime.wakeupby.state) | timestamp_custom('%I:%M %p') }}
Go to bed by
{% for n in cycles -%}
  - {{ as_timestamp(as_datetime(states.input_datetime.wakeupby.state) - timedelta(minutes=((n*90)+30))) | timestamp_custom('%I:%M %p') }} asleep by {{ as_timestamp(as_datetime(states.input_datetime.wakeupby.state) - timedelta(minutes=(n*90))) | timestamp_custom('%I:%M %p') }} - {{ (n*90) / 60 }} hours {{'\n'}}
{%- endfor %}

Output:

Wake up by 04:15 AM  
Go to bed by
- 05:15 PM asleep by 05:45 PM - 10.5 hours
- 06:45 PM asleep by 07:15 PM - 9.0 hours
- 08:15 PM asleep by 08:45 PM - 7.5 hours
- 09:45 PM asleep by 10:15 PM - 6.0 hours
- 11:15 PM asleep by 11:45 PM - 4.5 hours

🧊 It's cold. So turn on the heat. πŸ”₯

Temperature is another big component in sleep health. To sleep best, we need the room to be relatively cool (see tip #10). So if our goal is to wake up, then logic would conclude we should try to warm up our environment around the time we want to be awake.

Not only will this help our bodies naturally wake up, but it will also make the bed feel less "cozy" and more "omg get me out of this thing" 😲.

Most modern thermostats have a scheduling feature, so it's easy enough to create a program that cools the house down before bed time and heats it back up in the morning. And if you don't want to heat the whole house an alternative could be to use a space heater with a scheduling function.

Those are both good options, but I'm not here for good options, I'm here for over-engineered options! πŸ€–

For this solution I've actually already done most of the leg work with the Lights Automation discussed previously. I just need to adjust it a bit to also turn on the heat 5min before the alarm goes off.

I made two changes:

  1. Call the Nest Thermostat to set the daytime temp range
  2. Turn off the Master bedroom ceiling fan

Automation

alias: Alarm - Wake Up Alarm
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: >-
      {{now().strftime("%a %h %d %H:%M %Z %Y") ==
      states.sensor.next_alarm_5min_timestamp.state }}
  - condition: state
    entity_id: person.bailey
    state: home
  - condition: template
    value_template: >-
      {{ is_state_attr('sensor.bailey_phone_s23_next_alarm', 'Package',
      'com.sec.android.app.clockpackage') }}
action:
  - service: light.turn_on
    data:
      transition: 300
      brightness_pct: 100
      kelvin: 3500
    target:
      entity_id: light.master_bedroom_lamps
    enabled: true
  - service: climate.set_temperature
        data_template:
          target_temp_low: "{{states(\"input_number.day_min_temp\")|float}}"
          target_temp_high: "{{states(\"input_number.day_max_temp\")|float}}"
          entity_id: climate.nest_thermostat
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.master_bedroom_fan
mode: single

πŸ‹οΈ I don't want to do the thing. So change the routine. β˜•

This final hack was one of psychology not technology, but it was equally important. The last hurdle to overcome in getting out of bed was motivation.

In general, the reason I need to get up early is so that I have time to exercise before work. However, at 5am, the last thing I want to do is roll out of bed into my running shoes and head out the door.

So what would I rather do? (other than go back to sleep)

Get up and have a hot cup of coffee. β˜•

This may sound ridiculous, but it was a game changer for me. Adjusting my morning routine so that I could first sit and enjoy a cup of coffee before going to exercise made getting up something I could look forward to.

This does mean I need to get up a bit earlier than if I were to forgo the coffee, but the trade off is worth it if it means I consistently get out of bed and do the thing.

Is getting out of bed easy now?

Yes and no.

Most days, yes, but there are still some days, or a span of days, where none of these things seem to help.

However, even on those days where I have to fall back on sheer will power, I find that I have more will power than before to overcome the desire to stay in bed.

πŸ™Œ
By not having to use will power every single day, I end up with more of it in the tank to use on the days when I really need it.

This is another reason why Clear advocates for making things easy in Atomic Habits, because we know that will power is a limited resource. If we rely on it too much, it eventually burns out.

People who appear to be the most disciplined are often really just the best at structuring their lives in a way that does not require heroic willpower and self-control (p. 93).

πŸ’‘
The people with the best self-control are typically the ones who need to use it the least.

Instead of summoning a new dose of willpower whenever you want to do the right thing, your energy would be better spent optimizing your environment to support you, not work against you (p. 95).

While this routine was something I built over a year ago, long before reading Atomic Habits, it wasn't till after reading the book that I understood why this routine seemed to work.

This was an especially fun project to reflect on and see Biology, Psychology, and Technology come together to accomplish a goal.

Subscribe to Next Topic

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe