The Vera Community forums have moved!

General => Lighting & Load Control => Topic started by: aechelon on May 04, 2015, 10:20:02 pm

Title: LIFX REST api
Post by: aechelon on May 04, 2015, 10:20:02 pm
Looks like Lifx has a RESTful API in beta (http://developer.lifx.com/).

I just took it for a spin and it works a charm on the vera.

As mentioned on the website, you can generate an access token from your account settings page.  From there it's trivial to issue commands by invoking curl on the vera:

The command to turn all lights on is:

Code: [Select]
os.execute('curl -k -u \"YOUR_ACCESS_TOKEN:\" -X PUT -d \"state=on\" \"https://api.lifx.com/v1beta1/lights/all/power\"')
To turn on/off a specific lifx device you will want to run curl directly from the command line with "all" as the target (as shown above) and look for the REST response, which will contain the id of the devices.

Then to toggle the device:

Code: [Select]
os.execute('curl -k -u \"YOUR_ACCESS_TOKEN:\" -X PUT -d \"state=on\" \"https://api.lifx.com/v1beta1/lights/DEVICE_ID/power\"')
(note no quotes are required on the id)

So, for example, using the dummy access token and "Left Lamp" device from the lifx developer website...

ACCESS TOKEN:
c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192

LIFX DEVICE INFORMATION:
{
    "id": "d3b2f2d97452",
    "label": "Left Lamp",
    "status": "timed_out"
}

To turn on the lifx device "Left Lamp":
Code: [Select]
os.execute('curl -k -u \"c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192:\" -X PUT -d \"state=on\" \"https://api.lifx.com/v1beta1/lights/d3b2f2d97452/power\"')
To turn off the lifx device "Left Lamp":
Code: [Select]
os.execute('curl -k -u \"c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192:\" -X PUT -d \"state=off\" \"https://api.lifx.com/v1beta1/lights/d3b2f2d97452/power\"')
Building a Vera plugin around that should be a piece of cake!

Anyone willing to help?