Script for processing Sleep Cycle data exports
I wrote this script to make it easy for me to turn my Sleep Cycle app data into visual sleep charts showing sleep and wake times and hours slept.
These charts are used to diagnose and manage sleep and circadian rhythm disorders.
This script is designed to work with this Google Sheets template.
-
Open the Google Sheets template link
-
Choose "File" > "Make a Copy"
-
Export your Sleep Cycle data — Instructions are here
-
Place the exported data file in the files directory (or edit the file path in
bin/process-chart.php
to point to your file location). -
Run
bin/process-chart.php
php -f bin/process-chart.php
-
Open the
files/sleep_chart_output.tdv
file in a text editor. -
Copy the contents of the file
-
Go to the Google Sheet, select cell A2, and paste. You should see a chart appear.
-
Move or rename the old
files/sleepdata.csv
file. -
Follow the same steps above to update your chart. Sleep Cycle always exports your entire sleep log history, so you can just paste over the previous data from the top.