Release Lifx addon
#1
Hi everyone

I am the proud owner of some Lifx-bulbs. And immediatly I wanted to use these bulbs to adapt their colors while playing a movie. After some fiddeling around with the great boblight plugin, I had it working. It was working, but not very stable, and somewhat complex. I decided I wanted to make things more easy to run, and I created my own addon for Kodi.

It has been working great for me in the past few weeks. You can see a short example here: https://www.youtube.com/watch?v=3anynn4E4PE

The install instructions are on my blog: http://www.blinkingled.be/lifx-plugin-for-kodi/ and I currently host the addon on my own repository.

Feel free to leave any feedback on this addon. It is currently in a very basic state, but I'm comitted to add more features. Also if you are a developer and you would like to join forces on this one, let me know!

Enjoy the addon!
Reply
#2
Thank you I was excepting this for a while. Will try it as soon as possible! Great work!
HTPC homemade - BOX SilverStone Lascala LC17 - CPU Intel Core i3-3220T (2.8 GHz) - CM ASRock B75 Pro3 - HD Crucial M4 64 Go - CG ASUS GeForce GT 610 Low Profile 1 GB - RAM Corsair Vengeance Low Profile Blue Series 4 Go (2x2 Go) DDR3 1600 MHz CL9 - POWER Be Quiet! Power 7 400 W 80PLUS - REMOTE Harmony 650 - Frodo 12.2 XBMCbuntu Aeon-Nox 4.1.9 - MacPro 2010 - SMB
Reply
#3
This looks interesting, I had thought about doing the boblight for my setup, but don't like the setup/equipment needed to get it running. Have you thought about doing a 2/4 light setup?
Reply
#4
I've been looking, not all that closely, at these kind of wifi light bulbs but not only for Kodi.

I travel a lot and right now have mechanical timers running a few standard lamps but i'd like to have something a bit more random on the times they come on and off. These bulbs are pretty easy to control from a perl script cronned from linux box?
Reply
#5
Thanks for this. This is working great!

Unfortunately it's not working with multiple bulbs and as far as I can see there is no way of choosing which bulb(s) are doing the effect, right? Are there any plans of implementing support for multi-bulb setups?

Glad there's finally some love for LIFX in the Kodi community as those are without a doubt superior lamps to Philips Hue, just locked away in a rather awful native application.

I'm not a coder but maybe this code by frakman1 might help finding inspiration for multi-bulb support and screen-split setups. I tried it and it works perfectly although with a little delay unfortunately. https://github.com/frakman1/lifxscreen2

Keep it up, man!
Reply
#6
I played around with this code a little and was able to find a way to speak to a particular set of lamps (given their IP addresses are known) by simply jumping over the discovery section of the script altogether and just make a socket connection for each individual bulb by simply inputing the IP addresses directly. This is probably the most inelegant way to do this, but hey it works. I'm not even remotely a coder, I don't even really know what I was doing exactly, but for the interested, here's the changed code:

Code:
import xbmc
import xbmcaddon
import xbmcgui
import os

import socket
import sys
import binascii
import colorsys
import struct

from binascii import unhexlify

def long_to_bytes (val):
  
    val = long(val);  
    val = struct.pack('<Q',val);
    val = val[::-1]
    val = ''.join( [ "%02X" % ord( x ) for x in val ] ).strip();
    return val[12:16]

"""def get_bulb_ip ():

    sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
    sender.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sender.connect(('255.255.255.255', 56700));

    listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
    listener.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    listener.bind(('',56700));

    ownIp = socket.gethostbyname(socket.gethostname());

    packetArray = bytearray([0x24, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00])

    sender.send(packetArray);

    sender.close();

    deviceIp = ownIp;

    while deviceIp == ownIp:
        data, addr =listener.recvfrom(2048);
        deviceIp = addr[0];

    listener.close();
    sender.close();

    return addr[0];
"""

useLegacyApi   = True
capture = xbmc.RenderCapture()

if useLegacyApi:
    capture.capture(32, 32, xbmc.CAPTURE_FLAG_CONTINUOUS)

host1 = '192.168.1.12'
host2 = '192.168.1.13'
host3 = '192.168.1.14'
port = 56700

s1 = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s1.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s1.connect((host1, port))
s2 = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s2.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s2.connect((host2, port))
s3 = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s3.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s3.connect((host3, port))

class PlayerMonitor( xbmc.Player ):
    def __init__( self, *args, **kwargs ):
        xbmc.Player.__init__( self )

    def onPlayBackStarted( self ):
        if not useLegacyApi:
            capture.capture(32, 32)



while not xbmc.abortRequested:
    xbmc.sleep(100)
    if capture.getCaptureState() == xbmc.CAPTURE_STATE_DONE:
        width = capture.getWidth();
        height = capture.getHeight();
        pixels = capture.getImage(1000);

        if useLegacyApi:
            capture.waitForCaptureStateChangeEvent(1000)
            
        pixels = capture.getImage(1000)

        red = [];
        green = [];
        blue = [];

        for y in range(height):
            row = width * y * 4
            for x in range(width):
                red.append(pixels[row + x * 4 + 2]);
                green.append(pixels[row + x * 4 + 1]);
                blue.append(pixels[row + x * 4]);


        red = (sum(red)/len(red))/255.00;
        green = (sum(green)/len(green))/255.00;
        blue = (sum(blue)/len(blue))/255.00;

        hsb = colorsys.rgb_to_hsv(red, green, blue);

        huevalue = int(hsb[0]*65535);
        huevalueHex = long_to_bytes(huevalue);
        satvalue = int(hsb[1]*65535);
        satvalueHex = long_to_bytes(satvalue);
        brightnessvalue = int(hsb[2]*65535);
        brightnessvalueHex = long_to_bytes(brightnessvalue);

        packetArray = bytearray([0x31,0x00,0x00,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x00,0x00,0x00,0x55,0x55,0xFF,0xFF,0xFF,0xFF,0xAC,0x0D,0x00,0x00,0x00,0x00])

        packetArray[38] = unhexlify(huevalueHex[0:2]);
        packetArray[37] = unhexlify(huevalueHex[2:4]);

        packetArray[40] = unhexlify(satvalueHex[0:2]);
        packetArray[39] = unhexlify(satvalueHex[2:4]);

        packetArray[43] = unhexlify(brightnessvalueHex[0:2]);
        packetArray[42] = unhexlify(brightnessvalueHex[2:4]);

        try:
            s1.send(packetArray);
            s2.send(packetArray);
            s3.send(packetArray);
        except:
            print "Caught exception socket.error"

s.close()

if ( __name__ == "__main__" ):

    player_monitor = PlayerMonitor()

    try:
        capture.getCaptureState()
    except AttributeError:
        useLegacyApi = False

You have to change the number of hosts, IP addresses etc. so it reflects your local setup of course. have fun.
Reply
#7
Unfortunately, It does not work here. I have 6 bulbs.
HTPC homemade - BOX SilverStone Lascala LC17 - CPU Intel Core i3-3220T (2.8 GHz) - CM ASRock B75 Pro3 - HD Crucial M4 64 Go - CG ASUS GeForce GT 610 Low Profile 1 GB - RAM Corsair Vengeance Low Profile Blue Series 4 Go (2x2 Go) DDR3 1600 MHz CL9 - POWER Be Quiet! Power 7 400 W 80PLUS - REMOTE Harmony 650 - Frodo 12.2 XBMCbuntu Aeon-Nox 4.1.9 - MacPro 2010 - SMB
Reply
#8
I ended up purchasing two of these bulbs and yep, couldn't get them to work with the addon.

However on the whole they work great with other applications i wanted them for and now have automated bulbs running from a crontab using a daemon that i found. I have since ordered two more bulbs.
Reply
#9
for the guys who have trouble getting this to work - I'm just guessing here, but maybe you have another LIFX app blocking the communications address to the bulbs. make sure all other apps are closed and try again. I remember I had that problem once. You should be able to find this in the logs though. generally a log would be necessary to help you anyways. good luck.
Reply
#10
Thx for the feedback. Support for multiple-bulbs (configurable) is in the making.
Reply
#11
Great!!! Hope to see this soon!
HTPC homemade - BOX SilverStone Lascala LC17 - CPU Intel Core i3-3220T (2.8 GHz) - CM ASRock B75 Pro3 - HD Crucial M4 64 Go - CG ASUS GeForce GT 610 Low Profile 1 GB - RAM Corsair Vengeance Low Profile Blue Series 4 Go (2x2 Go) DDR3 1600 MHz CL9 - POWER Be Quiet! Power 7 400 W 80PLUS - REMOTE Harmony 650 - Frodo 12.2 XBMCbuntu Aeon-Nox 4.1.9 - MacPro 2010 - SMB
Reply
#12
Thanks for a nice addon. It's simple and easy to use, but maybe add a setting or limit max brightness. Also it would be cool to make it work with pictures (just an idea).
Image
Reply
#13
This is still working great and got even better with the latest feature additions. Now if there was a way to merge this with NatKodiLifx plugin for remembering the state of the bulbs at start/play and going back to the initial state at pause/stop this would be ridiculously cool :-)
Reply
#14
Hi there,

Does this have Pi support?
Reply
#15
is this project dead? i loved this addon. but it's nor working with the current version of lifx FW
Reply

Logout Mark Read Team Forum Stats Members Help
Lifx addon1