Wink Hub integration with OpenHAB for local control

.

Lighting Automation.

The best smart bulb on the market (price & performance) is probably the GE Link bulb.  For $15, you get a dimmable 800 lumen, 12W LED light bulb that’s controlled via Zigbee.  Problem is, how do you control it?  How do you automate it?

Mi Casa Verde’s Vera hub?  No.  No Zigbee radio (as of December 2014 anyways).

SmartThings hub?  It’ll work, but you’re forced to use “the cloud”, so if you lose internet (or if ST cloud goes down) you can’t control your lights.  But the combination of the ST hub and their Arduino shield gives some alternative methods of lighting control without having to pull out a smart phone.

Wink hub?  Same problem as the SmartThings hub (cloud required).  That is, until I ran into this and this.  So now you can root the hub, and have a means of controlling connected bulbs locally, without haivng to go through Wink’s servers.  Since I already have so much stuff integrated with OpenHAB, I wanted to do local control via OpenHAB.  And I really don’t like having to depend on the internet to control lights.

Follow the previous two links to root the hub.  Next, do the OpenHAB integration using the configuration below.

This is how OpenHAB is used to control Wink Hub

This is how OpenHAB is used to control Wink Hub

.

OpenHAB screen for controlling GE Link bulbs.

OpenHAB screen for controlling GE Link bulbs.

.

You can get fancy with the scenes and control both the bulbs that are on and the individual brightness.

Once the lights are integrated with OpenHAB, they can be used in conjunction with Arduino wireless motion sensors or door sensors to do automation.  Or maybe use the lights to indicate that the laundry is complete.  The Hub can be completely blocked off from the internet (and Wink servers) with your router’s access restrictions.

If you’re looking for a quick way to control the lights without having to pull out a smart phone or open up a browser, an Arduino or Pi with a IR sensor can be used to receive lighting control from a TV remote.  The same shell commands can be activated via MQTT.  There’s not very many options in the market for hand-held or wall mounted automation remotes.

Voice Control, Star Trek Style, without any button press.

Voice control is also possible with OpenHAB.  Normally, this requires pressing a button prior to giving the voice command, but it’s also possible to do voice control without any prior button presses.  An Android phone/tablet with Tasker and the Autovoice plugin can be used to run HTTP post commands directly to the OpenHAB items.  Autovoice allows full time voice recognition, so you don’t have to press any buttons to initiate the command.  And newer version of Android have the option of downloading the language to the device, so you can keep things local, no internet required.  This would be a nice setup for a wall-mounted interface.

1.  Create two tasks, lights-on and lights-off.  Each task sends a HTTP GET command like this:

Server:Port
openhabuser:openhabpassword@192.168.x.x:8080

Path:
CMD

Attributes:
itm_lights_livingroom=OFF
or
itm_scene_livingroom=2

2.  Create two profiles.  Event > Plugin > AutoVoice > Recognized.  Edit the configuration with filter word (“on” or “off”), and go down to Trigger word.  I used the trigger word “computer” so I feel like Captain Picard.  The trigger word is important because I’m running Autovoice recognition continuously.  It’s the equivalent of “Simon saids”.  This prevents you from accidentally turn off lights while in conversation.

As commentary, I’m pretty uncomfortable with Wink amassing a database of wifi passwords and locations where they can be used.  When you setup the hub, you need to enter your wifi password.  And the Wink app gets your phone’s GPS signal (it’s one of the permissions) to do geofencing.  OpenHAB can do most of these types of automation tasks, but gives you more control over sensitive data.

The downside to this method is that it’s unidirectional.  I can control the lights, but I can’t get the status of the bulbs.  Or of other z-wave or zigbee devices connected via the hub.  If anyone knows of a way to catch call backs from devices, or install a daemon on the hub itself to perhaps parse aprontest commands and send results via MQTT to the Raspberry Pi, that would be cool.

I hope some company will use open source firmware for their home automation hub, and spawn the first WRT54G of home automation hubs.

Configuration:

Item Definition

Switch itm_lights_livingroom "Living Room Lights"
Number itm_scene_livingroom "Scene"
Number itm_lights_lvl_livingroom "Level [%.1f]"
Switch itm_livingroom_night_light_enb "Auto Night Night"
Switch itm_livingroom_motion_enb "Motion Control"

Sitemap Definition

        Frame label="Lights"
        {
        Text label="Living Room Lights" icon="light-on" {
                Frame label="Living Room Lights" {
                        Switch item=itm_lights_livingroom label="Living Room Lights" mappings=[OFF="Off"]
                        Selection item=itm_scene_livingroom label="Bulb Pattern" mappings=[1=Bright, 2=General, 3=Evening, 4=Dim]
                        Switch item=itm_scene_livingroom label="Bulb Pattern" mappings=[1=Bright, 2=General, 3=Evening, 4=Dim]
                        Selection item=itm_lights_lvl_livingroom label="Brightness" mappings=[1="1%", 10="10%", 30="30%", 60="60%", 80="80%", 100="100%"]
                        Switch item=itm_livingroom_night_light_enb
                        Switch item=itm_livingroom_motion_enb
                }
        }//end text label livingroom lights
        }//end frame label lights

Rules Definition

/* living room lighting */

rule "Living Room Lights Off"
    when
        Item itm_lights_livingroom received update
    then
        executeCommandLine("/opt/myscripts/LivingRmOff.sh");
        say("Lights Off")
end




rule "Living Room Lights Pattern"
        when
                Item itm_scene_livingroom received update
        then
                if(itm_scene_livingroom.state == 1)
                {
                        executeCommandLine("/opt/myscripts/LivingRmPattern_1_bright.sh");
                        say("Bright")
                }
                if(itm_scene_livingroom.state == 2)
                {
                        executeCommandLine("/opt/myscripts/LivingRmPattern_2_general.sh");
                        say("General")
                }
                if(itm_scene_livingroom.state == 3)
                {
                        executeCommandLine("/opt/myscripts/LivingRmPattern_3_evening.sh");
                        say("Evening")
                }           
                if(itm_scene_livingroom.state == 4)
                {
                        executeCommandLine("/opt/myscripts/LivingRmPattern_4_dim.sh");
                        say("Dim")
                }
end


rule "Living Room Lights Dimming"
        when
                Item itm_lights_lvl_livingroom received update
        then
                if(itm_lights_lvl_livingroom.state == 1)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_1.sh");
                        say("One Percent")
                }
                if(itm_lights_lvl_livingroom.state == 10)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_10.sh");
                        say("Ten Percent")
                }
                if(itm_lights_lvl_livingroom.state == 30)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_30.sh");
                        say("Thirty Percent")
                }
                if(itm_lights_lvl_livingroom.state == 60)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_60.sh");
                        say("Sixty Percent")
                }
                if(itm_lights_lvl_livingroom.state == 80)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_80.sh");
                        say("Eighty Percent")
                }
                if(itm_lights_lvl_livingroom.state == 100)
                {
                        executeCommandLine("/opt/myscripts/LivingRmDim_100.sh");
                        say("One Hundred Percent")
                }
end


rule "Living Room Auto Night Light"
    when
        Time cron "0 0 23 * * ?"   // Every day 23:00 hours, evaluate sunset
        
    then
        if (itm_livingroom_night_light_enb.state == ON)
        {
            executeCommandLine("/opt/myscripts/LivingRmPattern_4_dim.sh");
            say("Turn On Night Lights")
        }
end

Shell scripts.  Change the devices to match your bulb’s designations and Wink Hub IP address.

LivingRmDim_1.sh

curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m1 -t2 -v 1;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m2 -t2 -v 1;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m3 -t2 -v 1;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m4 -t2 -v 1;"

LivingRmDim_10.sh

curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m1 -t2 -v 25;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m2 -t2 -v 25;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m3 -t2 -v 25;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m4 -t2 -v 25;"

LivingRmDim_100.sh

curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m1 -t2 -v 252;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m2 -t2 -v 252;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m3 -t2 -v 252;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m4 -t2 -v 252;"

LivingRmOff.sh

curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m1 -t1 -v OFF;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m2 -t1 -v OFF;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m3 -t1 -v OFF;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m4 -t1 -v OFF;"

LivingRmPattern_3_evening.sh

curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m1 -t1 -v OFF;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m2 -t1 -v OFF;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m3 -t1 -v ON;"
curl "http://192.168.2.32/set_dev_value.php" -d "nodeId=a&attrId=aprontest -u -m4 -t1 -v ON;"