Skip to content

fix(light): fix color-temp out-of-range errors and migrate to ATTR_COLOR_TEMP_KELVIN#587

Open
ZakiZtraki wants to merge 1 commit into
albertogeniola:masterfrom
ZakiZtraki:fix/color-temp-kelvin-conversion
Open

fix(light): fix color-temp out-of-range errors and migrate to ATTR_COLOR_TEMP_KELVIN#587
ZakiZtraki wants to merge 1 commit into
albertogeniola:masterfrom
ZakiZtraki:fix/color-temp-kelvin-conversion

Conversation

@ZakiZtraki

Copy link
Copy Markdown

Problem

Meross bulbs that support white/colour-temperature mode (e.g. MSL120D) return error code 5000 when Home Assistant sends a temperature payload outside the accepted range of 1–100:

Returned error: {'error': {'code': 5000, 'detail': 'Out of range.
  rgb value range: 0X0~0XFFFFFF, temperature range: 1~100, luminance range: 1~100'}}

The root causes were:

  1. No clamping – the mired-to-Meross conversion (100 - norm_value * 100) produced negative values or values > 100 when the input fell outside the assumed min/max mired range.
  2. Deprecated API – the code used ATTR_COLOR_TEMP (mired-based), which HA has deprecated and will remove in HA Core 2026.1, producing warnings in the log.
  3. No explicit kelvin range – neither entity class declared _attr_min_color_temp_kelvin / _attr_max_color_temp_kelvin, so the HA UI slider used HA's broad defaults instead of the Meross-supported range.

Changes

  • Migrate to ATTR_COLOR_TEMP_KELVIN in both LightEntityWrapper and DiffuserLightEntityWrapper, eliminating the HA 2026.1 deprecation warning.
  • Simplify conversion – work directly in Kelvin (no mired inversion), mapping the device's 2700–6500 K range linearly to Meross's 1–100 scale.
  • Clamp output with max(1, min(100, value)) as a safety net for edge-case inputs or floating-point drift.
  • Declare kelvin range (_attr_min_color_temp_kelvin = 2700, _attr_max_color_temp_kelvin = 6500) on both entity classes so the HA slider stays within supported bounds.
  • Replace color_temp with color_temp_kelvin on LightEntityWrapper to match the new API.

Compatibility

No existing configuration is broken:

  • RGB and HS colour paths are untouched.
  • Brightness/luminance path is untouched.
  • The fix applies only to the colour-temperature conversion branch.
  • The 2700–6500 K range covers all known Meross white-spectrum bulbs.

Tested devices

Model Hardware Firmware White mode Colour-temp slider RGB mode
MSL120D 2.0.0 2.1.5 ✅ (no more Out of range errors)

If you test this on additional devices, please comment below and I will update the table.

…KELVIN

Meross API rejects temperature payloads outside 1-100 (error code 5000
'Out of range'). The previous mired-based conversion produced negative
values when the input fell outside the assumed min/max range.

Changes:
- Replace deprecated ATTR_COLOR_TEMP (mired) with ATTR_COLOR_TEMP_KELVIN
  across both LightEntityWrapper and DiffuserLightEntityWrapper, silencing
  the HA 2026.1 deprecation warning.
- Convert Kelvin directly to the Meross 1-100 scale using the device's
  known range (2700-6500 K), removing the intermediate mired inversion.
- Clamp the result with max(1, min(100, value)) as a safety net for
  edge-case inputs or floating-point drift.
- Add _attr_min_color_temp_kelvin / _attr_max_color_temp_kelvin (2700-6500 K)
  to both entity classes so the HA UI slider stays within the supported range.
- Replace color_temp property (mired) with color_temp_kelvin (Kelvin) on
  LightEntityWrapper to match the new API.

Tested on: MSL120D hw2.0.0 / fw2.1.5 (white + colour-temperature modes
now work; RGB mode unaffected).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant