Instructions and Steps to Implement LIFX API

To be honest, I don’t really know what I’m doing, but I used to do some scripting in Lua years ago. If you know Lua, then I think what you would want to do is define a global variable for the level of that light in your “Startup Lua” (under apps, develop apps - where you had to enter require(“lifx_ctrl.lua”) ), using a value of between 0.0 and 1.0. I think you could write code to query the light for its level, but that functionality is not built into the script in its present state as far as I know.
You would then modify that variable at the time that you control the bulb to reflect its state.
After that, you could create a scene that adds or deducts 0.1 to/from that variable, redefines the variable with that new value and replaces the defined level with your variable.
I hope I’m explaining myself clearly here. Keep in mind that the minute you use another method to control the bulbs (like the app, for instance), the system will break until you control the bulb(s) with your scenes again which would then redefine the variable(s).

Joe, I did some testing and it was indeed the Vera that was misbehaving. The test through the website worked fine. I managed to fix it though. I believe what happened was that I lost the LIFX files when support messed around with my firmware during a remote session, so I had to copy the files back over and I must’ve copied an old file over or something. Once I re-did the whole install process from scratch, everything worked perfectly. Thanks for looking into that in any case.

I was wondering how difficult it would be to add the ability to execute scenes. One reason this would be great is because the LIFX developers seem to be having difficulty with the idea of having groups in child/parent relationships. As a result, I’ve had to create many different scenes as a workaround. While I could go and program each one manually, it sure would be a time saver if I could just use a line from your script to call up scenes instead. I’ve also created many scenes to emulate the colors of a sunrise, etc. and it would be painstaking work to have to go in and figure out the hex value for each and every light for each of those scenes.

Last question for this post – I know that the values for the light levels are between 0.0 and 1.0, but does that mean that we’re restricted to level changes of 10%, or can we use a value like 0.57, for example?

Thanks!

[quote=“Quixote, post:41, topic:191679”]To be honest, I don’t really know what I’m doing, but I used to do some scripting in Lua years ago. If you know Lua, then I think what you would want to do is define a global variable for the level of that light in your “Startup Lua” (under apps, develop apps - where you had to enter require(“lifx_ctrl.lua”) ), using a value of between 0.0 and 1.0. I think you could write code to query the light for its level, but that functionality is not built into the script in its present state as far as I know.
You would then modify that variable at the time that you control the bulb to reflect its state.
After that, you could create a scene that adds or deducts 0.1 to/from that variable, redefines the variable with that new value and replaces the defined level with your variable.
I hope I’m explaining myself clearly here. Keep in mind that the minute you use another method to control the bulbs (like the app, for instance), the system will break until you control the bulb(s) with your scenes again which would then redefine the variable(s).[/quote]

This is my first experince with Lua.
Thanks for the suggestions, but the fact that other scenes changes or app changes would break this method won’t work.

A little background into what I’m trying to accomplish:
I have a Lutron Pico remote that works controlling the LIFx light with buttons for ON, OFF, Dim light to 75%, Dim light to 25%, and random color pick.
I created a scene for each action and assigned the scene to the remote buttons.
This works great, I can control the light brightness, colors, and toggle ON/OFF. ON resets to default color.
I want to improve the dim up/down feature. Right now the scene’s LUA code just says to set the light to either 75 or 25. What I would like the scene to do is read the current light brightness and increase/decease by an increment amount.

I don’t know if you could pass a variable as the brightness value.

[quote=“silfa718, post:42, topic:191679”]This is my first experince with Lua.
Thanks for the suggestions, but the fact that other scenes changes or app changes would break this method won’t work.

A little background into what I’m trying to accomplish:
I have a Lutron Pico remote that works controlling the LIFx light with buttons for ON, OFF, Dim light to 75%, Dim light to 25%, and random color pick.
I created a scene for each action and assigned the scene to the remote buttons.
This works great, I can control the light brightness, colors, and toggle ON/OFF. ON resets to default color.
I want to improve the dim up/down feature. Right now the scene’s LUA code just says to set the light to either 75 or 25. What I would like the scene to do is read the current light brightness and increase/decease by an increment amount.

I don’t know if you could pass a variable as the brightness value.[/quote]

No, other Vera scene changes would not disrupt this method since you would modify the variable(s) with each light level change. If you use the app on your phone though, you would have no way of changing those variables to mirror the states of the lights and would thereby break that system. I think the confusion we’re having about “scenes” is that both the Vera and the LIFX app use the term “scene”. If you use the LIFX app to apply a (LIFX) scene, then it’s obviously not going to communicate with the Vera.

I understand what you’re trying to accomplish. I’m not familiar with the Lutron Pico remote, but it sounds like you’re working strictly through the Vera, so it seems that the method I mentioned may not be so bad (not to mention your only option :wink: ).
I don’t see why you wouldn’t be able to pass a variable as the brightness value as long as the syntax is correct. Sorry, it’s been many years since my Lua days, and I’m afraid I’ve forgotten most of it, but I’m sure there is someone here that is far more knowledgeable that can help.

The problems we would have with the way things are set up now as I understand them are that 1) I’m not sure if we can use the script to find the level of the light. The first post states that the “return values” include “pwr - power state of LIFX light”, which could be the level of the light or maybe just on/off (?). We’ll need to wait for Joek to shed some light on that and how to use the return values. 2) The level used to instruct the bulbs is an absolute value ranging from 0.0 to 1.0. There is no command for incremental modifications to brightness, so any way you look at it, I think you’re going to have to learn a little Lua and write a very basic script using the method that I outlined earlier.

Unfortunately, I don’t have access to my LIFX bulbs at the moment, but believe the ‘list’ mode provides all current settings of your bulbs (to include brightness). You’d have to parse the return value to determine the current brightness level.

I did implement the ‘list’ mode in lifx_ctrl.lua so should receive the return values. More info here on lifx API: List Lights

Cheers!

Joe

[quote=“joek, post:44, topic:191679”]Unfortunately, I don’t have access to my LIFX bulbs at the moment, but believe the ‘list’ mode provides all current settings of your bulbs (to include brightness). You’d have to parse the return value to determine the current brightness level.

I did implement the ‘list’ mode in lifx_ctrl.lua so should receive the return values. More info here on lifx API: https://api.developer.lifx.com/docs/list-lights[/quote]

Thanks for the reply. Can you clue us in on the syntax we would use with your script and how the return values are handled? Do they populate a table somewhere or is it just one variable with one long string?

Edit: Also, did you notice my post a few posts back? I had a couple of questions I mentioned there that you won’t need access to your bulbs in order to advise me. Thanks again.

After this get answered, I guess I’ll have to get busy figuring out LUA

Thanks for the help

After this get answered, I guess I’ll have to get busy figuring out LUA

Thanks for the help[/quote]

No problem at all. It’s actually a pretty good idea and if I weren’t using the Android app, I’d probably do the same thing. I’m a little preoccupied right now, but maybe I’ll see if I can remember some Lua from about a decade ago. :slight_smile:
You can find the manual online in PDF format.

Joe, you MIA?
:-\

My vera no longer shows my lifx lights anymore in the dashboard, happen to anyone else? It was working as of a couple days ago.

I never had my lights showing on my dashboard. Only the scenes I created with the scripts.

Okay, I forgot how this worked, I’ll test it and check back later

Update:

Found my problem. My bulb wasn’t connecting to the LIFX cloud. Why or how I don’t know. I reset the bulb via the app and it is working again.

Joe,

Would you consider modifying this to run the LIFX LAN API instead? Eliminates cloud/internet issues and should make it quicker and more reliable.

Well, it seems that Joe has deserted us.
I got impatient, so I opened the lifx_ctrl.lua file to poke around a little and try to figure out one of the features I needed. I finally managed to make sense of that particular problem, and it seems that the feature was actually already programmed into the script and it was only a matter of finding the syntax.
For anyone interested in activating the scenes that you’ve created using the LIFX app, you can go to this page:

Enter the token that you plugged into your lifx_ctrl.lua file and hit “Try it!” and you’ll get a list of your scenes. From there, you find the scene “uuid” (looks like a serial number), listed in the line right above the name of the scene.
In your newly created scene on the Vera, use the Lua code:

lifx_ctrl(“scene_id:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”, “scene”)

replace the "xxxx"s with your scene uuid. Simple as that.
Enjoy.

Is there anyone here that is knowledgeable enough in Lua to modify the lifx_ctrl.lua file to allow us to specify the duration for the scene function?
I’d like to set up my sunrise and sunset scripts to change color over several minutes, but I’m not sure how to modify the control script. It doesn’t look that complicated for someone that knows what they’re doing.
Thanks in advance.

[quote=“leyton01, post:52, topic:191679”]Joe,

Would you consider modifying this to run the LIFX LAN API instead? Eliminates cloud/internet issues and should make it quicker and more reliable.[/quote]

I’ve looked into operating the Lifx bulbs via local LAN some time ago, but determined using the lifx Rest API would be easier to implement. Plus not certain how to implement Lan portion on the vera, so would have to run a local server.

Joe

That’s not true I’ve not deserted this thread.

I subscribe to this thread and for some reason I am no longer receiving notifications when a new message is posted. I just reset my notifications so hopefully that fixes it.

Joe

That’s not true I’ve not deserted this thread. That’s fake news!

I subscribe to this thread and for some reason I am no longer receiving notifications when a new message is posted. I just reset my notifications so hopefully that fixes it.

Joe[/quote]

XD Well, I figured that fake news was all the rage these days, so I’d get in on the action. Sorry, I should have sent you a P.M. before jumping to conclusions.
Did you notice my post about scene duration? I have a routine that works with my alarm clock app and Tasker to run through some Lifx scenes to simulate a sunrise and sunset and it would be a lot better if the transitions were less abrupt. If I could shift between scenes over 10 minutes that would be pretty sweet. Doable?
Thanks.

[quote=“joek, post:55, topic:191679”][quote=“leyton01, post:52, topic:191679”]Joe,

Would you consider modifying this to run the LIFX LAN API instead? Eliminates cloud/internet issues and should make it quicker and more reliable.[/quote]

I’ve looked into operating the Lifx bulbs via local LAN some time ago, but determined using the lifx Rest API would be easier to implement. Plus not certain how to implement Lan portion on the vera, so would have to run a local server.

Joe[/quote]

I’ve been working on a plugin based loosely off the work done here. At this time it is only for UI7 and supports on/off, brightness and color via the user interface. It also periodically updates the light to reflect changes made outside Vera (on/off and brightness).

It’s still early work in progress, but if folks are interested I will publish it and we can go forward based on suggestions (probably start a new thread). The vision for this plugin was from the point of view of advanced configuration (pulsing, movement etc) being set by the lifx app (this applies especially to the light strip) and the basic things controlled by vera.

-Majimus

Awesome! I’m really excited about this! You are a hero in my eyes. ;D
I would definitely be interested in testing the plugin and making suggestions if that would help you in any way.
THANKS!!!

You can find the code at [url=https://github.com/majimus/majimusLifx]https://github.com/majimus/majimusLifx[/url] , this is really beta and ONLY for UI7.

I’ve been using it as I develop, but at this point there is still a lot of work to be done so.

To install:

  1. Upload all files to your vera (running UI7)
  2. Add a new device with device type = urn:schemas-majimus-com:device:Lifx:1
  3. The upnp device filename = D_MajimusLifx.xml
  4. The upnp implementation filename = I_MajimusLifx.xml

You will probably need to reload the interface for the new device to appear then u click the settings section for the configuration and you add your Lifx ApiKey and the id (the format for the id is “id:xxxxxx” without the quotes) of the light in question.

The steps will need to be adjusted for each light you want to add (you can probably get away with putting “all”) as the id and controlling all your lights at once.

Going forward I will move this to a parent->child setup since most people will be controlling all lights with the same token, as it is you can control lights from different accounts.

I’m happy to make changes based on feedback as time permits (but I do have a day job so you know how it goes)

-Majimus