Inspiration

Most sleep apps answer the wrong question. They tell you how long you were in bed, draw a generic stage chart, and leave you to work out what any of it means for the next morning. But fatigue is personal, cumulative, and usually noticed only after it has already cost you something - a slow commute, a missed deadline, a bad training session, a near-miss on a late-night drive.

We kept returning to a simpler question: how tired am I actually, right now, relative to my own normal? That question matters most for students in exam week, athletes balancing training and recovery, drivers before a long trip, and night-shift and on-call workers whose schedules never let them fully reset. Existing tools either need expensive hardware, reduce sleep to duration alone, or send sensitive data to a server. We wanted a phone-only system that measures functional state, explains itself, and keeps the most sensitive signal - your face - on the device.

That became Somno: a privacy-first fatigue and recovery companion built around a personal Sleep Deprivation Index.

What Somno does

A check-in takes about thirty seconds and combines four evidence streams:

  • a short psychomotor vigilance task (PVT) measuring reaction speed, lapses, anticipations and variability;
  • an optional on-device face scan that derives ocular and facial features with Google ML Kit;
  • a Karolinska Sleepiness Scale rating from 1 to 9;
  • recent sleep history, summarised as a bounded sleep-debt model.

Somno fuses whatever it has into one transparent Sleep Deprivation Index (SDI), then turns that state into a recovery plan for tonight, a day-ahead alertness curve, longitudinal trends, and a Smart Wake alarm that looks for light sleep in the half hour before your target wake time. Sleep debt is tracked as three separate ledgers - lost wake time, lost NREM and lost REM - because they accumulate and repay at different rates.

Everything core works offline with no account. Signing in is optional and exists only so history survives a new phone.

How we built it

Somno is a React Native + Expo + TypeScript app with a deliberately modular inference pipeline: measurement - quality control - personal baseline - fusion - action.

  • App layer: React Native, Expo and TypeScript, with Zustand for local state and React Navigation for flows.
  • Vision: Expo Camera plus Google ML Kit for face detection; Somno computes temporal, geometric and photometric features on-device.
  • Native Android: a custom Kotlin Expo module for exact alarm scheduling, full-screen alarm UI, sound/vibration lifecycle, snooze, process-state persistence and reboot re-arming.
  • Data: AsyncStorage for local-first persistence; Supabase (Auth + Postgres) for optional sync, with merge rules, stable record identities and deletion tombstones.
  • Release: EAS and Gradle for Android builds, with GitHub Actions running type checks, logic tests and release-integrity checks.

We wrote logic and journey test harnesses for the parts that are easy to get subtly wrong: PVT behaviour, sleep debt, alertness, recovery modelling, facial validity, authentication, merge conflicts, exports and alarm logic. A separate end-to-end harness drives the real screens.

The math behind the score

The SDI is intentionally a transparent weighted linear model rather than an opaque model we could not inspect or defend. Each signal is converted into a within-person z-score (z_i) against the user's calibrated baseline:

$$ \mathrm{SDI} = \operatorname{clamp}!\left( 50 + 10 \sum_{i \in S} \tilde{w}i z_i,\; 0,\; 100 \right), \qquad \tilde{w}_i = \frac{w_i q_i}{\sum{j \in S} w_j q_j} $$

Base weights are

$$ w_{\text{PVT}} = 0.40,\quad w_{\text{face}} = 0.25,\quad w_{\text{KSS}} = 0.15,\quad w_{\text{debt}} = 0.20 $$

When a signal is missing, the set (S) shrinks and the remaining weights renormalise instead of silently filling in a zero. Objective signals also carry a precision term (q_i):

$$ q_{\text{PVT}} = \operatorname{clamp}!\left( \frac{n_{\text{trials}}}{9},\; 0.5,\; 1 \right), \qquad

q_{\text{face}}

\begin{cases} 1, & \text{eyelid measures available} \ 0.6, & \text{still-image photometry fallback} \end{cases} $$

Subjective sleepiness is converted to a z-score-like signal and weighted lowest, because self-report is known to drift from objective performance under chronic restriction:

$$ z_{\text{KSS}} = 0.5\left(5 - \mathrm{KSS}\right) $$

Sleep debt is converted with a clamp, because an unclamped term could reach twelve standard deviations and arithmetically pin the score to zero, making the reaction test, face scan and self-report irrelevant:

$$ z_{\text{debt}} = \max!\left( -3,\; -\frac{D_{\text{hours}}}{2} \right) $$

Bounding it keeps debt as one voice among four. The score is paired with a confidence label derived from how many signals actually contributed:

$$ C = \begin{cases} \text{high}, & |S| \ge 4 \ \text{medium}, & 2 \le |S| < 4 \ \text{low}, & |S| < 2 \end{cases} $$

Challenges we ran into

No validation set, and no appetite for fake precision. We have not scored this against polysomnography or a criterion measure of alertness, so we refused to present invented decimal weights as science. The final ordering follows what the literature can actually support, and the interface shows how many signals contributed and how confident the result is.

Missing and low-quality signals are the normal case. A five-trial alarm check-in is not the same measurement as a nine-trial daily test, and a scan in poor light is not the same as a clean one. We made quality part of the inference path: precision-adjusted weights, renormalisation, and an honest confidence label.

Android alarm reliability. Exact alarms, Doze, OEM battery managers, process death and reboots all conspire against a wake-up that must fire. We handled this in native Kotlin, including permission flows and reboot re-arming, rather than trusting a JavaScript timer.

Privacy versus sync. Raw camera frames are processed transiently and never stored or uploaded; only derived numeric features persist. Sync itself needed tombstones and deterministic merge rules so deletion and multi-device edits behave correctly.

Honesty as a product constraint. Somno is not a medical device. It does not diagnose sleep disorders, and it will not tell you that you are fit to drive. Keeping the copy, the confidence badge and the model aligned with what the code can actually prove was a recurring design pressure - and, we think, a feature.

What we learned

A small, inspectable model with explicit inputs is more useful than a sophisticated one nobody can explain. Personal baselines matter more than population thresholds. Quality-aware fusion is not a detail — it is the difference between a score that means something and a score that merely looks precise. And local-first architecture removes an entire class of privacy problems before they start.

What's next

Larger-scale validation against established alertness measures, richer recovery modelling across irregular schedules, deeper wearable-free sleep inference, and broader device coverage for the Smart Wake module. The long-term goal is the same as the starting question: make personal fatigue visible early enough to act on it.

Built With

Share this project:

Updates

Submission history