Skip to content

Instantly share code, notes, and snippets.

@signaleleven
Last active December 1, 2019 15:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save signaleleven/cb06038d8c38f4c0e6d6d46484a7d611 to your computer and use it in GitHub Desktop.
Save signaleleven/cb06038d8c38f4c0e6d6d46484a7d611 to your computer and use it in GitHub Desktop.
Boblight - yeelight
#THIS CODE IS TERRIBLE. It's a proof of concept, not a finished product.
from yeelight import *
import sys
import time
bulb2 = Bulb(sys.argv[1])
bulb = Bulb(sys.argv[2])
time.sleep(0.5)
try:
bulb.stop_music()
except Exception as e:
pass
try:
bulb2.stop_music()
except Exception as e:
pass
time.sleep(0.5)
bulb.start_music()
bulb2.start_music()
counter = 0
dimming = 50
while True:
input = sys.stdin.readline()
#print(input)
inputData=input.split(' ')
counter = (counter + 1) % 1000
if(len(inputData)>5 and (counter % 1 == 0)):
dim = 3
r = float(inputData[0])*dim
g = float(inputData[1])*dim
b = float(inputData[2])*dim
brightness = int((0.299*r + 0.567*g + 0.134*b)*dimming)
print(brightness)
if brightness < 5:
bulb.turn_off()
else:
bulb.turn_on()
bulb.set_brightness(brightness-5)
bulb.set_rgb(int(r*255), int(g*255), int(b*255))
r = float(inputData[3])*dim
g = float(inputData[4])*dim
b = float(inputData[5])*dim
brightness = int((0.299*r + 0.587*g + 0.114*b)*dimming)
if brightness < 10:
bulb2.turn_off()
else:
bulb2.turn_on()
bulb2.set_brightness(brightness-9)
bulb2.set_rgb(int(r*255), int(g*255), int(b*255))
[global]
interface 127.0.0.1
port 19333
[device]
name xi
type popen
channels 6
interval 900000
output python3 /home/pi/boblight/ambixi.py 192.168.XXX.XX 192.168.XXX.YY
[color]
name red
rgb FF0000
[color]
name green
rgb 00FF00
[color]
name blue
rgb 0000FF
[light]
name xia
color red xi 1
color green xi 2
color blue xi 3
hscan 0 30
vscan 0 5
[light]
name xib
color red xi 4
color green xi 5
color blue xi 6
hscan 70 100
vscan 0 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment