Furret Blog

My Beeminder Sleep Tracking System

Lately I've been having to get up earlier than I am used to (around 6:30am to 7am) for work reasons. I'm usually fine with getting up early, but the problem is I like sleeping in too much, so over the weekend I stay in bed a couple hours later (even past 10am sometimes) and completely mess up my sleep schedule for the oncoming week.

I could just set a flat wake up time that I stick to every day, but the thing with sleep ins is that I genuinely enjoy them, and so I don't want to give them up completely1. Luckily, I have a convenient system that can track any values I want into it and binds me (with real money!) to sticking to whatever goal I want to track. But then I need a way to reliably track the time I wake up. I could just enter in data points manually each time I wake up, but...

Enter in the other side of this system. I recently upgraded phones and so now I have a SIM-less but perfectly functional old phone which is eminently capable of tracking what time I wake up and sending it to Beeminder. Using the Sleep As Android app's QR code scanning feature, I came up with an architecture to automate tracking my wake up times:

# before sleeping
Set alarm to the wake up time (e.g. 6:30am)
# at 6:30am
Alarm goes off -> scan QR code with phone -> phone sends time of scan to Beeminder via API

Of course, this only stores your raw wake up time. This is fine if you just want to enforce waking up before a certain time by posting a binary value to Beeminder (1 if you get up at or before the alarm time, otherwise 0), but if you want to allow for sleep ins there needs to be some way to translate each morning's wake up time to a range of values that give you credit for waking up early and a penalty for waking up late. With some work you can create a formula of the wake up time to the value posted to Beeminder and graph it:

claude-wakeup-graph

(this graph was generated by Claude)

Now you need some way to actually do the maths when I shut off the alarm. The maths itself is pretty much trivial to calculate, but you need some place to do it and also post the value to Beeminder's API. I could use a service like IFTTT or figure out some way to host a script to calculate the value, but eventually I settled on using the Android Automation tool Tasker. This lets you do all the calculations and the API call all on the phone itself, without any dependence on external services (other than Beeminder), but it seems the only way to enter scripts into Tasker is to either to either tediously tap it in yourself on the phone screen or else to manually edit scripts2 in its own not particularly human readable XML format and then import it into the phone's Tasker app. I eventually managed to figure out (with Claude's help) how to get the script onto the device, but this was pretty tedious and I would prefer if I could write scripts remotely and then deploy them onto my phone with one command.

So after I figured Tasker out and did some debugging I got it working, and it's been getting me up early for the last couple of weeks. I tweaked the formula a bit to allow for later wake ups on the weekend, but the core formula remains the same. I wish i could tweak it some more, but Tasker's interface isn't the greatest for script tweaks and debugging. But it works, and maybe this could help out some others who have trouble with sticking strict wake up times every day of the week.

You can get the Tasker backup file for this system here. Remember to change BEEMINDER_GOAL_URL and BEEMINDER_TOKEN_GOES_HEREbefore uploading it to Tasker!


Have thoughts? Post them in my feedback form!

  1. The other question is whether I ought to be avoiding sleeping in for long duration due to potential health risks. There are some large observational studies which suggest sleep regularity is correlated with lower mortality risk, but the actual causal effects are unclear. It seems like a good idea to avoid things that mess up your sleep regularity as much as possible and make active choices to improve your sleep quality, but 1-2 hours sleeping late one day a week seems alright to me. This is not medical advice, consult your doctor etc.

  2. I did get Claude Opus 4.8 to help me out by uploading the XML file to it and telling it to edit the file for me. It didn't get it 100% right, which is fair as the file doesn't seem to be human editable anyway.

#beeminder #life #technical