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
‎[{'class': 'filter-property', 'value': 'Type'}, {'class': 'filter-operator', 'value': 'is'}, {'class': 'filter-benchmark', 'value': 'Sleep'}]
‎[{'class': 'filter-property', 'value': 'Start Date'}, {'class': 'filter-operator', 'value': 'is in the last'}, {'class': 'filter-benchmark', 'value': '1', 'glyph': '', 'UUID': ''}, {'class': 'filter-unit', 'value': 'day', 'glyph': '', 'UUID': ''}]
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
LIST
SCRIPTING
‎Set ‎Repeat Item ‎to ‎List ‎in ‎Dictionary
VARIABLES
‎Set variable ‎Dict ‎to ‎Dictionary
VARIABLES
‎Get ‎Repeat Item
SCRIPTING
‎End If
SCRIPTING
‎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
SCRIPTING
‎End If
SCRIPTING
‎End If
MISSING
‎calculateexpression Under Construction
MATHS
‎Round ‎Raw hours ‎to ‎Ones Place
Mode
‎Always Round Down
MISSING
‎calculateexpression Under Construction
MATHS
‎Round ‎Calculation Result ‎to ‎Ones Place
Mode
‎Normal
TEXT
‎Rounded Minutes ‎ for ‎Repeat Item ‎ hours and ‎Rounded Hours ‎ minutes
SCRIPTING
‎End If
SCRIPTING
‎End Repeat
MATHS
‎Calculate the ‎Sum ‎of ‎Asleep
SCRIPTING
‎If ‎Sum ‎has any value
MISSING
‎calculateexpression Under Construction
MATHS
‎Round ‎RawH ‎to ‎Ones Place
Mode
‎Always Round Down
MISSING
‎calculateexpression Under Construction
MATHS
‎Round ‎Minutes ‎to ‎Ones Place
Mode
‎Normal
TEXT
‎Rounded Minutes ‎ hours ‎Rounded Hour ‎ minutes
SCRIPTING
‎Otherwise
TEXT
‎No detailed sleep data found
SCRIPTING
‎End If
TEXT
‎Item from List ‎- ‎Repeat Results ‎ Total Time Asleep: ‎If Result ‎Item from List
DOCUMENTS
‎Show ‎Text ‎in Quick Look

Showcuts

Magic Vars

Screenshot

Submitted Anonymously 10 months ago

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

Visit iCloud (iOS)

Copy iCloud Link

Scan QR Code

0