feat(windows): enable Night Light on a sunset-to-sunrise schedule - #738
Merged
Conversation
Adds run_onchange_41-set-night-light.ps1, which turns Night Light on with a sunset-to-sunrise schedule at strength 50 (3850 K). Night Light has no supported API; Windows persists it as two REG_BINARY CloudStore values holding Microsoft Bond CompactBinary v1 payloads. The script implements enough of that codec to decode the existing blobs, change only the fields it owns, and re-encode them, so the sunset/sunrise times Windows derives from the machine location are preserved byte for byte. Schedule mode is encoded by field presence: field 0 (schedule_enabled) is set and field 10 (set_hours_mode) is omitted. The on/off state is derived from the cached sunset/sunrise window rather than force-toggled, so Windows keeps managing the transitions. All writes stay in HKEY_CURRENT_USER and the script is idempotent. Verified against a live Windows 11 install: both captured blobs round-trip byte for byte through the codec. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
What
Adds
home/.chezmoiscripts/windows/run_onchange_41-set-night-light.ps1, which enables Windows Night Light on a sunset-to-sunrise schedule at strength 50 (3850 K). Pass-Strength 0..100for a different intensity.Why it needs a binary codec
Night Light has no supported configuration API. Windows persists it as two
REG_BINARYCloudStore values underHKEY_CURRENT_USER:default$windows.data.bluelightreduction.settings\...default$windows.data.bluelightreduction.bluelightreductionstate\...Both are Microsoft Bond CompactBinary v1 payloads inside a CloudStore envelope. Rather than hardcoding a blob (which would clobber the sunset/sunrise times Windows computes from your location), the script implements just enough of the codec to decode, mutate only the fields it owns, and re-encode.
Format reference: kvnxiao/win-nightlight-cli registry format docs (evidence grade 3 — reverse-engineered, not a Microsoft contract).
Design notes
0(schedule_enabled) is set totrue, and field10(set_hours_mode) is omitted — that is how Windows represents "Sunset to sunrise".0-> 6500 K (no effect),100-> 1200 K, so50stores 3850 K.BT_INT8is a raw byte, not a zigzag varint (unlikeBT_INT16/BT_INT32). Getting this wrong silently corrupts the hour/minute time blocks.HKEY_CURRENT_USER, the script honours-WhatIf, and it is idempotent (second run reports 0 changes).Verification
-Strength 60-> 3320 K,-Strength 50-> 3850 K, third run ->0 setting(s) changed.tests/powershell/NightLight.Tests.ps1: 62 new tests covering the Bond primitives, CloudStore wrapper, both payload schemas, strength conversion, night-window detection, andSet-NightLightConfigurationagainst a fake registry..ps1(enforced by a test).Docs
docs/customization.mdgains a "Windows Night Light" section documenting the registry layout, encoding rules, evidence grade, and reversal steps.