Skip to content

Instantly share code, notes, and snippets.

@SergioSV96
Last active December 18, 2023 21:30
Show Gist options
  • Save SergioSV96/4118b7175ec16f953eb23a753af3a399 to your computer and use it in GitHub Desktop.
Save SergioSV96/4118b7175ec16f953eb23a753af3a399 to your computer and use it in GitHub Desktop.
A Hyperion UDP listener for LIFX bulbs! Just "pip install lifxlan --user" and run with "python3 hyperion_lifx.py PORT NAME"
import sys
import socket
import colorsys
import argparse
from lifxlan import LifxLAN
def search_lifx_bulb(name, lifx):
"""
Returns the LIFX device for the selected bulb name
"""
print("Discovering lights...")
# get devices
devices = lifx.get_lights()
print("\nFound {} light(s):\n".format(len(devices)))
for i, device in enumerate(devices):
try:
print(device.get_label())
if device.get_label() == name:
return device
except:
pass
sys.exit("Device not found")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Connect a LIFX bulb with Hyperion.ng')
parser.add_argument('PORT', type=int, help='the hyperion.ng udpraw port selected')
parser.add_argument('NAME', type=str, help="the LIFX bulb's name")
args = parser.parse_args()
# Arguments
port = args.PORT
name = args.NAME
# Connection to LIFX
lifx = LifxLAN()
device = search_lifx_bulb(name, lifx)
"""
SOCKET UDP CLIENT
"""
IP = "127.0.0.1" # LOCAL IP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((IP, port))
print("waiting on port:", port)
packet = bytearray(3)
while True:
data = s.recvfrom_into(packet)
hsv = colorsys.rgb_to_hsv(packet[0], packet[1], packet[2])
hsvk = [hsv[0] * 65535, hsv[1] * 65535, hsv[2] * 257, 3500]
device.set_color(hsvk, 0, True)
@SergioSV96
Copy link
Author

Hello again, I've been very caught up in other matters at home, but as far as the lifx strips/beams are concerned, I do believe you are correct with the LifxLan requisites for enabling multi-zone support.

And as you also stated, hyperion would need to be able to send the correct number of zones for the strips.

The hyperion part is really easy to do, just add more zones using their website UI, then we need to decode them properly on the script, do you want to do this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment