This gem allows you to control your LIFX lights.
It handles discovery, gateway connections, tags, and provides a object-based API for talking to Lights.
Due to the nature of the current protocol, some methods are asynchronous.
This gem is in an early beta state. Expect breaking API changes.
- Ruby 2.0+
- Tested on OS X Mavericks, but should work other *nix platforms. Please file an issue if you have any problems.
Add this line to your application's Gemfile:
And then execute:
Or install the gem with:
gem install lifx # Add sudo if required.
client = ::. # Talk to bulbs on the LAN client.discover! do |c| # Discover lights. Blocks until a light with the label 'Office' is found c.lights.with_label('Office') end # Blocks for a default of 10 seconds or until a light is found client.lights.turn_on # Tell all lights to turn on light = client.lights.with_label('Office') # Get light with label 'Office' # Set the Office light to pale green over 5 seconds green = ::.green(saturation: 0.5) light.set_color(green, duration: 5) # Light#set_color is asynchronous sleep 5 # Wait for light to finish changing light.set_label('My Office') light.add_tag('Offices') # Add tag to light client.lights.with_tag('Offices').turn_off client.flush # Wait until all the packets have been sent
Documentation is available at http://rubydoc.info/github/lifx/lifx-gem/master/frames. Please note that undocumented classes/methods and classes/methods marked private are not intended for public use.
Examples are located in the
- travis-build-light: Changes the colour of a light based on the build status of a project on Travis.
- auto-off: Turns a light off after X seconds of it being detected turned on.
- identify: Use divide-and-conquer search algorithm to identify a light visually.
bundle exec rspec.
The integration specs rely on a least one device tagged with
Test to function. At this point, they can fail occasionally due to the async nature of the protocol, and there's not much coverage at the moment as the architecture is still in flux.
A more comprehensive test suite is in the works.
Please file an issue for general feedback, bugs, clarification, examples, etc etc. Feel free to hit me up on Twitter, too: @chendo.