Bed time with IFTTT

Hey folks,

I wanted to start tracking my bedtime. Initially I thought, it’s easiest if I just make the 24hr value into the score. That means I’d best get to bed before 24:00 to get any points. But it has two bad side effects: It encourages me to stay up as late as possible until 24. And even worse if I miss the deadline there is an incentive to stay up longer, definitely messing up my entire sleep schedule.

I like automation. If I don’t have to remember logging, I have to build habits that trigger the logging automatically. I have been using Sleep as Android for some time, which integrates with IFTTT. On platform.ifttt.com we can add filter code in typescript format to manage how data is processed. Figured I’d share my code to “score” bedtimes.

var format = "hh:mm:ss";
var time = moment(MakerWebhooks.event.OccurredAt.toLowerCase().split(" at ")[1], "hh:mma");

var early = moment('19:00:00',format),
medium = moment('22:00:00',format),
late = moment('24:00:00',format),
end = moment('01:00:00',format);

if (time.isBetween(early, medium)) {
   // Early
   Beeminder.addData.setDatapointValue("3");
   Beeminder.addData.setDatapointComment("Got to bed nice and early.");
} else if (time.isBetween(medium, late)) { 
   // Medium
   Beeminder.addData.setDatapointValue("2");
   Beeminder.addData.setDatapointComment("Got to bed in plenty time.");
} else if (time.isBetween(late, end)) { 
   // Late
   Beeminder.addData.setDatapointValue("1");
   Beeminder.addData.setDatapointComment("Got to bed. But it's a close call.");

} else { 
   // Bad
   Beeminder.addData.setDatapointValue("0");
   Beeminder.addData.setDatapointComment("Boy that was late.");
}

This way, when I start the sleep tracking tool, it sends a ping to the Weebhooks IFTTT service. That sends data to my Beeminder goal. Scores can obviously be adjusted. Times can be set differently as well. I use 24hrs, but with the format “hh:mma” you can use 12hrs am/pm format. It’s super flexible and I tested it a bunch already.

Hope some find it useful to manage their bedtime.

4 Likes

Thanks! I love having more examples of IFTTT filtering on the forum!

2 Likes

This is great! also, @adamwolf do you know how long filtering has been available? I remember searching for a way to do something like this a couple years ago and came up empty handed.

2 Likes

I do not remember when it transitioned from private to public. It was public by March 2018, when I talked about it here: https://forum.beeminder.com/t/triathalon-training-goal/3814

1 Like

I don’t know much about programming, but would love to be able to do this with Fitbit or Apple Health. (I don’t have an Android phone.) Does anyone have new ideas at this point? I know this is an old post.