Giter Site home page Giter Site logo

hue's Introduction

Hue

Work with Philips Hue light bulbs from Ruby.

Installation

Add this line to your application's Gemfile:

gem 'hue'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hue

Usage

The first time you use it, it will automatically create a user for you. Doing this requires you to have pushed the button on your bridge in the last 30 seconds. If you haven't it will throw an exception and let you know you need to push the button. Simply press the button and run the command again.

CLI

$ hue all on
$ hue all off
$ hue all --hue 65280 --brightness 20
$ hue light 2 on
$ hue light 2 --brightness 20

Ruby

client = Hue::Client.new

Lights

light = client.lights.first
light.on!
light.hue = 46920
light.color_temperature = 100
transition_time = 10*5 # Hue transition times are in 1/10 of a second.
light.set_state({:color_temperature => 400}, transition_time)

Groups

# Fetching
group = client.groups.first
group = client.group(1)

# Accessing group lights
group.lights.first.on!
group.lights.each { |light| light.hue = rand(Hue::Light::HUE_RANGE) }

# Creating groups
group = client.group # Don't specify an ID
group.name = "My Group"
group.lights = [3, 4] # Can specify lights by ID
group.lights = client.lights.first(2) # Or by Light objects
group.new? # => true
group.create! # Once the group is created, you can continue to customize it
group.new? # => false

# Destroying groups
client.groups.last.destroy!

hue's People

Contributors

aggroboy avatar cschell avatar csouls avatar davidbegin avatar hmsk avatar kurtsson avatar lepht avatar maddox avatar marcoroth avatar meltingice avatar mertdumenci avatar quicksander avatar riywo avatar shokai avatar siphonay avatar sodabrew avatar soffes avatar sshao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hue's Issues

Trace on init [ Ruby 1.9 ]

irb(main):001:0> require 'hue'
=> true
irb(main):002:0> client = Hue::Client.new
EOFError: end of file reached
    from /opt/puppet/lib/ruby/1.9.1/net/protocol.rb:141:in `read_nonblock'
    from /opt/puppet/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
    from /opt/puppet/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
    from /opt/puppet/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:1294:in `request'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:1196:in `request_get'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:746:in `start'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
    from /opt/puppet/lib/ruby/1.9.1/net/http.rb:431:in `get'
    from /opt/puppet/lib/ruby/gems/1.9.1/gems/hue-0.1.3/lib/hue/client.rb:27:in `bridges'
    from /opt/puppet/lib/ruby/gems/1.9.1/gems/hue-0.1.3/lib/hue/client.rb:19:in `bridge'
    from /opt/puppet/lib/ruby/gems/1.9.1/gems/hue-0.1.3/lib/hue/client.rb:49:in `validate_user'
    from /opt/puppet/lib/ruby/gems/1.9.1/gems/hue-0.1.3/lib/hue/client.rb:14:in `initialize'
    from (irb):2:in `new'
    from (irb):2

INVALID JSON - Failing to Validate User

All has been working fine until this morning.

Now:

client = Hue::Client.new
JSON::ParserError: A JSON text must at least contain two octets!
from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:in `initialize'

and, from the CLI

'hue lights' returns:

/Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:in initialize': A JSON text must at least contain two octets! (JSON::ParserError) from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:innew'
from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:in parse' from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:468:inJSON'
from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/hue-0.1.3/lib/hue/client.rb:27:in bridges' from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/hue-0.1.3/lib/hue/client.rb:19:inbridge'
from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/hue-0.1.3/lib/hue/client.rb:49:in validate_user' from /Users/arkonovs/.rvm/gems/ruby-2.2.0/gems/hue-0.1.3/lib/hue/client.rb:14:ininitialize'
from /Users/arkonovs/GitHub/alexa-home/modules/lights.rb:4:in new' from /Users/arkonovs/GitHub/alexa-home/modules/lights.rb:4:in<top (required)>'
from /Users/arkonovs/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /Users/arkonovs/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from app.rb:5:in `

'

Changes to Whitelist username creation

Hi Sam,
I work for Philips Hue Developer Support. In case you were not aware, in a few months time we will be changing the way usernames are created on the bridge (for security reasons). Custom whitelist usernames will no longer be allowed and the bridge randomly generated username must be used instead. Please see below link for more information:
http://www.developers.meethue.com/documentation/important-whitelist-changes

Am not a Ruby developer myself, but a quick glance at the code and in client.rb (line 97) the setting of the username will have no effect after February 2016 (the username should be derived from the bridge success response as shown in the above link) and the initialization of the username will stop working also. Hopefully the above link should make it clear what changes need to be done here. Apologies for the inconvenience.

Thanks
Steve

Setting Light state attribute does not actually change the light

Issue

Using Light#hue= to set the hue does not actually change the physical light's hue. Documentation and code both suggest that this is not the expected behavior.

This also probably holds the same for trying to set saturation, brightness, color_temperature, alert, effect, but I haven't personally tested all of these attributes.

System

  • Mac OSX 10.10.1
  • Hue API Version 1.7.0
  • Bridge swversion "01023599"
  • Reproduced on the following ruby versions:
    • ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
    • ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]
    • rubinius 2.5.2.c145 (2.1.0 50aa7356 2015-04-07 3.5.1 JI) [x86_64-darwin14.0.0]

Reproduction

require 'hue'

client = Hue::Client.new
light = client.lights.first

puts "light.hue: #{light.hue}"

puts "setting hue to 0 via 'light.hue = 0'..."
light.hue = 0                     # =>  expect the hue to change here,
                                  #     but my lights do not change in hue

puts "light.hue: #{light.hue}"    # =>  however, the object's attribute
                                  #     has changed to 0.

puts "refreshing light via 'light.refresh'..."
light.refresh

puts "light.hue: #{light.hue}"    # =>  the object's attribute has gone back
                                  #     from 0 to its original value.

Output:

light.hue: 15126
setting hue to 0 via 'light.hue = 0'...
light.hue: 0
refreshing light via 'light.refresh'...
light.hue: 15126

Reason

  1. Hue::Light includes the module Hue::EditableState
  2. Hue::EditableState uses define_method to define the method hue= (and others)
  3. the hue attribute is defined in Hue::Light as as an attr_accessor
  4. attr_accessor creates a hue= method
  5. the attr_accessor-created hue= method takes "precedence" over the one created by the included module's define_method: see this gist for a pure ruby reproduction of this behavior.

As a result, light.hue= only changes the hue attribute on the Hue::Light object, and does not actually get posted to the light itself.

Fix

Could probably just replace the relevant attr_accessor's with attr_reader's instead. Unless someone else gets to this first, I should have a PR ready for this soon.

No way to invalidate cached lights

If light colors change via means other than the current client, there's no way to do a full update of state due to the lights being memoized.

bridge#refresh should clear out any of the stored instance variables.

hue all STATE

is the hue all STATE command working? for me it always gives a false result

hue all STATE
{"success"=>{"/lights/1/state/on"=>false}}
{"success"=>{"/lights/2/state/on"=>false}}
{"success"=>{"/lights/3/state/on"=>false}}

when i turn one light on for example it gives a response saying it's on, but after that, if i call state it will say it's off

(running hue bridge 2.0 with the latest firmware update available)

nUPNP no longer works for bridge discovery

The bridge discover method in client.rb does not seem to work any more (see thread). Perhaps it's still working for some but, as the thread suggests, other discovery methods should be used.

One such method could be using arp. I've made a simple patch which will find a single hue bridge on the current network but isn't suited for a pull request (as it shells out). It can be used for a proof of concept though.

Another option: allow IP to be specified (either via ~/.hue or Hue::Client.new). Finding the IP manually is trivial using say the Hue app for iOS (the only problem would be if the DHCP server issued a new IP).

No Bridge Found

Anyone know why I keep getting
``bridge': Hue::NoBridgeFound (Hue::NoBridgeFound)`
Sometimes it works fine but most of the time it just errors

Exception on (unauth user?)

Yay, happy to see there's are ruby gem for hue. Thanks!

Just tested it, unfortunately I got the following exception, guess it's because of unauth user? Although I pushed the button... - any ideas?

bin/hue all on
/Users/tobi/Projects/ruby/hue/lib/hue/client.rb:53:in `[]': can't convert String into Integer (TypeError)
    from /Users/tobi/Projects/ruby/hue/lib/hue/client.rb:53:in `validate_user'
    from /Users/tobi/Projects/ruby/hue/lib/hue/client.rb:14:in `initialize'
    from /Users/tobi/Projects/ruby/hue/lib/hue/cli.rb:36:in `new'
    from /Users/tobi/Projects/ruby/hue/lib/hue/cli.rb:36:in `client'
    from /Users/tobi/Projects/ruby/hue/lib/hue/cli.rb:15:in `all'
    from /Users/tobi/.rvm/gems/ruby-1.9.3-p286/gems/thor-0.17.0/lib/thor/task.rb:27:in `run'
    from /Users/tobi/.rvm/gems/ruby-1.9.3-p286/gems/thor-0.17.0/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/tobi/.rvm/gems/ruby-1.9.3-p286/gems/thor-0.17.0/lib/thor.rb:344:in `dispatch'
    from /Users/tobi/.rvm/gems/ruby-1.9.3-p286/gems/thor-0.17.0/lib/thor/base.rb:434:in `start'
    from bin/hue:8:in `<main>'

Push new version

Could you build and push a new version? The one on rubygems doesn't work for me, but cloned from github it does.

CLI is not working

The following commands did not work, along with hue all with any arguments:

Desktop zachfeldman  $ hue light 1 on --brightness 20
ERROR: "hue light" was called with arguments ["1", "on", "--brightness", "20"]
Usage: "hue light ID STATE [COLOR]"
Desktop zachfeldman  $ hue light 1 on --brightness 20 --saturation 20, --hue 62000
ERROR: "hue light" was called with arguments ["1", "on", "--brightness", "20", "--saturation", "20,"]
Usage: "hue light ID STATE [COLOR]"

Color formats (RGB, Hex, and HSL)

I saw this in the todo list and thought I'd give it a go. I wrote some classes to quickly generate the correct color values for the HUE. I'll post the pull request in a but for review but basically its implemented like this:
Calling RGB.new(123,231,222).to_hue, HexRGB.new("7BD5DE").to_hue or HSL.new(185.45, 0.60, 0.67).to_hue will return a hash containing the integer values for the HUE color like {:hue=>33760, :saturation=>153, :luminance=>172}

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.