Skip to content

Changing color with color code #546

Answered by f00stx
tromphakvoort asked this question in Q&A
Discussion options

You must be logged in to vote

The colour code can be (almost) directly decoded to an HSV color value, so if you know what color you'd like, you can also encode the correct color value (the resulting string is just the 3 segments of an HSV value, as hex, and then zero-padded):

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
}

// Bright green, #00FF00
hsv = {
    h: 120,
    s: 100,
    v: 100,
}

console.log(hsv2tuya(hsv)) // = 007803e803e8

Setting dps['24'] to the resulting value (007803e803e8) does the trick on my device (an LED strip in th…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by codetheweb
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #513 on November 30, 2021 18:42.