huey icon indicating copy to clipboard operation
huey copied to clipboard

RGB hex codes not working?

Open rikai opened this issue 11 years ago • 5 comments

Just recently got Hue light starter kit and was messing around with Huey.

All the various bits seem to work except setting the color based on a hex color code. I enter the code and it seems to go through fine, but it doesn't work. Setting H S B manually seems to work fine, but rgb seems to do nothing despite seemingly being successful... Any help would be greatly appreciated! :)

Titan:Desktop studio$ irb
1.9.3-p545 :001 > require 'huey'
 => true

1.9.3-p545 :018 > studio = Huey::Group.new(Huey::Bulb.find(1), Huey::Bulb.find(2), Huey::Bulb.find(3))
 => #<Huey::Group:0x007fdb9b1b1a10 @bulbs=[#<Huey::Bulb:0x007fdb9b029850 @id=1, @changes={:hue=>33196, :sat=>106, :bri=>245}, @name="Left", @on=true, @bri=245, @hue=33196, @sat=106, @xy=[0.4595, 0.4105], @ct=500, @transitiontime=nil, @colormode="ct", @effect="none", @reachable=true, @alert="none">, #<Huey::Bulb:0x007fdb9b024e18 @id=2, @changes={}, @name="Right", @on=true, @bri=254, @hue=14922, @sat=144, @xy=[0.4595, 0.4105], @ct=369, @transitiontime=nil, @colormode="ct", @effect="none", @reachable=true, @alert="none">, #<Huey::Bulb:0x007fdb9b0219e8 @id=3, @changes={}, @name="Center", @on=true, @bri=245, @hue=33196, @sat=106, @xy=[0.4595, 0.4105], @ct=369, @transitiontime=nil, @colormode="ct", @effect="none", @reachable=true, @alert="none">], @attributes_to_write={}>

1.9.3-p545 :026 > studio.rgb = '8FF1F5'
 => "8FF1F5"
1.9.3-p545 :027 > studio.save
 => [true, true, true]

The above does absolutely nothing.

rikai avatar Apr 12 '14 22:04 rikai

I've been testing this more over the past few days, and i was incorrect. It does in fact change the colors, the color i was testing was apparently just being calculated as being very similar to the default setting, which is odd, as i was trying #8FF1F5 from the readme to get aqua which should be noticeably different from the default setting i would think... So, it's definitely off from what it should be. For example, #00FF00, which should be pure green, gives me a pale yellow color, rather than anything remotely resembling a green... #0000FF gives a fairly light shade of blue instead of the deeper blue it should be and so on...

Now, this is my first experience with hue lights, so i'm unsure of the limitations and i may just be seeing that, but i'm pretty sure i saw much greener greens when messing around with the presets in the mobile app.

rikai avatar Apr 14 '14 19:04 rikai

So yeah, this is probably an artifact of the color conversion formula I use. I'm manually calculating this myself @ https://github.com/Veraticus/huey/blob/master/lib/huey/bulb.rb#L80 from a formula I'm fairly sure I found online somewhere... I would definitely appreciate help making it more accurate. Feel free to take a crack at it if you like, and if not hopefully it's something I'll be able to get to soon.

Veraticus avatar Apr 16 '14 21:04 Veraticus

@rikai The Hue does not take RGB colors, it requires CIE XYZ or Hue/Saturation/Brightness colorspace inputs: http://developers.meethue.com/1_lightsapi.html#16_set_light_state

See also: http://en.wikipedia.org/wiki/CIE_1931_color_space http://en.wikipedia.org/wiki/HSL_and_HSV

I'm pretty sure I had the same issue and gave up on RGB. I don't have any time to help out unfortunately :(

sodabrew avatar Apr 17 '14 06:04 sodabrew

I ran into the same problem. I wrote a ruby script to read Philips Ambilight values (RGB) and set my Hue accordingly (HSV) https://github.com/dschanoeh/AmbiHue. For the conversion I basically copied your code and tried to find the error that was causing the strange colours. I compared the results with what other RGB to HSV converters did and also reimplemented the algorithm - everything was fine. So I guess the problem is not the conversion but the fact that the bulbs are not covering the whole color spectrum but just a subset. This was pointed out here http://rsmck.co.uk/hue:

What's that I hear you say? Of course it's RGB... Well it is and it isn't. The sources within a Hue are not primary Red, Green and Blue as are used in other LED lighting products; The Red is a touch more 'orange', the Green is closer to a 'lime-green' and the Blue is closer to Violet. They remind me of the intermediate colours in the ETC Selador x7 colour system.

Why did Philips do this? Simple - it enables the Hue to produce much nicer whites (at any colour temperature) than a normal RGB fixture and also much nicer pastel shades, which are likely to be the most common use of Hue.

The problem (from our point of view) is you can't easily map RGB colours to Hue, nor can you mix them with other LED fixtures and expect the same results. It's also why the CIE 1931 co-ordinates don't work exactly as you might expect.

dschanoeh avatar Apr 18 '14 10:04 dschanoeh

So i was doing some searching around and i ran across this stack overflow question relating to the issue.

One of the replies to the thread gives some code on how he adapted to the color gamut, but more importantly links to a very detailed explanation in the iOS-OSX SDK adapted for the color gamut of the Hue Lights. Hopefully it'll give you some help and insight into the proper ranges, rather than having to do some guesswork. :)

rikai avatar Apr 19 '14 21:04 rikai