Skip to content

Changing color with color code #513

Closed

Description

@tromphakvoort

Hi, this isn't probably the place to ask this question but I don't really know where else to ask it.
When I request the data from my RGBW lamp it returns dps 20-26 with 24 containing the color, brightness and saturation in colour mode.
I can't seem to understand how this code is build. I've read a lot of issues on GitHub with possible explanations but none have completely worked for me.

My Bulb returns the following data:

dps: {
    '20': true,
    '21': 'colour',
    '22': 1000,
    '23': 1000,
    '24': '015303e803e8',
    '25': '000e0d0000000000000000c80000',
    '26': 0
  }

From what i can find on the internet the color is in HSV separating the values with a 0.

What i can't seem to figure out is why my color code contains letters and what they mean.

Could anyone help me out with this or point me in the right direction?

Activity

  1. kueblc commented on Sep 8, 2021

    @kueblc
    Collaborator

    From what i can find on the internet the color is in HSV separating the values with a 0.

    Not quite, the zero is not a separator.

    What i can't seem to figure out is why my color code contains letters and what they mean.

    This is a hexadecimal representation of color. Two hexadecimal digits represent one byte, so the challenge is figuring out which byte controls which channel.

    I would send the bulb values with one byte set at a time and observe what it does, ie
    ff0000000000
    00ff00000000
    0000ff000000
    ... and so on.

  2. duncte123 commented on Oct 18, 2021

    @duncte123
    Contributor

    I ran into the same issue, from my findings it seems that the 3e803e8 dictates the brightness and the colour/white sliders. The first 5 bits are for the colour.

  3. f00stx commented on Nov 17, 2021

    @f00stx

    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 the "Arlec GridConnect" family).

  4. tromphakvoort commented on Nov 30, 2021

    @tromphakvoort
    Author

    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 the "Arlec GridConnect" family).

    Did this in javascript but got a different result. My result is 0078640640 I'm new to binary and hexadecimal so I dont completely understand how you got your result and why mine is different.

    This is the code I used:

    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;
    }
    
    hsv = {
      h: 120,
      s: 100,
      v: 100
    };
    
    console.log(hsv2tuya(hsv));
  5. codetheweb commented on Nov 30, 2021

    @codetheweb
    Owner

    @tromphakvoort looks like you're missing the required parenthesis, i.e you're doing tuyaS = 10 * hsv["s"].toString(16).padStart(4, "0") instead of tuyaS = (10 * hsv['s']).toString(16).padStart(4, '0').

    Converting to a discussion.

  6. Repository owner locked and limited conversation to collaborators on Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions