peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

RGB from lightStatusWithRGB is not corrected #112

Closed yene closed 7 years ago

yene commented 7 years ago

hi peter

I know it may not be possible I just wanted to hear your opinion on this issue. When getting the RGB of a newer color bulb the reported value is Orange instead of red.

state = lightState.create().on().rgb(255, 0, 0);
api.setLightState(5, state).then(displayResult).done();
api.lightStatusWithRGB(5).then(displayResult).fail(displayError).done();
    "rgb": [
      235,
      96,
      27
    ],
peter-murray commented 7 years ago

Hi,

The RGB values are a little tricky to deal with as the Hue system really does not support them directly.

When you specify an RGB value, you have to convert it into an HSL value that is supported by the light. Each light type made by Phillips has a different set of value for the colours that it can reproduce, and there are some rather complicated conversions that get applied from the RGB values into what the light can support.

If you supply values outside the range that can be supported, then the Hue bridge/light will clip the values to the closest it can support so this can result the desired values being passed in being further modified outside of the library.

When I read the values back and provide the RGB in the state, the conversion is applied in reverse from the HSL values. This is just an approximation as the lights do not support real RGB values, but should be very close to what you requested, within the realms of the actual colours that the light can support.

With all this in mind, when you ask for an RGB value, what you get is as close to what the light can produce within the limits for the specific light (which is why I do not support this in a group setting). The RGB state value returned from the light itself is as close to what I can determine by converting the HSL value into the RGB space.

If you are setting red and getting orange for the light itself, not just from the API result, them please send me the details for the light (use the info function for the bridge) and I can take a look at it and see if there may be an error in the conversions going on.

Thanks, Peter

yene commented 7 years ago

Here is my light. the RGB is orange. The HSL values is a red.

{
  "state": {
    "rgb": [
      235,
      96,
      27
    ],
    "on": true,
    "bri": 72,
    "hue": 737,
    "sat": 237,
    "effect": "none",
    "xy": [
      0.6484,
      0.3309
    ],
    "ct": 153,
    "colormode": "xy",
    "reachable": true
  },
  "type": "Extended color light",
  "modelid": "LCT007",
...
}

The RGB state value returned from the light itself is as close to what I can determine by converting the HSL value into the RGB space.

But in the code you convert XY to RGB instead of converting HSL to RGB. (maybe the HSL value were not correct 2 years ago and a firmware update fixed it)

yene commented 7 years ago

Ah nevermind I just did more testing, and the HSB value also is different from the actual light, and cannot be relied on.

peter-murray commented 7 years ago

Sorry, it converts into xy colour space not HSL... I wrote it so long ago, but what I said still holds true if you substitute HSL for XY.

I will take another look at the code and lights, as I am working on updating the library to use native promises and remove the Q promise library. RGB is a real tricky one as the lights really don't directly support it.