Red Gregory

View Original

Notion Formula: Automate Sleep Database With Relations And Rollups

More specifically, under the conditions of a tag associated with a "task," properties for an "alarm set" to wakeup and "unwinding" time before bed is altered. To do this I use relational and rollup properties.

Let's Begin With Tasks

In the task database there is only three properties (Name, Priority and Deadline). We want to connect 'Name' and 'Priority' into a separate sleep tracker.

The Sleep Tracker

In order to connect tasks, we need to first create a relation property and connect that property to the 'Tasks' database.

Next, configure a rollup property like so:

Original Formulas

Looking at the formulas of the "Sleep Tracker," there are three distinct properties:

  • Unwinding → Time to unwind before bed (1 hour before "Latest Sleep Time") → dateSubtract(prop("L.Sleep Time"), 1, "hours")

  • L. Sleep Time → Latest time to go to sleep dependent upon "Alarm Set" (7 hours before alarm) → dateSubtract(prop("Alarm Set"), 7, "hours")

  • Alarm Set → Time to wake up the next morning (6:00 AM) → dateAdd(prop("Date"), 30, "hours")

New Formulas With Inclusion Of Tasks Database

Using the new properties, here are modified formulas that give the original formulas more nuance.

  • Unwinding → if(contains(prop("Priority"), "Essay"), concat("⭕️ Look Over Essay" + " -- " + format(dateSubtract(prop("L.Sleep Time"), 1, "hours"))), if(contains(prop("Priority"), "Exam"), concat("⭕️ Meditate" + " --" + format(dateSubtract(prop("L.Sleep Time"), 1.5, "hours"))), if(day(prop("Date")) == 5, "🛌 Flexible", format(dateSubtract(prop("L.Sleep Time"), 1, "hours")))))

  • L. Sleep Time → dateSubtract(prop("Alarm Set"), 7, "hours")

  • Alarm Set → (day(prop("Date")) == 5) ? dateAdd(prop("Date"), 32.5, "hours") : dateAdd(prop("Date"), 30, "hours")

Video Tutorial

View Example In Notion