led: add led_colorBlendLimit to limit blended RGB colors - #2243
Open
ryan-ronnander wants to merge 1 commit into
Open
ryan-ronnander wants to merge 1 commit into
ryan-ronnander wants to merge 1 commit into
Conversation
- 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
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. |
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:
Works the same: only the RGB blend gets limited. |
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.
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 andrgb_calmay 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, likeled_dimmerScale, so it adds no config field. It is applied tofinalColors, 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: 1and a Tuyacolormaxpvalue in the device's stock config (visible in its Tuya Cloudcutter profile underdevice_configuration, or in a firmware dump). To match stock, setled_colorBlendLimitto Tuyacolormaxp/ 100:0(default)colorpfunis 0 or missing), or you prefer the brighter blends0.51colormaxp: 100, by far the most common1.5colormaxp: 150, seen on a few ceiling lights and downlights2*colormaxp: 200, the highest stock value2.53or more* Stock Tuya firmware clamps
colormaxpto 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:
colormaxpled_colorBlendLimitBulbs 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:
led_colorBlendLimit 1FFFFFF)FF0000)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:
From your own full flash dump, with bk7231tools, which decrypts that storage:
On the filament bulb above, both print
{"colorpfun":1,"colormaxp":100,"gmwr":100,"gmwg":70,"gmwb":75}. Tuyacolorpfun: 1with Tuyacolormaxp: 100meansled_colorBlendLimit 1. The Tuyagmwr/gmwg/gmwbvalues are the per-channel ceilings, whichled_gammaCtrl cal 1.0 0.7 0.75already reproduces.If this looks like a useful feature, I can follow up with a small docs PR: a note in
docs/led_gamma_control.mdand a short how-to for matching a bulb's stock Tuya light settings, plus a related bit from a recent PR (the single valueCTRangefrom #2236).Related:
SM2135_Currentfix for the bulb tested above)