Code Monkey home page Code Monkey logo

hue-lib's Introduction

hue-lib

This is a Ruby library for controlling the Philips Hue lighting system. The API has not yet been released, but there are several people working to figure it out.

WARNING

All of this is very experimental and could permanently damage your awesome (but ridiculously expensive) lightbulbs. As such, exercise extreme caution.

Getting Started

You can get a great overview of the options and limitations of the lights from Ross McKillop.

Usage

To begin using, fire up the irb console from the project root thus:

irb -I lib
>> require 'hue'
=> true

Start by registering your application. Press the button on the bridge and execute

>> Hue.register_default
=> #<Hue::Bridge:0x8b9d950 @application_id="4aa41fe737808af3559f3d22ca67a0ca", @base_uri="http://198.168.1.1/api">

This will create two config files in your ~/.hue-lib directory. One for the bridges discovered on your network and one for the registered application.

You can fetch the default application thus:

>> bridge = Hue.application
=> #<Hue::Bridge:0x8b9d950 @application_id="4aa41fe737808af3559f3d22ca67a0ca", @base_uri="http://198.168.1.1/api">

You can see all of the lights attached to your controller by querying the bridge.

>> bridge.lights
=> {"1"=>{"name"=>"Bedroom Overhead"}, "2"=>{"name"=>"Living Overhead"}, "3"=>{"name"=>"Standing Lamp"}, "4"=>{"name"=>"Living Cabinet"}}
>> bridge.light_names
=> "1. Bedroom Overhead\n2. Living Overhead\n3. Standing Lamp\n4. Living Cabinet"

If you know the ID number of a particular lamp, you can access it directly.

>> b = Hue::Bulb.new(bridge, 1)
=> #<Hue::Bulb:0x007fe35a3586b8 @bridge=#<Hue::Bridge:0x007fe35a358690 @id="1">>

# on/off
>> b.on?
=> false

>> b.on
=> true

>> b.on?
=> true

# brightness
>> b.brightness = 128
=> 128

# color
>> b.color = Hue::Colors::ColorTemperature.new(6500)
=> Temperature=6500°K (153 mired)

>> b.color = Hue::Colors::HueSaturation.new(10_000, 255)
=> Hue=10000, Saturation=255

>> b.color = Hue::Colors::XY.new(0.5, 0.5)
=> XY=[0.5, 0.5]

# blinking
>> b.blinking?
=> false

>> b.blink

>> b.blinking?
=> true

>> b.solid

>> b.blinking?
=> false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.