Skip to content

Map color temperature onto 6500–2000 K instead of 1–300 mireds - #31

Open
stefan-schweiger wants to merge 1 commit into
athombv:masterfrom
stefan-schweiger:fix/color-temperature-range
Open

stefan-schweiger wants to merge 1 commit into
athombv:masterfrom
stefan-schweiger:fix/color-temperature-range

Conversation

@stefan-schweiger

Copy link
Copy Markdown

Fixes #30

Problem

Homey's light_temperature (0 coldest … 1 warmest, without Kelvin values) is exposed as 1–300 mireds, which controllers show as ~3,333 K to 1,000,000 K. In Home Assistant almost the whole color temperature slider is "cold", and warm whites fall outside the range.

Change

  • Map 0–1 onto 153–500 mireds (6,500 K–2,000 K) everywhere it's converted: the initial value, Homey → Matter updates and moveToColorTemperature.
  • coupleColorTempToLevelMinMireds uses the new minimum.
  • Lights that haven't reported a temperature yet start at 250 mireds (4,000 K). The previous ?? 150 fallback never applied: scaleNumber(null, …) returns the minimum, and undefined gives NaN.

Existing installations

Lights from existing installations keep working after the update; this PR includes the migration for them.

The bridge saves each light's color temperature, and Matter.js restores the saved value when the light starts. Values saved with the old range can be below the new minimum (e.g. 1 mired), so HomeyColorControlServer.initialize() moves a saved value into the new range before Matter.js validates it. Without this step, such a light would fail to initialize after updating. The second test covers this with a light that saved 1 mired.

Tests

New tests/color-temperature.test.mjs:

  • the mapping in both directions, including a light without a value yet;
  • a light that saved 1 mired with the old range still starts and can be controlled after updating.

Both tests fail on master; all 30 tests pass.

The Kelvin values remain approximate, as Homey doesn't report a light's real range.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SzwF97RnBPp9K8AduC4A9q

Homey's light_temperature (0 coldest, 1 warmest) was mapped onto
1–300 mireds, which controllers show as roughly 3,333 K to
1,000,000 K. Map it onto 153–500 mireds (6,500 K to 2,000 K) instead,
in both directions, with 4,000 K for lights without a temperature yet.

Matter.js restores a stored color temperature over the Endpoint's
properties, so a value stored with the old range (e.g. 1 mired) would
fail validation and leave the light unusable. Keep a stored value
within the new range when the light starts.

Fixes athombv#30

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SzwF97RnBPp9K8AduC4A9q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Color temperature is exposed as 1–300 mireds (≈3,333 K to 1,000,000 K)

1 participant