Repository navigation
feat(biometrics): opt in to capacitance presence on other Pods - #12
Merged
Merged
Conversation
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.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, soDOMINANCE_RATIOgave 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
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_inputsreturns(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 oncapSense2ignores the switch.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.UnexplainedUseGuardstill 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.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
capSensefiles through the liveStreamProcessor. 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'sconfirmation.tsandoffWhenUp.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 inrhythms-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.
Across the 12 side-nights:
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
HeardUncheckedLiveTestintest_stream_presence.py:Also new tests in
test_stream_helpers.py(the inputs, the refresh, the declined calibration, the log lines) andtest_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 intest_features.py.Server:
npx tsc --noEmitandnpm run lintare clean. Thesrc/features,src/db,src/routes/settings,src/jobs/rhythmsandsrc/8sleeptests andserverStatus.test.tsran: 1,069 passed, 5 failed. All 5 also fail on dev on Windows (NetworkManager scan cache, migration checksums). The fullnpm teststops in the shell-script tests on Windows.App:
npx tsc -bandnpm run lintare clean, andnpx vitest runpasses 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