Skip to content

feat(biometrics): opt in to capacitance presence on other Pods - #12

Merged
LTimothy merged 3 commits into
LTimothy:devfrom
Ali-Al1:feat/cap-presence-unchecked
Nov 17, 2026
Merged

LTimothy merged 3 commits into
LTimothy:devfrom
Ali-Al1:feat/cap-presence-unchecked

Conversation

@Ali-Al1

@Ali-Al1 Ali-Al1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Why

On any Pod but a Pod 5, New sleep tracking runs the capacitance detector only to decide when vitals are taken. The presence the server hears (Smart Schedule, When I get up, presence auto-off, the in-bed indicator) stays on the vibration sensor, by design (d5a8bf9, de0d873). That caution makes sense for a format nobody has checked. It also leaves a Pod 3 with nothing better when the piezo detector can't separate the sides.

Seen on a Pod 3 (3.6.1, capSense) with New sleep tracking on and both sides' levels learned (about 1,000 counts each). On the night of 16 to 17 Nov, the left sleeper was in bed on their own side from 21:18 to 07:05 UTC. The partner's movement reached the left piezo at 1.5 to 4 times the left sleeper's own signal, so DOMINANCE_RATIO gave the bed to the right side. The server heard the left side as empty, so the cool-down waited for the 2 hour limit (22:30), and When I get up turned the side off at the set time instead of when they got up. The capacitance detector, running alongside for vitals, logged the left side correctly all night: entry at 21:18:46, exits at 07:05:38 and 07:10:24.

What

  • A new feature flag, uncheckedCapPresence ("Capacitance presence on other Pods (beta)"), off by default. Its row sits under New sleep tracking in Settings > Features and is disabled until New sleep tracking is on. It has a manifest entry (depends_on: ['biometrics-v2']) and appears in the Features count.
  • stream._presence_v2_inputs returns (params, baselines, format, True) on an unchecked format when the switch is on. It needs the same conditions as before: both sides' learned levels and once-a-second piezo. A Pod 5 on capSense2 ignores the switch.
  • In StreamProcessor.use_presence_v2, the server hears the capacitance detector when the format is checked or the inputs say so. The processors are then used as on a Pod 5, with no quiet pair.
    • The UnexplainedUseGuard still runs on any unchecked format. When capacitance places nobody in a bed that is in use for 10 of 15 minutes, the vibration sensor takes the server back before presence auto-off could act.
    • A declined calibration is remembered without the switch, so turning the switch on or off does not retry it.
    • Changing the switch starts presence over, as a change of format does.
  • Log lines: the switch line now says which detector the server hears. A running detector that takes new calibration now logs it; before, it took it silently. That silence is what made this Pod look as if it had never switched: it switched at 18:31 on 16 Nov, as soon as the right side's level was first learned, and later level updates left no trace.

Checked against real nights

I replayed six nights (18:00 to 10:00 UTC, 11 to 16 Nov) from the Pod's RAW piezo and capSense files through the live StreamProcessor. There were two runs: one with presence on piezo, which is what the server hears today, and one with this switch on, both using the Pod's current calibration. The presence each run posted went through dev's confirmation.ts and offWhenUp.ts, with bedtime 20:30 and set off 07:00. The replay agrees with the Pod's own record. On 16 Nov the replayed transitions match the live journal's piezo and capacitance lines to within 3 s, and the piezo replay reproduces 13 of the 16 real decisions in rhythms-history.jsonl.

The "Capacitance" column is the per-minute capacitance rise at half the learned level or more. Times are UTC; "confirmed" is the cool-down start and "got up" is the off time.

Night Side Capacitance Piezo (today) This switch on
11 Nov left in 20:50, up 06:57 (sat 07:05 to 07:09) confirmed 21:09, got up 07:22 confirmed 21:10, off at set time 07:00
12 Nov left in 23:31 (two 19 min stints before) confirmed 21:55, got up 07:20 2 h limit 22:30, got up 07:18
13 Nov left in 21:14, a rise on the left all morning to 10:00 confirmed 21:33, set time 07:00 confirmed 21:34, kept on to the 10:00 limit
14 Nov left in 23:38, up 09:11 2 h limit 22:30, got up 07:26 2 h limit 22:30, got up 09:22
15 Nov left in 21:11, up 06:46 confirmed 21:30, got up 07:31 confirmed 21:31, set time 07:00
16 Nov left in 21:18, up 07:05 (back 07:08 to 07:10) 2 h limit 22:30, set time 07:00 confirmed 21:38, got up 07:21
11 Nov right in 21:15, up 07:06 confirmed 21:34 (3 of 12 tick phases), got up 07:20 confirmed 21:35 (12 of 12), got up 07:17
12 Nov right in 21:39, up 07:07 confirmed 22:09, got up 07:20 confirmed 21:59, got up 07:18
13 Nov right empty until 00:20, up 06:01 confirmed 21:42, kept on to the 10:00 limit 2 h limit 22:30, set time 07:00
14 Nov right in 21:53, up 09:22 confirmed 22:13, got up 09:36 confirmed 22:13, got up 09:33
15 Nov right in 21:17, up 07:07 confirmed 21:31, got up 07:19 confirmed 21:37, got up 07:17
16 Nov right in 21:21, up 07:10 confirmed 21:44, got up 07:23 confirmed 21:41, got up 07:21

Across the 12 side-nights:

  • Minutes the side was reported in bed while its capacitance rise was under a fifth of its level: 300 with piezo, 35 with this switch. Nearly all of the 35 fall in the 60 s exit dwell after a real exit. One run of about 10 minutes on the morning of 14 Nov had the partner moving on the other side.
  • Minutes reported empty while capacitance was at half the level or more: 1,899 with piezo, 8 with this switch.
  • Crosstalk: there were 555 minutes in which one side was empty beside an occupied partner. On the empty side, the partner put the capacitance rise at a median of 65 counts and a 99th percentile of 291 (left) and 385 (right), against entry levels of 400 and 375. The 10 minutes above entry all came in the minutes just before a real entry on that side. Capacitance never put an empty side in bed.
  • The guard never fired.

Two mornings change in the other direction. On the mornings of 14 and 15 Nov (a weekend), capacitance shows weight on the left side long after 07:00, so the side stays on (to 10:00, and to 09:22). With piezo it went off at 07:00 and 07:26. That is the rule working as intended if someone was in bed. The data cannot say who it was.

Tests

  • Biometrics: new HeardUncheckedLiveTest in test_stream_presence.py:

    • the server hears capacitance;
    • a light sleeper beside a heavier one is heard in bed where piezo loses them;
    • an empty side beside one person is never heard;
    • the guard hands the server back and the calibration stays declined either way;
    • the switch works on and off mid-night.

    Also new tests in test_stream_helpers.py (the inputs, the refresh, the declined calibration, the log lines) and test_features.py.

  • python -m pytest biometrics/__tests__/: 932 passed, 69 failed, 1 error. dev at b00e16a on the same Windows machine: 915 passed and exactly the same 69 failures and 1 error (NATS, logger paths, sleep-detector fallbacks, recorded legacy vitals output). The touched suites pass, apart from one existing Windows path test in test_features.py.

  • Server: npx tsc --noEmit and npm run lint are clean. The src/features, src/db, src/routes/settings, src/jobs/rhythms and src/8sleep tests and serverStatus.test.ts ran: 1,069 passed, 5 failed. All 5 also fail on dev on Windows (NetworkManager scan cache, migration checksums). The full npm test stops in the shell-script tests on Windows.

  • App: npx tsc -b and npm run lint are clean, and npx vitest run passes 2,017 tests. Two tests and one suite timed out under full-run load (AppRoutes, MissedAlarmBanner, UpdateFreeSleepButton) and pass when run on their own.

  • Not checked: CI on Linux, and a live night on the Pod with the switch on (the Pod was read-only for this work). Not tested on a Pod 4, or on a Pod 3 with only one sleeper.

Written with an AI coding tool and checked against real data from a Pod 3: RAW recordings, journals and Smart Schedule history.

🤖 Generated with Claude Code

Ali-Al1 and others added 3 commits November 17, 2026 18:09
On any Pod but a Pod 5, New sleep tracking runs the capacitance detector
only to decide when vitals are taken, and the server keeps hearing the
vibration sensor. On a Pod 3 where one sleeper's movement reaches the
other side's piezo more strongly than that side's own, the piezo
detector gives the whole bed to the heavier sleeper, so Smart Schedule
never confirms the lighter one in bed and When I get up misses them
getting up, while capacitance places both correctly.

A new switch, uncheckedCapPresence (Settings > Features, under New
sleep tracking, off by default), lets an owner who has checked it on
their own nights hand that presence to the capacitance detector, as on
a Pod 5. It waits for the same learned levels and once-a-second piezo
as before. The guard keeps running, so when capacitance places nobody
in a bed in use for 10 of 15 minutes the vibration sensor takes the
server back and the calibration stays declined whichever way the
switch is set. Changing the switch starts presence over, as a change
of format does.

The stream now logs which detector the server hears when it switches,
and logs when a running detector takes new calibration, which it did
silently before.
…recorded nights

The Features text said tested, though the nights were replayed from recordings. The manifest now says the guard does not catch one sleeper missed beside a detected partner. A test also covers the side piezo had in bed when the switch turns on mid-night.
A Pod 5 always hears capacitance presence, so the switch did nothing there. The Features count leaves it out on a Pod 5 too.
@LTimothy
LTimothy merged commit 7ec5cda into LTimothy:dev Nov 17, 2026
10 checks passed
@LTimothy

Copy link
Copy Markdown
Owner

Thanks again! This shipped in v3.9.0 (beta) under Settings > Features, off by default: https://github.com/LTimothy/nightstand/releases/tag/v3.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants