Login About Gallery
Last Night's Sleep
COMMENT
Made by: mvan231 Originally created before advanced sleep tracking was available in WatchOS 9 / iOS 16. Updated in 2022 for the inclusion of these sleep stages Updates for showing Hours and Minutes of total sleep time vs x.y hours V4 - Updated calculation method to use seconds instead of relying on the sum method - Handling added for when detailed sleep data isn't available
CALENDAR
Subtract
1
days
from
Current Date
DATE
Specified Date
Adjusted Date
18:00
TEXT
{ "In Bed":[], "Core":[], "REM":[], "Deep":[], "Awake":[] }
VARIABLES
Set variable
Dict
to
Text
HEALTH
Find
All Health Samples
where
All the following are true
Type
is
Sleep
Start Date
is in the last
1
day
Sort by
Start Date
Order
Oldest First
Limit
SCRIPTING
Repeat with each item in
Health Samples
NOTHING
Nothing
SCRIPTING
If
Date
is less than
Repeat Item
SCRIPTING
Get
Value
for
Repeat Item
in
Dict
CALENDAR
Get time between
Repeat Item
and
Repeat Item
in
Seconds
SCRIPTING
Set
Repeat Item
to
List
in
Dictionary
VARIABLES
Set variable
Dict
to
Dictionary
VARIABLES
Get
Repeat Item
End If
End Repeat
SCRIPTING
Get
First Item
from
Repeat Results
SCRIPTING
Get
Last Item
from
Repeat Results
FILES
Filter
Dict
Sort by
Name
Order
A to Z
Limit
SCRIPTING
Repeat with each item in
Files
SCRIPTING
Get
Value
for
Repeat Item
in
Dict
MATHS
Calculate the
Sum
of
Dictionary Value
SCRIPTING
If
Sum
is greater than
0
SCRIPTING
If
Repeat Item
is not
In Bed
SCRIPTING
If
Repeat Item
is not
Awake
VARIABLES
Add
Sum
to
Asleep
End If
End If
calculateexpression Under Construction
MATHS
Round
Raw hours
to
Ones Place
Mode
Always Round Down
calculateexpression Under Construction
MATHS
Round
Calculation Result
to
Ones Place
Mode
Normal
TEXT
Rounded Minutes
for
Repeat Item
hours and
Rounded Hours
minutes
End If
End Repeat
MATHS
Calculate the
Sum
of
Asleep
SCRIPTING
If
Sum
has any value
calculateexpression Under Construction
MATHS
Round
RawH
to
Ones Place
Mode
Always Round Down
calculateexpression Under Construction
MATHS
Round
Minutes
to
Ones Place
Mode
Normal
Otherwise
TEXT
No detailed sleep data found
End If
DOCUMENTS
Show
Text
in Quick Look

Showcuts

Magic Vars

Screenshot

Submitted Anonymously a month ago

This is an old shortcut, so some variables might be missing!

Visit iCloud (iOS)

Copy iCloud Link

Scan QR Code

0