Skip to content

led: add led_colorBlendLimit to limit blended RGB colors - #2243

Open
ryan-ronnander wants to merge 1 commit into
openshwprojects:mainfrom
ryan-ronnander:led-color-blend-limit
Open

ryan-ronnander wants to merge 1 commit into
openshwprojects:mainfrom
ryan-ronnander:led-color-blend-limit

Conversation

@ryan-ronnander

@ryan-ronnander ryan-ronnander commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Tuya advertises this in its lighting firmware as a "Power Limit" feature (Tuya lighting solutions): "The power of a cold/warm white ceiling light can be limited to the power of a single way or to the total power of two ways, and this applies to RGB ceiling lights."

Many bulbs ship stock Tuya firmware that caps the total drive of the three RGB channels, not just each channel on its own. After gamma and white balance it adds up R+G+B and, when the sum is over the limit, scales all three down together so the hue does not drift. A single saturated color is never reduced, but blends are, so white mixed from RGB draws about the same power as pure red.

OpenBeken can only limit each channel individually (led_gammaCtrl cal), never their sum. On those bulbs a blend near white drives all three LEDs at full at once and draws more than double the stock power, which on the bulb tested below is above its 7 W rating. That is how it showed up in the first place: switching that bulb from its warm filament at full to RGB white at full, the RGB white looked clearly brighter than the 2000 K filament, where on stock it is the dimmer of the two.

This adds led_colorBlendLimit [limit], which caps that sum: in RGB mode, R+G+B after gamma and rgb_cal may not exceed the given multiple of one channel at full. At 1, the stock value, the RGB LEDs together never draw more than one of them fully lit. 0, the default, keeps the current behavior. It is a runtime setting for the startup command, like led_dimmerScale, so it adds no config field. It is applied to finalColors, so PWM, the I2C LED drivers, smooth transitions, TuyaMCU and pixel strips all get it.

When to set it. Stock Tuya firmware turns this limit on per product, with Tuya colorpfun: 1 and a Tuya colormaxp value in the device's stock config (visible in its Tuya Cloudcutter profile under device_configuration, or in a firmware dump). To match stock, set led_colorBlendLimit to Tuya colormaxp / 100:

Value When
0 (default) The stock firmware did not limit blends (Tuya colorpfun is 0 or missing), or you prefer the brighter blends
0.5 Possible, but not recommended. It caps all three RGB channels together at 50% of one channel at full, so pure red, green or blue drop to half brightness, and every blend gets that same half channel to share. Anything below 1 dims saturated colors like this.
1 Tuya colormaxp: 100, by far the most common
1.5 Tuya colormaxp: 150, seen on a few ceiling lights and downlights
2* Tuya colormaxp: 200, the highest stock value
2.5 Possible, but not recommended, and above any stock value. Only full-strength blends near white get trimmed. On a bulb without channel ceilings, full RGB white runs each LED at about 83% (2.5 / 3). On the bulb tested below, whose ceilings add up to 2.45 channels, it never kicks in.
3 or more Never takes effect, the same as 0: three channels at full is the most a blend can ask for. 2.99 is the highest value that still trims anything (full white to about 99.7%)

* Stock Tuya firmware clamps colormaxp to 100-200, so 2 is the highest stock value, and the Cloudcutter profiles only show 100 and 150. Higher values are allowed and simply limit less. The setting can only reduce output, never drive the LEDs harder than with it off.

It is not tied to one LED driver: stock firmware enables it on PWM bulbs as well as BP5758D, SM2135, SM2235 and BP1658CJ ones. A few examples with it on:

Product Driver Tuya colormaxp led_colorBlendLimit
SYLVANIA 40A19FILCCLWIFI SM2135 100 1
Merkury MI-BW210-999WW BP5758D 100 1
LSC Smart Connect 2578539 BP5758D 100 1
Globo Connor 41386-30SH PWM 100 1
Amico DC08-DR6 downlight PWM 150 1.5

Bulbs whose stock firmware leaves it off, such as the Feit OM60, Lenovo SE-242DC and Gosund WB5, should keep the default.

A preliminary attempt at matching OpenBeken database entries to Cloudcutter profiles by model number turned up roughly 55 likely matches, and around 15 of those look like bulbs whose stock firmware enables this limit, so they probably run brighter in color mode than stock today. Whether those templates should pick this up once it is released is your call; I can share the list if that helps.

Tested on a SYLVANIA RGBW Color Filament A19 (BK7231N, SM2135, rated 7 W) with a Sonoff S31 upstream, full brightness, 12 readings each:

State Stock Tuya This build, limit off This build, led_colorBlendLimit 1
RGB white (FFFFFF) 3.8 W 8.09 W 3.9 W
Pure red (FF0000) 3.81 W 3.73 W 3.74 W
Filament white (2000 K) 6.58 W 6.70 W 6.70 W

With the limit on, RGB white drops to about the level of pure red, as on stock, and nothing else moves. A selftest covers the limit off, full white at 1 and 1.5, a saturated color, a blend under the limit and a blend over it.


Checking your own bulb. The limit lives in the bulb's Tuya user_param_key, which Tuya keeps in its encrypted flash storage, so searching a dump for the text finds nothing. Two ways to read it:

From the bulb's Tuya Cloudcutter profile, if it has one:

curl -fsS https://raw.githubusercontent.com/tuya-cloudcutter/tuya-cloudcutter.github.io/master/devices/<profile>.json \
  | jq -c '.device_configuration | if type == "string" then fromjson else . end | {colorpfun, colormaxp, gmwr, gmwg, gmwb}'

From your own full flash dump, with bk7231tools, which decrypts that storage:

bk7231tools dissect_dump -e -O ./dissect dump.bin
jq -c '{colorpfun, colormaxp, gmwr, gmwg, gmwb}' ./dissect/*_user_param_key.json

On the filament bulb above, both print {"colorpfun":1,"colormaxp":100,"gmwr":100,"gmwg":70,"gmwb":75}. Tuya colorpfun: 1 with Tuya colormaxp: 100 means led_colorBlendLimit 1. The Tuya gmwr/gmwg/gmwb values are the per-channel ceilings, which led_gammaCtrl cal 1.0 0.7 0.75 already reproduces.

If this looks like a useful feature, I can follow up with a small docs PR: a note in docs/led_gamma_control.md and a short how-to for matching a bulb's stock Tuya light settings, plus a related bit from a recent PR (the single value CTRange from #2236).


Related:

- Limits R+G+B in RGB mode, after gamma and rgb_cal, to a multiple of
  one channel at full, scaling all three together so the hue does not
  drift and a single saturated color is untouched
- Many bulbs ship stock Tuya firmware with this limit. On one such
  bulb, stock drew 3.9 W for white mixed from RGB at full brightness,
  the same as a single saturated channel. Without the limit that
  white measured 8.2 W, more than double, and OpenBeken had no way
  to hold it back
- Default 0 keeps the current behavior; 1 matches the stock limit.
  It is not saved, so set it in the startup command to keep it
@ryan-ronnander

Copy link
Copy Markdown
Contributor Author

Note though, that even with the new color blend limit, if flag 12 is used for remembering an RGB blend, the bulb comes up uncapped and "extra bright" for a split second before applying the limit.

@ryan-ronnander

Copy link
Copy Markdown
Contributor Author

Also gave this a quick test on a PWM bulb (SYLVANIA A19, BK7231T), just to make sure it works on something other than the SM2135:

State led_colorBlendLimit 0 led_colorBlendLimit 1
Warm white 9.35 W 9.37 W
Pure red 4.25 W 4.26 W
RGB white 8.15 W 3.46 W

Works the same: only the RGB blend gets limited.

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