Controlling Philips Hue using OpenHAB in Raspberry Pi

Mona Jalal picture Mona Jalal · Mar 10, 2016 · Viewed 7.1k times · Source

I want to control the Philips Hue Lux color lamps with OpenHAB. So I wonder what are the steps I should do and if I am missing something.

In pi@raspberrypi:/opt/openhab/configurations/rules $ sudo vi demo.rules

rule "Select scene"
    when
        Item scene received command
    then
        switch(receivedCommand) {
            /*alles uit */
            case 0 : {
            sendCommand(Toggle_7, OFF); 
            sendCommand(Toggle_3, OFF);
            sendCommand(Toggle_1, OFF);
            sendCommand(Toggle_10, OFF);
            sendCommand(Toggle_11, OFF);
            sendCommand(Toggle_5, OFF);
            sendCommand(Toggle_9, OFF);
            }
            /*sfeer */
            case 1 : { 
            sendCommand(LWD_3, 90);
            sendCommand(Color_7, "45.584415,86.033516,70.19608");
            sendCommand(Color_1, "45.584415,86.033516,70.19608");
            sendCommand(Color_10, "45.584415,86.033516,70.19608");
            sendCommand(Color_11, "45.584415,86.033516,70.19608");
            sendCommand(Color_5, "45.584415,86.033516,70.19608");
            sendCommand(LWD_9,10);
            }
            /*Alles aan */
            case 2 : {
            sendCommand(Toggle_7, ON); 
            sendCommand(Toggle_3, ON);
            sendCommand(Toggle_1, ON);
            sendCommand(Toggle_10, ON);
            sendCommand(Toggle_11, ON);
            sendCommand(Toggle_5, ON);
            sendCommand(LWD_9,100);
            }
            /*eten */
            case 3 : {
            sendCommand(Toggle_3, OFF);
            sendCommand(Color_7, "42.391304,73.6,100.0");
            sendCommand(Color_1, "42.391304,73.6,100.0");
            sendCommand(Color_10, "42.391304,73.6,100.0");
            sendCommand(Color_11, "60,42,100");
            sendCommand(Color_5, "60,42,100");
            sendCommand(LWD_9,10);        
            }
            case 4 : {
            /*nacht */
            sendCommand(LWD_9, 50);
            sendCommand(Color_7, "46.25,37.64706,100.0");
            sendCommand(Color_10, "46.25,37.64706,100.0");
            sendCommand(Toggle_1, OFF);
            sendCommand(Toggle_3, OFF);
            sendCommand(Toggle_11, OFF);
            sendCommand(Toggle_5, OFF);
            }
            case 5 : {
                /* Sunset */
            sendCommand(Color_7, "42.391304,73.6,100.0");
            sendCommand(Color_1, "42.391304,73.6,100.0");
            sendCommand(Color_10, "42.391304,73.6,100.0");
            sendCommand(Color_11, "42.391304,73.6,100.0");
            sendCommand(Color_5, "42.391304,73.6,100.0");
            sendCommand(Toggle_3, OFF);
            sendCommand(LWD_9,10);        
            }
            case 6 : {
                /* Aqua */
            sendCommand(Color_7, "230.82353,100.0,100.0");
            sendCommand(Color_1, "230.82353,100.0,100.0");
            sendCommand(Color_10, "230.82353,100.0,100.0");
            sendCommand(Color_11, "230.82353,100.0,100.0");
            sendCommand(Color_5, "230.82353,100.0,100.0");
            sendCommand(Toggle_3, OFF);
            sendCommand(LWD_9,10);        
            }
            case 7 : {
            /* Duo */
            sendCommand(Color_7, "272,100.0,100.0");
            sendCommand(Color_5, "272,100.0,100.0");
            sendCommand(Color_1, "330,100.0,100.0");
            sendCommand(Color_10, "330,100.0,100.0");
            sendCommand(Color_11, "330,100.0,100.0");
            sendCommand(Toggle_3, OFF);
            sendCommand(LWD_9,10);        
            }

            case 8 : {
            /* Duo ambilight play */
            sendCommand(Color_7, "272,100.0,30.0");
            sendCommand(Color_5, "272,100.0,30.0");
            sendCommand(Color_1, "330,100.0,30.0");
            sendCommand(Color_10, "330,100.0,30.0");
            sendCommand(Color_11, "330,100.0,30.0");        
            }
            case 9 : {
            /* Duo ambilight pauze*/
            sendCommand(Color_7, "272,100.0,100.0");
            sendCommand(Color_5, "272,100.0,100.0");
            sendCommand(Color_1, "330,100.0,100.0");
            sendCommand(Color_10, "330,100.0,100.0");
            sendCommand(Color_11, "330,100.0,100.0");
            }
        }
end

in pi@raspberrypi:/opt/openhab/configurations/items $ vi demo.items

I have
:

/* Hue */
Switch Toggle_1   "left bulb"   (Switching) {hue="1"}
Switch Toggle_2   "center bulb" (Switching) {hue="2"}
Switch Toggle_3       "right bulb"  (Switching) {hue="3"}

Color Color_1     "left bulb"   (Colorize)  {hue="1"}
Color Color_2         "center bulb" (Colorize)  {hue="2"}
Color Color_3     "right bulb"  (Colorize)  {hue="3"}

Dimmer Dimm_1     "left bulb"   (WhiteDimmer)   {hue="1;brightness;30"}
Dimmer Dimm_2     "center bulb" (WhiteDimmer)   {hue="2;brightness;30"}
Dimmer Dimm_3     "right bulb"  (WhiteDimmer)   {hue="3;brightness;30"}

Dimmer CT_Dimm_1      "left bulb"   (CTDimmer)  {hue="1;colorTemperature;30"}
Dimmer CT_Dimm_2      "center bulb" (CTDimmer)  {hue="2;colorTemperature;30"}
Dimmer CT_Dimm_3      "right bulb"  (CTDimmer)  {hue="3;colorTemperature;30"}

in pi@raspberrypi:/opt/openhab/configurations $ vi openhab.cfg:

I have:

############################### Philips Hue Binding ###################################
#
# IP address of Hue Bridge (optional, default is auto-discovery)
hue:ip=192.168.1.117
hue:secret=openHABRuntime
hue:refresh=10000

I ran it using sudo ./start.sh and then paired the Hue hub with OpenHAB. I am not what is missing because still I can't control the Hue with OpenHAB.

enter image description here

enter image description here

enter image description here

My main struggle is connecting the web UI to the code in openHAB. Any pointer is really appreciated! Also I have stitched the code above from various tutorials so it possibly would make no sense at all!

Answer

LeonG picture LeonG · Mar 10, 2016

Changing how the UI's look is done with the *.sitemap files. This files define how and which items are shown in the UI: https://github.com/openhab/openhab/wiki/Explanation-of-Sitemaps

As for the rest of the example: - Are you sure about the ip and secret of the Hue bridge? - How many light bulbs are connected to the bridge? Because in the *.items file hue=1 means the first bulb connected to your bridge.