HomeAboutExperienceProjectsContactBlog
RésuméDex0/17
← Projects

Goodnight

Apple Health sleep stages in, a phased overnight bed-temperature plan out. On device.

WIND-DOWNDESCENTCOOL PLATEAUREM HOLDWAKE26C+1.5C-3C-2.1C+1CDEEPREM20:0022:0000:0002:0004:0006:0008:00

Drag the times to replan the night. This is the engine's plan before it has any Health data; the cycles assume 15% deep and 22% REM sleep.

Warm wind-down, a fast descent, a cool plateau through the deep-sleep-heavy first cycles, a cool hold through REM (70% of the cool depth, following a 2025 trial rather than the usual 'warm during REM' advice), then a wake ramp gated by your predicted core-temperature minimum. Lights out 23:00, wake 07:00, neutral 26 °C.

Goodnight reads your nightly deep, REM and core stages from Apple Health, learns your timing and sleep architecture, and builds a five-phase temperature plan for a cooling pad or smart AC. It grew out of Sleep Optimizer, a web tool and iPhone app that did the same from WHOOP exports.

Why

Smart-bed temperature schedules are locked to specific hardware and cloud accounts, and the manual ones leave you guessing what to set. The data to do better already sits in Apple Health. Goodnight turns it into a plan you can export to Shortcuts, a cooling pad, or an air conditioner, with every setpoint explained.

How it's put together

IPHONEAPPLEHEALTHHEALTHKITSERVICEAPPMODELSLEEPCORENIGHTSFEATURESPROFILESRI GATEENGINEEXPORTAPP GROUPJSONSIRIINTENTSHOMEWIDGETEXPORTPAD / AC
Everything runs on the phone: the app pulls sleep stages from Apple Health and hands them to SleepCore, a Swift package with no side effects that builds the plan. The widget and Siri read a JSON copy of it, and the only thing that leaves the device is the list of timed setpoints you export to Shortcuts, a cooling pad or an AC.

Trade-offs

Bounded rules over a learned model. Every setpoint carries a rationale and the evidence behind it, so the plan explains itself. Rules have explicit caps and don't depend on order. The downside: It can't discover patterns no one wrote a rule for.

A pure engine in its own Swift package. No side effects, so the scheduling logic is tested without a simulator or the app. The downside: Some state is duplicated in the app layer.

Medians over your good nights. Robust to the occasional 3 a.m. outlier. The downside: Needs a few qualifying nights before it says anything personal.

Fine print

Not medical advice. Temperature effects on sleep stages are modest, and the app says so.

Timezone-aware nights (travel mode, DST tests), a confidence meter, a widget, and a Live Activity for the next setpoint.

Next: Habit FormedA gesture-driven habit tracker whose habits can check themselves off from Apple Health.

Year
2026
Platform
iPhone and web
Status
Working app + web v1
Code
Goodnight sourceSleep Optimizer source
Built with
Swift, SwiftUI, HealthKit, WidgetKit, ActivityKit, App Intents, Next.js, TypeScript
  • 5 temperature phases
  • 8 bounded personalization rules
  • 87 tests across both Swift engines
  • 0 servers