Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
C00kieGamez opened this issue Mar 24, 2023 · 2 comments

Comments

@C00kieGamez
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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!

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

No branches or pull requests

2 participants