arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
462 stars 104 forks source link

Workaround for correct coldwhite/warmwhite in RGBWW mode, integration needed #608

Open wu7zh opened 1 year ago

wu7zh commented 1 year ago

Hi, I'm trying to work with a LVWIT Gu10 bulb (RGB+CCT) that is running OpenBeken. I got everything working so far and am using RGBWW mode. The problem:

When I select a color temperature in HomeKit, mqttthing publishes #0000007878 for the coldest white, and #00000016dd for the warmest white. This means I never reach the real coldest or warmest color that the bulb is capable of. I tried to do some javascript math to correct the error, but then dimming becomes a problem, as I need to substract values.

Ideally I want mqttthing to publish #000000ff00 for the coldest white, and #00000000ff for the warmest, any way to do this?

wu7zh commented 1 year ago

Okay I figured it out (kinda) Came up with a function that can backcalculate the values.

In case anyone needs it:

            "setRGBWW": {
                "topic": "cmnd/obk1F5988B2/led_basecolor_rgbcw",
                "apply": "return message.slice(0,-4) + Number(Math.round(( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) - ( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) * ( ( parseInt(message.slice(-2),16) - parseInt(message.slice(-4,-2),16) ) / ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) / 209 ) ) ))).toString(16).padStart(2,0) + Number(Math.round(( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) * ( ( parseInt(message.slice(-2),16) - parseInt(message.slice(-4,-2),16) ) / ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) / 209 ) ))).toString(16).padStart(2,0)"
            },
wu7zh commented 1 year ago

Reopening this as it would be very nice to have a official integration of this behavior instead of this workaround. Also in case anyone uses the code above, it needs to be modified to catch a NaN error when applying RGB values.

        "setRGBWW": {
            "topic": "cmnd/<YOUR_ID>/led_basecolor_rgbcw",
            "apply": "return  (message.slice(-4) = '0000') ? message : message.slice(0,-4) + Number(Math.round(( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) - ( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) * ( ( parseInt(message.slice(-2),16) - parseInt(message.slice(-4,-2),16) ) / ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) / 209 ) ) ))).toString(16).padStart(2,0) + Number(Math.round(( 255 * ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) * ( ( parseInt(message.slice(-2),16) - parseInt(message.slice(-4,-2),16) ) / ( ( parseInt(message.slice(-4,-2),16) +  parseInt(message.slice(-2),16) ) / 255 ) / 209 ) ))).toString(16).padStart(2,0)"
        },