在 Raspberry Pi 中使用 OpenHAB 控制 Philips Hue

Controlling Philips Hue using OpenHAB in Raspberry Pi

我想用OpenHAB控制飞利浦Hue Lux彩灯。所以我想知道我应该采取什么步骤以及是否遗漏了什么。

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

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

我有
:

/* 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"}

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

我有:

############################### 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

我 运行 它使用 sudo ./start.sh 然后将 Hue 集线器与 OpenHAB 配对。我不是缺少什么,因为我仍然无法用 OpenHAB 控制色调。

我的主要努力是将网络 UI 连接到 openHAB 中的代码。非常感谢任何指针!我还从各种教程中拼接了上面的代码,所以它可能根本没有意义!

使用 *.sitemap 文件更改 UI 的外观。 此文件定义 UI 中显示的方式和内容: https://github.com/openhab/openhab/wiki/Explanation-of-Sitemaps

至于示例的其余部分: - 你确定 Hue 桥的 IP 和秘密吗? - 桥上连接了多少个灯泡?因为在 *.items 文件中 hue=1 表示第一个连接到你的桥的灯泡。

是随机的,但您还必须配对网桥。你知道至少一个灯泡可以打开和关闭吗?

只是检查一下,但是您的 switchscene 项目不叫 switch 和 scene 是吗?

绑定很挑剔,您可能必须为每个绑定声明变量类型:

var DecimalType hue = new DecimalType(240) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
var PercentType sat = new PercentType(100) // 0-100
var PercentType bright = new PercentType(100) // 0-100
var HSBType light = new HSBType(hue,sat,bright)
sendCommand(Light_GF_Lounge_C, light)

虽然坦率地说,绑定有点麻烦,你最好直接使用 API,然后设置你在应用程序或其他东西中设置的场景。

或直接

rule "Set lights"
when
    Item Switch_Lounge received update ON
then
    var String hueApiCall = "curl@@-X@@PUT@@-d@@{\"on\": %s, \"hue\":%d , \"sat\": %d, \"bri\": %d, \"transitiontime\": %d}@@http://192.168.1.147/api/YOURPAIREDHUEUSERID/groups/%d/action"
    executeCommandLine(String::format(hueApiCall, true, 13088, 212, 100, 10, 2 ))
end

executeCommandLine中的每个值按顺序匹配 % 占位符,在此示例中:true,色调:13088,sat:212,bri,100,过渡时间:10,第 2 组

使用该语法,您可以设置场景、警报等等。