Difference between revisions of "Install Hue"

From xPL
Jump to: navigation, search
(Ubuntu)
(Create a control user)
 
(11 intermediate revisions by one user not shown)
Line 2: Line 2:
 
The bridge API implements a [http://en.wikipedia.org/wiki/Representational_state_transfer#RESTful_web_APIs RESTful] web service using HTTP methods.
 
The bridge API implements a [http://en.wikipedia.org/wiki/Representational_state_transfer#RESTful_web_APIs RESTful] web service using HTTP methods.
  
Before all,make sure you have installed an [[install xpl hub|xPL hub]].
+
Before all, make sure you have installed an [[install xpl hub|xPL hub]].
  
 
= Access the Hue bridge =
 
= Access the Hue bridge =
Line 19: Line 19:
 
== Create a control user ==
 
== Create a control user ==
  
Access to the [http://developers.meethue.com API] is limited by a whitelist.
+
Access to the [http://www.developers.meethue.com/philips-hue-api API] is limited by a whitelist.
 
[http://developers.meethue.com/4_configurationapi.html#41_create_user Creating a new user] is done by pressing the link button on the bridge and then sending an HTTP POST request.
 
[http://developers.meethue.com/4_configurationapi.html#41_create_user Creating a new user] is done by pressing the link button on the bridge and then sending an HTTP POST request.
  
Trying without pressing the button:
+
Trying without having pressed the button:
 
  curl http://192.168.1.166/api -d '{"devicetype":"Linux machine","username":"xplHueDevice"}'
 
  curl http://192.168.1.166/api -d '{"devicetype":"Linux machine","username":"xplHueDevice"}'
 
will produce:
 
will produce:
Line 64: Line 64:
  
 
Install <code>HTTP::Tiny</code>:
 
Install <code>HTTP::Tiny</code>:
 +
sudo apt-get install libhttp-tiny-perl
 +
 +
or:
 
  su
 
  su
 
  perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' 2> /dev/null | grep -i http
 
  perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' 2> /dev/null | grep -i http
Line 69: Line 72:
 
  exit
 
  exit
  
Download the [http://www.dspc.ch/xPL/Downloads/xpl-hue.pl serial port xPL device] script.
+
Download the [http://www.dspc.ch/xPL/Downloads/xpl-hue.pl xPL Hue controller] script.
  
 
Move the script to xPL scripts directory:
 
Move the script to xPL scripts directory:
Line 82: Line 85:
 
  su control
 
  su control
 
  SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 
  SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
$SCRIPTS_BASE_DIR/xpl-hue.pl -h
 
  $SCRIPTS_BASE_DIR/xpl-hue.pl -vn hue
 
  $SCRIPTS_BASE_DIR/xpl-hue.pl -vn hue
  
 
Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:
 
Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:
 
  SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 
  SCRIPTS_BASE_DIR=/home/control/Documents/Controls
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.request device=3
+
$SCRIPTS_BASE_DIR/xpl-monitor.pl -vf
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=3 command=activate
+
 
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=3 command=deactivate
+
Open a 3rd terminal window (on any machine with xPL installed) and control the lights:
 +
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.request device=1
 +
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=1 command=activate
 +
  $SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=1 command=deactivate
 +
 
 +
The first <code>xpl-send</code> command asks for the status of the bulb.
 +
The answer is seen in the xPL traffic monitor.
  
 
= Launch the xPL Hue controller at startup =
 
= Launch the xPL Hue controller at startup =
  
The xPL serial port device is to be launched after the xPL hub.
+
The xPL Hue clock controller is to be launched after the xPL hub.
  
 
== Ubuntu ==
 
== Ubuntu ==
Line 131: Line 142:
 
  service xpl-hue start
 
  service xpl-hue start
 
  service xpl-hue status
 
  service xpl-hue status
 +
initctl list | grep xpl
 
  ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///'
 
  ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///'
  
 
== Mac OS ==
 
== Mac OS ==
  
On Mac OS, the xPL serial port device starts-up later than the hub.
+
On Mac OS, the xPL Hue controller starts-up later than the hub.
  
 
Edit <code>/Library/LaunchDaemons/xpl-hue.plist</code>:
 
Edit <code>/Library/LaunchDaemons/xpl-hue.plist</code>:
Line 164: Line 176:
 
  ps ax | grep -i xpl | grep -v grep
 
  ps ax | grep -i xpl | grep -v grep
  
[[Category: install]]
+
[[Category: all]] [[Category: install]] [[Category: xPL]]

Latest revision as of 09:08, 3 June 2015

The hue system consists of LED light bulbs connected via ZigBee to a bridge which is in turn connected to Ethernet. The bridge API implements a RESTful web service using HTTP methods.

Before all, make sure you have installed an xPL hub.

Access the Hue bridge

Discover the Hue bridge

The bridge can be discovered with the help of a web browser at URL: www.meethue.com/api/nupnp.

It can be discovered in a terminal by:

curl -G http://www.meethue.com/api/nupnp

which produces an answer similar to:

[{"id":"001788fffe09f498","internalipaddress":"192.168.1.166"}]

The data structure is represented in text form with the help of JSON (JavaScript Object Notation).

Create a control user

Access to the API is limited by a whitelist. Creating a new user is done by pressing the link button on the bridge and then sending an HTTP POST request.

Trying without having pressed the button:

curl http://192.168.1.166/api -d '{"devicetype":"Linux machine","username":"xplHueDevice"}'

will produce:

[{"error":{"type":101,"address":"","description":"link button not pressed"}}]

Do it again afer having pressed the button.

Configure the Hue bridge

Get configuration info:

curl -G 192.168.1.166/api/xplHueDevice/config

Change IP address:

curl 192.168.1.166/api/xplHueDevice/config -X PUT -d '{"ipaddress": "192.168.1.202"},"dhcp": false'
curl -G 192.168.1.202/api/xplHueDevice/config

Update the DNS server to attribute 192.168.1.202 to apollo.cofnet (god of the ligtht). Check IP address:

curl -G apollo.cofnet/api/xplHueDevice/config && echo

Hue bridge command line control

Get lights list:

curl -G apollo.cofnet/api/xplHueDevice/lights && echo

Get bulb state:

curl -G apollo.cofnet/api/xplHueDevice/lights/2 && echo

Turn light on and off again

curl apollo.cofnet/api/xplHueDevice/lights/2/state -X PUT -d '{"on": true}' && echo
sleep 1
curl apollo.cofnet/api/xplHueDevice/lights/2/state -X PUT -d '{"on": false}' && echo

Turn light on, red:

curl apollo.cofnet/api/xplHueDevice/lights/2/state -X PUT -d '{"on": true, "hue": 0, "sat": 255, "bri": 255}' && echo

Change to blue within 10 seconds:

curl apollo.cofnet/api/xplHueDevice/lights/2/state -X PUT -d '{"hue": 46920, "transitiontime": 100}' && echo

Install xPL Hue controller

Install HTTP::Tiny:

sudo apt-get install libhttp-tiny-perl

or:

su
perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' 2> /dev/null | grep -i http
perl -MCPAN -e "install 'HTTP::Tiny'"
exit

Download the xPL Hue controller script.

Move the script to xPL scripts directory:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
mv xpl-hue.pl $SCRIPTS_BASE_DIR
chown control:users $SCRIPTS_BASE_DIR/*.pl
chmod 775 $SCRIPTS_BASE_DIR/*.pl

Test xPL Hue controller

Test it on a BeagleBone:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-hue.pl -h
$SCRIPTS_BASE_DIR/xpl-hue.pl -vn hue

Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-monitor.pl -vf

Open a 3rd terminal window (on any machine with xPL installed) and control the lights:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.request device=1
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=1 command=activate
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c lighting.basic device=1 command=deactivate

The first xpl-send command asks for the status of the bulb. The answer is seen in the xPL traffic monitor.

Launch the xPL Hue controller at startup

The xPL Hue clock controller is to be launched after the xPL hub.

Ubuntu

On Ubuntu, the xPL Hue controller starts-up once xpl-hub_started has been emitted.

Edit /etc/init/xpl-hue.conf :

################################################################################
# xPL hue, controls Philips hue light bulbs
#
description "xPL hue"
version     "1.0"
author      "Francois Corthay"

#-------------------------------------------------------------------------------
# Configuration variables
#
env SCRIPTS_DIR='/home/control/Documents/Controls'
env SCRIPT_NAME='xpl-hue.pl'
env PARAMETERS='-n hue'

#-------------------------------------------------------------------------------
# Start and stop conditions
#
start on xpl-hub_started
stop on shutdown
respawn
setuid control
setgid users

#-------------------------------------------------------------------------------
# Start daemon
#
exec $SCRIPTS_DIR/$SCRIPT_NAME $PARAMETERS

Start the device and test it:

su root
service xpl-hue start
service xpl-hue status
initctl list | grep xpl
ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///'

Mac OS

On Mac OS, the xPL Hue controller starts-up later than the hub.

Edit /Library/LaunchDaemons/xpl-hue.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>xPL Philips hue controller</string>
    <key>OnDemand</key>
    <false/>
    <key>UserName</key>
    <string>control</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Users/control/Documents/Controls/xpl-hue.pl</string>
      <string>-n</string>
      <string>hue</string>
      <string>-w</string>
      <string>25</string>
    </array>
  </dict>
</plist>

Load the xPL client:

launchctl load /Library/LaunchDaemons/xpl-hue.plist
launchctl list | grep -i xpl 
ps ax | grep -i xpl | grep -v grep