Instructions and Steps to Implement LIFX API - Part II

Instructions and Steps to Implement LIFX API - Part II
This topic is a continuation from the original topic “Instructions and Steps to Implement LIFX API” found here: http://forum.micasaverde.com/index.php?topic=36961.0

The LUA code lifx_ctrl() provides ability to control LIFX lights via Vera U17. The implementation uses the LIFX API (RESTful) and therefore an internet connection is required for network access to LIFX servers. The LIFX control provides a basic framework, so can easily be modified to enhance its functionality - feel free. It’s implemented as a LUA function and the function can be called by other LUA code or from LUUP within a scene on the Vera.

The code is pretty basic and does not do any error checking or handling. When time permits I’ll add that functionality.

INSTALLATION

LIFX API Access Token

  • Create/generate an LIFX API access token from here: https://cloud.lifx.com/settings
  • Add your LIFX API personal/private access token to the LUA file lifx_ctrl.lua by replacing the existing one in the code.
  • Optional - using your LIFX API access token test your ability to control your lights with the LIFX API using the following link below. At the bottom of the webpage there’s a place to try the API: http://api.developer.lifx.com/docs/list-lights

Install lifx_ctrl.lua (download link below)

  • Make sure your private LIFX API token is added to lifx_ctrl.lua code, then
  • Upload lifx_ctrl.lua to Vera using the GUI. APPS → Develop APPS → Luup files.
  • Add require("lifx_ctrl.lua") to Vera startup lua: APPS → Develop APPS → Edit Startup Lua

USAGE
The lifx_ctrl function can be used inside a Vera scene luup (or from another luup code) as follows:

  lifx_ctrl (selector, mode, color, bright, cycles, period)

where:

  • selector - choose “all”, group or a specific LIFX light
  • mode - on, off, toggle, pulse, breathe or list
  • color - red, green, blue, pink, etc. or #RRGGBB format
  • bright - brightness setting (0.0 - 1.0) for “on” and “pulse” modes
  • cycles - no. of cycles to pulse the LIFX light(s) when in “pulse” mode
  • period - time in seconds for one cycles of the effect

EXAMPLES
Some example usage:
lifx_ctrl("id:f055d5005dde", "pulse", "blue",.5, 5, 2) – pulse bulb blue 5 times at 1/2 brightness & cycle period of 2 secs
lifx_ctrl("all", "on", "#00ff00", 1) – turn on all lights green at full brightness
lifx_ctrl("all", "off") – turn off all lights
lifx_ctrl("all", "toggle") – toggle all lights
lifx_ctrl("id:f055d5005dde", "off") – turn off selected light
lifx_ctrl("label:bulb01", "breathe", "yellow",1, 3,.5) – breathe blub yellow 3 times at full brightness & cycle period of .5 secs
lifx_ctrl ("label:bulb01" , "breathe" , "white" , 1 , 2 , .04) – a lightning effect

Example luup code used inside a Vera Scene:
function delaylifx()
lifx_ctrl("label:bulb01", "toggle") – toggle lifx
end

luup.call_delay('delaylifx', 1) – Call function after a delay of 1 seconds

DOWNLOAD
You’ll find the lifx_ctrl lua code here: https://github.com/joekmd/lifx_ctrl/archive/master.zip

Enjoy!!!

Just wondering the reason for the re-post.
I am still unable to use scripts to pulse my lights for some reason and nothing I’ve tried has worked, even after updating to version 2.0.
Any help would be much appreciated.

@Quixote It’s not a re-post as I made fixes to the original code. The new Vera forum isn’t as flexible and could not update the original posts, so created a new topic.

The big fix was adding TLSv1.2 for interfacing with LIFX API. Also, there were a couple other changes needed - not sure why, but possibly lifx made a couple minor changes to their api. Everything seems to be functioning (once again).

Please cut-and-paste the pulse call that isn’t working and I can try it.

Hi,
Thanks for getting back to me. None of my scripts work. The test scene that I’ve been using contains the following line of Lua:

lifx_ctrl(“label:TV Backlight”,“pulse”,“purple”,1,1,2)

My plugin version seems to have updated to 2.0, but perhaps there are some files that I need to overwrite to ensure that they’re all the correct versions? I may have compromised their integrity while trying to get the plugin to work a couple of months ago.
Thanks

@Quixote - I did test your code by cut-and-paste into my system and it did work fine for me. However, when pasting the code I had to change the quotes from ” to " - something weird with the browser font.

I’d recommend going to the LIFX site to make sure you are able to communicate with your lights: https://api.developer.lifx.com/docs/pulse-effect

Make sure your LIFX API token is in the lifx_ctrl code and have the latest (from Dec 22, 2019), which uses TLSv1_2 protocol.

Hope that helps!

Joe

Hi Joe,
It’s been a while since I felt like messing around with this stuff again, but I can confirm that the quote marks are not an issue since I have not modified my scripts in many months.
On the api.developer site, the scripts work just fine. I’m also able to turn on and off lights on the Vera webserver page using the switches in the GUI.
I just tried uninstalling the app, using winSCP to delete any files off the Vera that I thought could be related, then reinstalling the app from the app store and re-entering my key. Nothing helps. Just to be sure, I should be using the newer LIFX app, right (app id 8986)? (There are 2 for some reason – one last updated 2017).
Thanks.

@Quixote - I do not know anything about app id 8986 you are referring to. The code I created works for me. The instructions to install are included in the first post and the code can be downloaded here: https://github.com/joekmd/lifx_ctrl/archive/master.zip

Joe

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules