codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 332 forks source link

Setting brightness overrides color / set multiple properties only applies last #625

Closed C00kieGamez closed 1 year ago

C00kieGamez commented 1 year ago

It seems when setting the brightness of the device it overrides the previous commands and reverts to white without any color

Function to convert hsv

function hsv2tuya(hsv) {
    tuyaH = hsv['h'].toString(16).padStart(4, '0')
    tuyaS = (10 * hsv['s']).toString(16).padStart(4, '0')
    tuyaV = (10 * hsv['v']).toString(16).padStart(4, '0')

    return tuyaH + tuyaS + tuyaV
}

Works fine with changing the color of the device to be orange

frontRight.on('connected', () => {
    console.log('Connected to device!');

    frontRight.set({ dps: 21, set: 'colour' }); //sets 21 to be colour
    hsv = {
        h: 25,
        s: 100,
        v: 100
    }
    frontRight.set({ dps: 24, set: hsv2tuya(hsv) }); //sets color of device to be orange

});

exact same thing except at the end the brightness is changed to 20%

frontRight.on('connected', () => {
    console.log('Connected to device!');

    frontRight.set({ dps: 21, set: 'colour' }); //sets 21 to be colour
    hsv = {
        h: 25,
        s: 100,
        v: 100
    }
    frontRight.set({ dps: 24, set: hsv2tuya(hsv) }); //sets color of device to be orange

   frontRight.set({ dps: 22, set: 200 }); //sets brightness to 20%
});

In the above example it changes to orange for about a quarter of a second but then goes back to white and changes the brightness

The same occurs using the set multiple found in the documentation [https://codetheweb.github.io/tuyapi/index.html] :

frontRight.on('connected', () => {
    console.log('Connected to device!');

    frontRight.set({ dps: 21, set: 'colour' }); //sets 21 to be colour
    hsv = {
        h: 25,
        s: 100,
        v: 100
    }
    frontRight.set({
        multiple: true,
        data: {
            '20': true, //turns device on
            '21': 'colour', //changes to color
            '22': 1000, // changes brightness to full
            '24': hsv2tuya(hsv) // changes to color
        }
    });
});

In this case, since the color change is after, the brightness is overridden and is never changed (switching the order makes the bulb turn white and change brightness, overriding the color)

I cant find a away to change the brightness without it first changing to white and then setting the color when I would prefer for it to stay a color and change its brightness without turning white. Any ideas why?

Apollon77 commented 1 year ago

From what I know the "brigthness" of color is part of the HSV value, so for colour mode it needs to be set as part of hsv. brightness will change the color mode to "white only".

C00kieGamez commented 1 year ago

From what I know the "brigthness" of color is part of the HSV value, so for colour mode it needs to be set as part of hsv. brightness will change the color mode to "white only".

Yep your right, I'm not used to HSV (was thinking it was more like RGBA where HSV is the color and then there is a separate value for alpha or brightness) and it turns out the V, or sometimes called B is the brightness! modifying that value and checking the brightness slider in the app shows that it's exactly that. Thanks!