Author Topic: Instructions and Steps to Implement LIFX API  (Read 11444 times)

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #30 on: October 21, 2016, 03:24:40 pm »
Hey Joe,
I've run into some problems with my bulbs and have since been unable to use them, but I was still wondering if you've considered building your code into a full-fledged Vera plugin. That would be pretty sweet!
I've been looking at the RGB plugin a little, about to add a Fibaro RGBW controller and I'm thinking it would be pretty kick-ass if there were a quick and easy way to coordinate the devices if I ever manage to setup LIFX bulbs again.

-Derek
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline joek

  • Sr. Newbie
  • *
  • Posts: 48
  • Karma: +7/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #31 on: October 21, 2016, 03:36:11 pm »
Hey Joe,
I've run into some problems with my bulbs and have since been unable to use them, but I was still wondering if you've considered building your code into a full-fledged Vera plugin. That would be pretty sweet!
I've been looking at the RGB plugin a little, about to add a Fibaro RGBW controller and I'm thinking it would be pretty kick-ass if there were a quick and easy way to coordinate the devices if I ever manage to setup LIFX bulbs again.

-Derek
@Quixote

Sorry, no intentions for me to build a LIFX plugin. IMO, it would be best for LiFi Labs to develop and support an official LIFX plugin for Vera.

Regards,
Joe

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #32 on: October 21, 2016, 03:37:12 pm »
Bummer.  We both know that will never happen.   :(
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline jcposada

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #33 on: November 07, 2016, 01:36:42 am »
Just wanted to say thanks for doing this work and publishing so others can benefit from it. I was able to easily get my scenario working (turn on a specific set of lights for a specific period of time when a specific code is entered on a lock).

JC

Offline magispat

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #34 on: November 09, 2016, 02:07:18 pm »
from a home automation newbie, just wanted to say thanks!  just to be slightly difficult, has anybody managed to get the fade on / off duration working?

Online majorcuddles

  • Newbie
  • *
  • Posts: 12
  • Karma: +1/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #35 on: November 24, 2016, 01:07:09 pm »
Thanks again for your contributions to the community


Sent from my iPhone using Tapatalk

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #36 on: December 04, 2016, 09:57:09 am »
Hi Joe,
I just tested my Lifx bulbs again this morning and I guess they must've fixed something because they actually worked this time I tried to connect to them with the app. :)
I set them up on my new Vera Plus and started doing a little testing with the new breathe function and I'm finding some strange behavior. I'm having my bulbs retain the color that I choose for the breathe rather than return to their original color as they were with the pulse function.
Has anyone else noticed this with their setup?
Thanks.

-D
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #37 on: December 10, 2016, 12:40:35 pm »
Can someone please test the breathe function and verify my results?
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline joek

  • Sr. Newbie
  • *
  • Posts: 48
  • Karma: +7/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #38 on: December 17, 2016, 08:03:30 am »
@Quixote

Sorry I am not at a place where I can test the breathe function, but did check the Lua code. The code does have the presist set to false, which should retain the color prior to starting breathe.

You could test the lifx api yourself by going to their web page and using the breathe function. The link is in the first post.

Joe

Offline silfa718

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #39 on: January 04, 2017, 12:32:35 am »
Just got this working, and everything worked on the first try. Thanks for the clear instructions.

Would it be possible to to add duration (How long in seconds you want the power action to take.) to the parameter list. At first I thought this the period parameter.

Also if i wanted to create a dimmer scene, that would look at the current brightness and raise (or lower) by a factor of .1 from the current state, would that be possible? How?

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #40 on: January 05, 2017, 06:48:37 am »
Also if i wanted to create a dimmer scene, that would look at the current brightness and raise (or lower) by a factor of .1 from the current state, would that be possible? How?

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!
« Last Edit: January 05, 2017, 06:53:27 am by Quixote »
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline silfa718

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #41 on: January 05, 2017, 11:45:59 am »

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).


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.

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #42 on: January 05, 2017, 03:20:31 pm »
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.

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 ;) ).
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.
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline joek

  • Sr. Newbie
  • *
  • Posts: 48
  • Karma: +7/-0
Re: Instructions and Steps to Implement LIFX API
« Reply #43 on: January 05, 2017, 06:05:06 pm »
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

Cheers!

Joe

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Instructions and Steps to Implement LIFX API
« Reply #44 on: January 05, 2017, 06:18:07 pm »
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

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.
« Last Edit: January 05, 2017, 06:22:57 pm by Quixote »
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.