Open Sispheor opened 6 years ago
There is an example in the documentation:
# Set lights using name as key
for light in ['Kitchen', 'Bedroom', 'Garage']
light_names[light].on = True
light_names[light].hue = 15000
light_names[light].saturation = 120
Here, you can see that the hue of the lights in the Kitchen, Bedroom, and Garage is changed to 15000, which is sort of a greenish-yellow color. However, this is just one of the ways to change the colors.
This wrapper is simply using the Philips Hue Rest API and sending the appropriate JSON to the appropriate endpoints. To learn more about the Hue API and the various ways to set the color, you'll need to register at https://developers.meethue.com. The good news is that it's easy and free.
It should be added to the README.md front page of your repository.
Hi, there's an open pull request which need some more docs and tests to be ready for merge, I'm happy to support here!
Without digging too much into the codebase I figured out I can control my bulb's color by setting the xy
attribute as they seem to use the xy color space.
from random import random
# ...
for light in ['Kitchen', 'Bedroom', 'Garage']
if light_names[light].type != 'Color light':
continue
light_names[light].on = True
light_names[light].xy = [random(), random()] # [0.0..1.0, 0.0..1.0]
Feel free to contribute a pull request if you want to add some documentation ! Otherwise the API documentation on Philips Hue's site will indicate you how to change colors.
Le sam. 6 avr. 2019, à 16 h 44, Kevin Morris notifications@github.com a écrit :
Is this ever going to be addressed?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/studioimaginaire/phue/issues/125#issuecomment-480536209, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEu9FRSEharoJb_Ft8jOGM3CscAqSZuks5veQcYgaJpZM4Rc-g1 .
Hello, I've done some testing on the xy color mode and I feel like I have a semi-idea of what's going on.
It seems like x refers to the red color percentage and y refers to the green color percentage. The rgb values add up to 1 and blue is 1-(r+g)
i.e. when xy is 0,0 it would be:
red : 0, green : 0, blue : 1 - (0 + 0)
Here's some code I wrote to convert a color hex code to a xy list:
def convertColor(hexCode):
R = int(hexCode[:2],16)
G = int(hexCode[2:4],16)
B = int(hexCode[4:6],16)
total = R + G + B
if R == 0:
firstPos = 0
else:
firstPos = R / total
if G == 0:
secondPos = 0
else:
secondPos = G / total
return [firstPos, secondPos]
According to the example code, I would set the color with this line:
# Set color to pink, hex code FF00E7
b.set_light(1,'xy',convertColor('FF00E7'))
Hope this somewhat helps!
Quick Edit: I use the light strips which only supports the xy mode, this isn't accurate but gets a general idea of the color I think
Here's how I'm doing it
helper = ColorHelper()
rgb = helper.hex_to_rgb(colour)
h, s, v = colorsys.rgb_to_hsv(rgb[0], rgb[1], rgb[2])
b = get_api()
b.set_light(light_id, 'hue', int(round(h * 65535)))
b.set_light(light_id, 'sat', int(round(s * 255)))
b.set_light(light_id, 'bri', int(round(v)))
You can find the ColorHelper class here but it's trivial to recreate
I haven't found any doc or examples about changing the color of a lamp. I can see in the code some clues that indicate that is supported. Can anyone push a snippet ?
Thanks !