-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpywal_lights.py
65 lines (55 loc) · 1.94 KB
/
pywal_lights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
from phue import Bridge
hexlist = []
#Location of colors file for pywal
with open ('~/.cache/wal/colors', 'rt') as filecol:
for hexcol in filecol:
hexlist.append(hexcol)
def hex_to_rgb(value):
value = value.lstrip('#')
return list(int(value[i:i+2], 16) for i in (0, 2, 4))
#Primary Light Colour
#hexlist[0] = color0 hexlist[1] = color1 and so on for terminal colours.
rgbp = hex_to_rgb(hexlist[1])
#Secondary Light Colour
rgbs = hex_to_rgb(hexlist[2])
frgbp = [x / 255.0 for x in rgbp]
frgbs = [x / 255.0 for x in rgbs]
frp = float(format(frgbp[0]))
fgp = float(format(frgbp[1]))
fbp = float(format(frgbp[2]))
frs = float(format(frgbs[0]))
fgs = float(format(frgbs[1]))
fbs = float(format(frgbs[2]))
def rgb_to_xy(red, green, blue):
red = pow((red + 0.055) / (1.0 + 0.055), 2.4) if red > 0.04045 else (red / 12.92)
green = pow((green + 0.055) / (1.0 + 0.055), 2.4) if green > 0.04045 else (green / 12.92)
blue = pow((blue + 0.055) / (1.0 + 0.055), 2.4) if blue > 0.04045 else (blue / 12.92)
x = red * 0.649926 + green * 0.103455 + blue * 0.197109
y = red * 0.234327 + green * 0.743075 + blue * 0.022598
z = green * 0.053077 + blue * 1.035763
x = x / (x + y + z)
y = y / (x + y + z)
return [x, y]
xyp = rgb_to_xy(frp,fgp,fbp)
xys = rgb_to_xy(frs,fgs,fbs)
#Philips Hue Bridge IP
b = Bridge('***.***.***.***')
#Connect to Bridge
b.connect()
#Get API
b.get_api()
#Get Light Names
lights = b.get_light_objects('name')
#Set Light Colour (xyp = primary, xys = Secondary)
lights["Living room main"].xy = xyp
lights["Living room lamp"].xy = xys
#Set Lights ON
lights["Living room main"].on = True
lights["Living room lamp"].on = True
#Set Light Brightness 100%
lights["Living room main"].brightness = 255
lights["Living room lamp"].brightness = 255
#Set Light Saturation
lights["Living room main"].saturation = 200
lights["Living room lamp"].saturation = 200