Kodi Integration with LIFX

After a few days with no internet I am back and glad to see the community is willing to help. I actually have zero programming knowledge, I might be in over my head but im willing to learn anything you guys can provide. I will start reading into it (im sure its not as easy as that) Essentially i want the lights to turn on when i open kodi and dim to 1-5% when a movie starts. I also want the lights to go back on when i pause the playing video. I love my Lifx light and i will continue to try to find a good way to integrate them to my media center.

This plugin for Kodi already does pretty much exactly what you want: https://github.com/phoniclynx/NateKodilifx

(It doesn’t turn the lights on when you start Kodi, but it does dim them when you play something, and restore them when you pause)

I was working on a slightly more sophisticated version of this, using the LAN protocol rather than the HTTP API, but the results so far are a bit patchy. This is probably because my implementation of the LAN protocol is pretty rubbish/unreliable. If I ever get time to rewrite it to use @daniel_hall’s version of the LAN SDK instead, I’ll let you know.

I’ve managed through sheer stubborness to shoehorn Daniel Hall’s Lifxsdk into Eventghost. It’s working pretty well now. Suntracker plugin turns on outside light, sets it to yellow for bug control and dims it during the wee hours of the night.

The lifx plugin I wrote turns on lounge light at 50% when projector is started, dims to 25% when Kodi starts and turns it on and off when playing media, pausing (15%) and stopping.

My scripting knowledge is rudimentary, but I managed to modify the sdk a little to fix some eventghost python version issues. I’m still trying to figure out the sdk, but i’m getting there.

I’m having issues with lost responses sometimes but I see daniel has a todo: comment there, patience needed.

Not sure what I have done is worth sharing, but I’d consider it.

edit: this last part of the discussion should probably have it’s own thread, I realised after I posted…

Im going to give this a try again. Last I remember I tried the addon but I could not get it to turn anything on or off even after adding the api key that was generated by the LIFX online web page.

[Moved off-topic things to new thread, everything is on topic again :smile:]

It is fairly easy to do once you get a better understanding.
I had cobbled together a script that first checks if the lights are even on, if not it assumes they should stay off and does nothing.
If they are on it looks for the scenes stored in the cfg file, for movie, tv and pause etc and matches them to the returned list storing the ID of the scenes.

If you play a movie it stores the lights activates the set scene and then after the same amount of time to transition to the new scene it once again stores the lights status for comparison.
This way if you pause or stop it sees if the light state is the same as the scene, if so it applies the pause scene or resets the lights to original. if the lights have changed it assumes the settings have been overridden and leaves things alone.
it is a basic attempt that I am now moving to the new V1 API and then will look at local LAN via Daniels SDK, once I understand his API I will include an ambient mode to set the lights to the same as the screen. I have already created this but using the HTTP API and it is a little slow.

btw. ps… that NateKodiLifx plugin is mine… if you have any questions… I’ve not done any work on it for a while… and for some reason KODI is complaining when it starts up… but it does work… it is based on the v1beata API so it may not work for a bit till you change how it calls the API.

And you did a good job with it. As I am learning I forked it to make changes to suit myself and made a lot of changes to it.

In windows there is a log error relating to SSL requirements which I have been ignoring I am not sure if you saw the same problems. Your script was brilliant to get me started so thanks again Phoniclynx

I briefly attempted to get it working in Windows but I failed as it was throwing up all kinds of weird errors.

I’d be interested to see what you came up with… It took me days and days to get what you see in Github before it was any kind of useful.

I’m half thinking of integrating it with my lifxhub that i’m writing… That way all it needs to do is send a scene name to a URL and then another one when you pause the video and or finish the video… it already has the capability to return it back to it’s previous scene int he hub program I wrote.

ps I have no idea how to program really… I"m just making it up as I go along cuz no one else seemed to write much code for the lights haha.

I didn’t have a problem with your original script, I just needed to install dependencies and ignored the SSL notice.

I changed the request methods and need to review the headers being used to ensure the return format etc is correct and then I have to review it all to tidy up etc. I have done little scripting myself and had never touched Python before so it has been a great learning experience.
If you look at windows again send through your errors, I found it easy to resolve them all so would be happy to help you out. It took a while to work out adding dependencies in the Kodi Python install but it was easy enough once I worked out where everything was.

Here’s something I made earlier :wink:

Here is something I have built - Lifx Ambilight Addon for Kodi

  • In Theater mode the add-on dims the Lifx lights as soon as a movie starts playing, and turns the lights back to original settings once the movie is done.
  • Ambilight mode turns your Lifx lights in a room-sized Ambilight.


Kodi + Lifx + Ambilight + Movie (LOTR) Test

1 Like

This looks great. Will try it out soon. Thanks for sharing!

1 Like