This is an unofficial JSON RESTful API service for controlling LIFX devices. This API adds some reliability that the LIFX gem does not include.
- Mostly synchronous, apart from setting colour
- Supports MDNS
- Ruby 2.0+
- Tested on OS X Mavericks, but should work for other *nix platforms.
- Install the gem:
gem install lifx-http
- On OS X Mavericks using system Ruby:
sudo gem install lifx-http
- If you see this:
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
Runexport ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future; sudo -E gem install lifx-http
- If you see this:
- On OS X Mavericks using system Ruby:
- Run in foreground (no daemonizing yet):
lifx-http
- Test if working:
curl http://localhost:56780/lights.json
- Toggle all lights:
curl -XPUT http://localhost:56780/lights/all/toggle -d ''
- Set all lights to green:
- URL params:
curl -XPUT "http://localhost:56780/lights/all/color?hue=120&saturation=1&brightness=1&duration=2" -d ''
- JSON body:
curl -XPUT http://localhost:56780/lights/all/color -H "Content-Type: application/json" -d '{"hue": 120, "saturation": 1, "brightness": 1, "duration":2}'
- Override method by setting
_method
:curl "http://localhost:56780/lights/all/color?hue=120&saturation=1&brightness=1&duration=2&_method=put"
- URL params:
- Start a slow sunrise effect:
curl -XPUT "http://localhost:56780/lights/all/color?hue=35&saturation=0.37&brightness=0.65&duration=10m" -d ''
selector
is either:all
for all lightslabel:[label]
for light with labellabel
tag:[tag]
for lights with tagtag
[light_id]
for light with idlight_id
GET /lights
- Lists all lightsGET /lights/{selector}
- Lists lights matchingselector
PUT /lights/{selector}/on
- Turns lights matchingselector
onPUT /lights/{selector}/off
- Turns lights matchingselector
offPUT /lights/{selector}/toggle
- Toggle lights matchingselector
. If any lights inselector
is on, it will turn them offPUT /lights/{selector}/color
- Sets the color for lights matchingselector
. Color data can be passed as URL parameters or form parameters (JSON)PUT /lights/{light_id}/label
- Changes the label of light with idlight_id
POST /lights/{light_id}/tag
- Adds a tag to the lightDELETE /lights/{light_id}/tag
- Removes a tag from the light
This API is documented using Swagger.
To view documentation and play with the API, start the API server locally, then visit http://petstore.swagger.wordnik.com/ and put http://localhost:56780/swagger_doc
in the first text box, then hit Explore
.
You should see something like this:
- Update MDNS gem
- MDNS fix
- Duration now supports minute and hour suffixes e.g. "12h" for 12 hours thanks to @Bluebie
- MDNS support! Enables easy discovery of a LIFX HTTP instance on the LAN.
- First gem release
MIT. See LICENSE