How To Call It
System is a global table: call its functions with a dot (System.<method>(...)), not a colon. Requires Macro Handler 1.0.62 or later.
Reads milliseconds since device boot, including sleep. It is not the wall clock.
Documented for app version 1.0.64Updated:
System is a global table: call its functions with a dot (System.<method>(...)), not a colon. Requires Macro Handler 1.0.62 or later.
In system flow, design steps as observe first and act second when the API can affect device state.
Takes no arguments; extra arguments return nil. Uses nonnegative SystemClock.elapsedRealtime and resets at reboot. Stopped execution, read failure or a negative result returns nil. It is not sleep-excluding uptimeMillis or a date/time value.
Uses no settings service and requests no permission. This pure monotonic clock read is also available on the main UI thread. Wall-clock or time-zone changes do not change it; do not compare readings from different boots.
Automation.check({kind="leaf",leafType="time_since_boot",durationMs=60000,comparisonMode="above"}) tests the same sleep-inclusive duration as a condition. It does not create a timer or persistent trigger.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local elapsed = System.getDeviceUptime()
if elapsed ~= nil then print("Milliseconds since boot", elapsed) endFrom foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local elapsed = System.getDeviceUptime()
if elapsed ~= nil then print("Milliseconds since boot", elapsed) endlocal stepOk = true
local elapsed = System.getDeviceUptime()
if elapsed ~= nil then print("Milliseconds since boot", elapsed) end
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local elapsed = System.getDeviceUptime()
if elapsed ~= nil then print("Milliseconds since boot", elapsed) end
end)
if not ok then
print("API step failed: System.getDeviceUptime: " .. tostring(err))
requestStop()
end-- In system flow, design steps as observe first and act second when the API can affect device state.
local function run_getdeviceuptime_step()
local elapsed = System.getDeviceUptime()
if elapsed ~= nil then print("Milliseconds since boot", elapsed) end
end
local ok, err = pcall(run_getdeviceuptime_step)
if not ok then
toast("Step failed")
print(err)
endlocal elapsed = System.getDeviceUptime()
if elapsed == nil then error("Device uptime unavailable") end
print(elapsed / 60000, "minutes since boot")