GithubHelp home page GithubHelp logo

rv-kip / hue-cli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bahamas10/hue-cli

0.0 1.0 0.0 114 KB

A command line interface to phillips hue

Home Page: http://bahamas10.github.com/hue-cli/

hue-cli's Introduction

hue(1)

A command line interface to phillips hue

Installation

First, install Node.js, then:

npm install -g hue-cli

...and the executable will be installed globally as hue

Usage

Usage: hue [-H host] [--json] [command]

control phillips hue over the command line

examples
  hue config                  # view the hue config
  hue lights                  # get a list of lights
  hue lights 5                # get information about light 5
  hue lights 5,6,7 on         # turn lights 5 6 and 7 on
  hue lights on               # turn all lights on
  hue lights 1 ff0000         # turn light 1 red
  hue lights 1 red            # same as above
  hue lights 4,5 colorloop    # enable the colorloop effect on lights 4 and 5
  hue lights 4,5 clear        # clear any effects on lights 4 and 5
  hue lights 1 state          # set the state on light 1 as passed in as JSON over stdin
  hue help                    # this message
  hue register                # register this app to hue
  hue search                  # search for hue base stations

commands
  config, lights, help, register, search

options
  -h, --help     print this message and exit
  -H, --host     the hostname or ip of the bastion to control
  -i, --init     initialize the config file at ~/.hue.json
  -j, --json     force output to be in json
  -u, --updates  check for available updates
  -v, --version  print the version number and exit

Example

starting off

First, let's search for nearby base stations

$ hue search
1 stations found

1: 10.0.1.218

Pass in -j for json if you'd like

$ hue -j search
[
  "10.0.1.218"
]

Next, let's try to list the lights on that base station

$ hue -H 10.0.1.218 lights
error: application not registered, run `hue register` first

This app isn't registered yet, let's go ahead and do that

$ hue -H 10.0.1.218 register
please go and press the link button on your base station
Hue Base Station paired!

listing lights

All you had to do was press the button on your base station to register, cool right? Let's re-run the lights command

$ hue -H 10.0.1.218 lights
   1 Mike 1
   2 Mike 2
   3 Dave closet
   4 Hallway 2
   5 Hallway 1
   6 Front hallway
   7 Dave Ledge Left
   8 Dave Ledge Right
   9 Dave's Piano
  10 Dave's Lamp
  11 Balcony Mike
  12 Balcony Dave
  13 Balcony Living Room
  14 Mike 3
  15 Living room 3
  16 Living room 1

Again, -j if you'd like json output.

Running with the command lights will give us a list of all the lights connected to the base station.

Before we continue, let's create a configuration file. In the file we can set the default host to connect to, so we don't have to keep supplying the -H argument. Run:

$ hue --init
config file written to `~/.hue.json`

Now, modify that file and replace null with 10.0.1.218, or whatever your IP or hostname is. Now we'll no longer have to supply the -H argument with every command.

From here, we can get information about a single light like:

$ hue lights 1
   1 on    Mike 1

And -j for json

$ hue -j lights 1
{
  "state": {
    "on": true,
    "bri": 141,
    "hue": 13122,
    "sat": 211,
    "xy": [
      0.5119,
      0.4147
    ],
    "ct": 467,
    "alert": "none",
    "effect": "none",
    "colormode": "ct",
    "reachable": true
  },
  "type": "Extended color light",
  ...
}

controlling the lights

Let's actually mess with the lights now. Let's turn on the light in my closet.

$ hue lights 3 on
light 3 success

What about both lights in the hallway?

$ hue lights 4,5 on
light 4 success
light 5 success

What if we try to turn on a non-existent light?

$ hue lights 99 on
light 99 failed: resource, /lights/99/state, not available

Cool, errors handled properly. Let's see some more examples

$ hue lights off
light 1 success
light 2 success
light 3 success
...

This is shorthand for

$ hue lights all off

Where all is a recognized keyword for all lights in the system. You can also:

$ hue lights off

To quickly turn off all lights on the system

controlling colors

We can turn the lights on and off, that's great... what about colors?

How about hex

$ hue lights 4 ffffff
light 4 success

We just set the light in the hallway to pure white, hex ffffff. Let's go crazy and turn all of the lights in the house red (this is where we need the all keyword)

$ hue lights all ff0000
light 1 success
light 2 success
...

It's worth noting here that, because this tool is written in Node, all requests to the lights are done concurrently. This means we don't have to wait for light 1 to finish before we instruct light 2 to change, nor wait for light 2 to finish before we instruct light 3 to change, and so on.

Shorthand hex is also supported

$ hue lights 3,4 0f0
light 3 success
light 4 success

Now lights 3 and 4 are green

Last but not least, any CSS name is supported for colors

$ hue lights 1 yellow
light 1 success

Light 1 is now yellow. The full list of colors is available here http://xahlee.info/js/css_color_names.html

effects

You can enable the colorloop effect on lamps by running

$ hue lights 4,5,6 colorloop
light 4 success
light 5 success
light 6 success

and clear all effects with

$ hue lights 4,5,6 clear
light 4 success
light 5 success
light 6 success

debugging

Last but not least, you can pass the state as JSON over stdin. The possible values are found at http://developers.meethue.com/1_lightsapi.html in section 1.6.

$ echo '{"bri": 240, "hue": 25500}' | hue lights 7 state

The state keyword tells hue to read from stdin

Config

An optional config file can be created at ~/.hue.json that looks like...

{
  "host": "1.2.3.4",
  "colors": {
    "myred": "fe0000",
    "myblue": "0000fe"
  }
}
  • host: the host to connect to (normally passed in as -H)
  • colors: a key-value pair of color aliases to their hex mapping, you can use these when changing the colors of a light

Credits

License

MIT

hue-cli's People

Contributors

bahamas10 avatar

Watchers

 avatar

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.