All articles
13 min read

Orthosomnia

Fixing my sleep made me realize how much OSA is neglected for "non-cliché" people - then it made me obsessive about it

By Aloïs

Listen to this article

AI-generated narration · English

Orthosomnia is a term used to describe a situation where a person becomes overly focused on the sleep data shown by a sleep tracking device. Instead of helping them sleep better, this concern with getting the "right" sleep score or number can make them more anxious and may even contribute to insomnia (source : https://en.wikipedia.org/wiki/Orthosomnia)

Contents


During my college studies, I became aware that something wasn't working well in my body T_T

Middle school and high school were barely ok-ish, but in college things got harder. You explore way more difficult concepts, have to organize yourself, think about waaaaaaay more things !

Almost sleeping in exams, having legit 0 mental energy, it quickly became unbearable

Over the years, this became my “personality”. I just accepted that I was the tired guy, that this was how I was. I still remember the day I asked my cousin if it was “normal” to have migraines and headaches every morning.
Of course, he answered no.

Then it really clicked, and I started trying to optimize my sleep (orthosomnia [1]). I read a ton of posts on Reddit, especially on the brainfog sub [2] (great place to find people with chronic fatigue to discuss with if you ask me)

Trying everything

I tried everything I could:

But I was still waking up completely tired every other day.

For a long time, I thought I just had a hyperactive brain (I've never been able to nap) and no OSA, and that's why I tried all those GABA things, etc. But then I learned that sedatives can increase the number of apneas and their severity [11].

One thing that helped was to move to a calmer flat. I knew I had a very light sleep, so minimizing the external factors helped.

Society tries to sells too much things to desperate people :<

2023 : A false negative

In 2023, I went through a polygraphy [12] (air, HR, movement) which measured an AHI [13] of ~10.


A polygraphy is not a PSG [14]. It only looks at your breathing, oxygen and heart rate… not your brain. So it has no idea if you're actually asleep, and it misses the micro-awakenings that end a lot of hypopneas. Result: it tends to underestimate the AHI [15].

An AHI of ~10 is already mild OSA [16] (it starts at 5 per hour)… but the doctor told me I was in normal ranges.

I started to become more and more frustrated, because I couldn't understand what was going on.

I worked as a freelancer. The days were horrible; I was tired all the time. I had a lot of digestive issues. I couldn't understand why I needed twice the time to heal from my injuries, getting sick every few months…

My mood was horrible too. I was grumpy, irritable for nothing… not the best version of me, at all.


And I couldn't remember stuff. What I said to someone, a conversation I had, technical details at work, etc. etc. New information just didn't stick, it was super hard to encode anything. I was kind of “absent”: there, but not really there. And anyone who went through it knows that you cannot “escape” it.

All of this, plus personal issues, led to a burnout. I hurt some people alongside and feel bad every day for it. I think emotions, impulsivity, etc. are highly related to sleep.

I wish I had solved this earlier

2026 : The second diagnosis

3 years and a breakdown later, my psychiatrist and I noticed that I often mentioned my sleep during medical interviews. After a session with him, we agreed I had to check my sleep again.

I went to a clinic and saw a sleep specialist, who gave me the stuff for an at-home PSG [14].

LLM : [insert copyright free PSG stuff here]

I don't know why, but I had to wait 3 months between the exam and the results... which led to more frustration.

However, the AHI went from 10 to 26, and 32 during REM [17]. This time I really believed I had the answer to my fatigue !

I was prescribed a MAD [18]. When I was a child, I got braces for my teeth, and then a retainer, but I didn't like it at all and wasn't able to sleep with it.

So I mentioned the CPAP [19], and he told me it wouldn't be possible to get it because my OSA isn't severe enough.

A bit frustrated after all those years and the last 3 months waiting for the results, I just asked GPT if it was safe to use CPAP at home with my settings.

I figured out it was not so “hard” to set, unless you have a very specific condition (which I assumed wasn't my case).

Not medical advice!

And then I (re-entered) the world of orthosomnia.

I immediately looked for a second-hand CPAP on a classified ad website. I found one (ResMed AirSense 10) near where I live, instantly bought it and was able to get it that evening

Being back, I started it using LLMs [21] to put the most “generic” settings for the first night.

  • First night: quite special: I had aerophagy [22], but felt I was more rested than usual.
  • Second night: lowered the pressure.
  • Third night: fixed the mask… and it paid ! No more headache !

I've also identified that one of the supplements I was taking interacted with my other medication, which slowed my CPAP settings exploration (be careful if you take any; I used to underestimate the effects they could introduce).

Then, from ~27 Sept., I found really good settings.

Now, my mask is a ResMed AirFit F20, with a ClimateLineAir tube.
I almost don't have any OSA anymore. A few central apneas [23], but I'm trying to reduce their number every night.

My energy levels are between 6 and 9 every day !! when before they would be between 1 and 6 on average.

We can see in the 2 following images (AutoSleep app, “quality sleep” metric) how irregular my sleep was before vs now (I got the CPAP on the 31st of August) :)

“Quality sleep” from April to the end of July

“Quality sleep” from August

What I did to find my settings

LLMs are getting increasingly smart and I do consider that “intermediate” level digital is solved by them (not always the most efficient way but it's another problem).

As an full stack data dev I've always been interested in machine learning, deep, etc. Being able to understand how it works and what it's capable of doing is truly a strength today as :

  • Everything interacts with APIs
  • A lot of IoT devices expose data via BLE
  • You can add SSH to your mobile devices

⇒ LLM can thus interact with everything.

Basically, I have my own set of self-hosted apps. At first I helped someone I know to have its own coaching track app: found TraceApps (worth checking out)

The “xTrace” naming staid : thus the one for sleep is named SleepTrace. :D

Data pipeline: 8 sources, mostly streamed live, feed a Raspberry Pi; a GPU PC computes the night and two LLMs summarize it; an LLM agent reads the private website to fine-tune the CPAP and sleep settings

One night, every signal on one clock, next to the infrared video (mock data)
Zoomed on a wave of central apneas: every breath, every flagged event (mock data)
Deep dive: one wave, breath by breath, next to the brain waves (mock data)
What happens around an apnea, averaged over every event (mock data)
The week view: averages and the seven nights side by side (mock data)
Every data source, night by night
One night, every signal on one clock, next to the infrared video (mock data)

How the loop works

Every day, the run builds my night pages. Then I open Claude Code and ask the agent to read them: CPAP airflow, events, EEG stages, oxygen, video… everything on the same clock. It tells me what it sees, I change one setting, and the next nights tell us if it worked. Simple.

Five periods of CPAP use: AHI 12.5, 21.2, 14.5, 8.8, 7.6; central index 9.6, 13.4, 13.4, 7.5, 6.0; obstructive index 2.0, 4.5, 0.4, 0.9, 0.4; hours per night 4.8, 5.5, 3.6, 5.3, 6.1.

What's left? Mostly central apneas. Today I asked the agent to do a deep dive on 3 nights to investigate further the CAs.
Looks like they come in waves (one every ~38 s), mostly right after a big breath or a micro-awakening: when I fall back asleep after putting the mask back on, during REM, and sometimes when the machine climbs to 11–12 cmH₂O at the end of REM.


Though my central apnea index already went from ~14/h (mid-Sept) to ~6/h.

Next test: EPR from 2 to 1 (or off) for a week… and we'll see.

My sleep lab, device by device

ResMed AirSense 10 AutoSet

ResMed AirSense 10 AutoSet · CPAP

A few hundred $, second-hand

Use: CPAP therapy; airflow (25 Hz), pressure, leaks and apnea flags.

Reliability: Reported apnea-count correlation with sleep-lab measurements: r = 0.87–0.95 [26]. No sleep/wake detection.

Muse S Athena

Muse S Athena · EEG headband

$475

Use: Sleep stages, brain waves, head position and movement.

Reliability: Muse sleep-staging validation: κ = 0.76 [27] against PSG. SleepTrace uses a separate YASA-based algorithm coded by Claude Opus 5.5.

Wellue Checkme O2 Ultra

Wellue Checkme O2 Ultra · wrist oximeter

~$150

Use: Blood oxygen and pulse, every second (streamed to the Pi).

Reliability: Blood oxygen precision: ±2%.

Apple Watch Ultra 2

Apple Watch Ultra 2 · smartwatch

~$800

Use: Sleep stages, heart rate, HRV, breathing disturbances.

Reliability: Sleep staging evaluated against PSG by Apple (white paper [28]). An independent comparison of six wearables [29] reported κ = 0.53 and underestimation of deep sleep and wake.

Tapo C100

Tapo C100 · IR camera

~$30

Use: Body movement, sound, chest movement from the video (streamed to the Pi).

Reliability: Video-analysis algorithm coded by Claude Opus 5.5 and compared with CPAP data. No formal validation.

Old Android phone on a chest belt

Old Android phone on a chest belt · accelerometer + mic

~$50

Use: Breathing effort, movement, sleep position and sound (recorded since 6 Oct).

Reliability: Algorithm coded by Claude Opus 5.5. Correlation with CPAP airflow: r ≈ 0.95 on one test night. No formal validation.

Apollo AIR-1

Apollo AIR-1 · Home Assistant

~$110

Use: Bedroom CO₂, temperature, humidity, particles.

Reliability: Sensirion SCD40 CO₂ accuracy: ±(50 ppm + 5 %) (datasheet [30]).

Old Lenovo tablet

Old Lenovo tablet · bedside screen

Use: Displays the previous night's summary and charts at the bedside.

For the nerds: the tech stack
  • Language: Python 3.13, NumPy, SciPy, Pillow and Matplotlib.
  • Pipeline: bronze - silver - gold layers; each stage is cached by a fingerprint of its code and inputs, and only reruns when one of them changes.
  • Orchestration: Prefect 3 flow, started by hand in the morning: the Pi keeps the data, a worker on my PC runs the heavy stages on its GPU and sends the results back.
  • Streaming: the Pi records the camera's RTSP stream and the oximeter over Bluetooth, and pulls the phone's files over SSH.
  • Video: FFmpeg with CUDA decoding; movement, sound and breathing effort computed with NumPy.
  • CPAP: home-made parser for ResMed EDF files (25 Hz flow and pressure, events), using OSCAR [31]'s ResMed loader as a reference.
  • EEG: raw Bluetooth LE packets decoded with OpenMuse; sleep stages with YASA and MNE.
  • Oximeter: Viatom Bluetooth protocol, written with bleak.
  • Chest belt: accelerometer and mic recorded on the phone with Termux; the sound is synced to the camera's audio.
  • Night summary: Opus 5.5 and Sol 6.1 both draft it, then Opus merges the two.
  • Other sources: Apple Health Auto Export JSON (sent with LocalSend) and the Home Assistant REST API.
  • Front-end: static, self-contained HTML pages with vanilla JS canvas charts (synced cursor and zoom), plus phone and tablet views, published atomically as immutable releases.

100% vibe-coded, and a bit more than that

SleepTrace is 100% vibe-coded. The whole pipeline I just talked about, the sensors, the parsers, the pages… all of it. Opus 5.5 and Sol 6.1 did very well.

And as a dev, of course (I still sometimes) read through the code. It does feel quite special to watch a tool this specific to my life take shape like that :)

It makes me optimistic about the future of medicine. Being able to bring together what happens between appointments, better understand what we're going through, show up with data instead of an “I'm tired”… I feel like there's so much we can do. After all those years of not understanding, it gives me a bit of hope :)

I don't have the lifestyle you'd typically associate with OSA. I work out, eat well, don't drink, don't smoke, don't even snore… so for years, sleep apnea just wasn't on my radar.

That's the part I keep thinking about. If I'd had the tech to figure this out when I was younger, I really don't think I would have had the same life.

My studies, work, relationships… all those years where I thought being exhausted was just who I was. I can't redo them, but the idea that someone else might get an answer earlier makes me pretty optimistic :)

What's next

Still waiting for my MAD [18].

Sources
  1. Wikipedia: Orthosomnia
  2. Reddit: r/brainfog
  3. Wikipedia: Mouth taping
  4. Singh S et al. Blue-light filtering spectacle lenses for visual performance, sleep, and macular health in adults. Cochrane Database Syst Rev, 2023
  5. Wikipedia: Light therapy
  6. Wikipedia: Melatonin as a medication and supplement
  7. Wikipedia: Glycine
  8. Wikipedia: Withania somnifera
  9. Wikipedia: Magnesium glycinate
  10. Wikipedia: Gamma-Aminobutyric acid
  11. Wikipedia: Obstructive sleep apnea (Medication and lifestyle)
  12. Wikipedia: Sleep study (Home sleep test)
  13. Wikipedia: Apnea–hypopnea index
  14. Wikipedia: Polysomnography
  15. Kapur VK et al. Clinical Practice Guideline for Diagnostic Testing for Adult Obstructive Sleep Apnea: an AASM Clinical Practice Guideline. J Clin Sleep Med, 2017
  16. Wikipedia: Obstructive sleep apnea (Criteria)
  17. Wikipedia: Rapid eye movement sleep
  18. Wikipedia: Mandibular advancement splint
  19. Wikipedia: Continuous positive airway pressure
  20. Wikipedia: Obstructive sleep apnea
  21. Wikipedia: Large language model
  22. Wikipedia: Aerophagia
  23. Wikipedia: Central sleep apnea
  24. Wikipedia: API
  25. Wikipedia: Bluetooth Low Energy
  26. Comparison of ResMed AutoSet (version 3.03) with polysomnography in the diagnosis of the sleep apnoea/hypopnoea syndrome. Eur Respir J, 1997
  27. Lanthier M et al. Assessing the performance of a portable electroencephalographic sleep monitor against level 1 polysomnography. Sleep Advances, 2025
  28. Apple. Estimating Sleep Stages from Apple Watch (white paper), October 2025
  29. Schyvens AM et al. A performance validation of six commercial wrist-worn wearable sleep-tracking devices for sleep stage scoring compared to polysomnography. Sleep Advances, 2025
  30. Sensirion. SCD40 CO₂ sensor datasheet
  31. OSCAR: Open Source CPAP Analysis Reporter