We have moved at community.getvera.com

Author Topic: LIFX REST api  (Read 1381 times)

Offline aechelon

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +7/-0
« on: May 04, 2015, 10:20:02 pm »
Looks like Lifx has a RESTful API in beta.

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


    "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?