Home Automation

As you may have seen I have the Amazon Echo at home. I liked the potential to make the echo the hub for home automation. The first step is to get something you can control so I set out to find something that works with Alexa natively so there would be no issues with integration. I searched Amazon for the a switchable plug that I could plug my living room light in to. I found the TP-LINK HS100.打印

This is a wifi enabled smart plug. You plug it in and from an Android app set it up on your wi-fi network. Once it’s set up you just ask Alexa to look for new devices and it will find the smart plug. Through the set up you designate a name for the device so now you can say something like “Alexa turn on the living room light” and it will switch it on and say “OK”. This is cool and how I work my living room light today. Of course the light is just one thing you can turn any item on that is plugged in to the smart plug. It is just a simple way to power on and power off. This is the beginning of automating the home of course, the smart plug is about $30 so this could be an expensive way to avoid turning a light switch. I will admit that I got mine a lot cheaper than that, it was on sale and I had a gift card from a survey so I ended up paying about $4 out of pocket.  Since we have had that light operated by Alexa we have wished that we had one for the bedroom light so that it would be on when we go upstairs. Now imagine, instead of saying “Alexa turn off the living room light” at the end of the day we could say “Alexa its bed time” and have her turn off the living room light, turn off the tv and the tuner, turn on the bedroom light, set the alarm, check the garage door is closed, and start the sounds of the sea music. – Well, this is possible if you introduce something like Openhab. What is this you ask, here’s a brief description of Openhab

If you looked at it you probably noticed that it’s a work in progress. I jumped onboard seeing that they had just released Openhab2 so I thought we would go right in there. It’s a bit of a nightmare to understand and set up especially since the transition to Openhab2 as there are lot of artifacts that have not been ported yet. As you probably know I am a Linux enthusiast. I just love having the flexibility and power without all the bloating. I am adept at Linux administration as I was once a certified Solaris (Unix) administrator.  I have always loved scripting and have found some amazing things you can do with simple scripts. Imagine my excitement when I leafed through the Openhab documents to see that there is a “binding” that will allow you to execute a Linux script. That means almost anything you can do with a script can be done from within Openhab.

Looking at the available bindings there is a binding that will allow you to integrate Alexa into the system. There are also binding for many different home automation devices. So, where to start….

I decided that the best way to get this set up would be to use my laptop, which runs Ubuntu Linux, to set this up. It is a convenient place to play with it, if I can make it work reliably I will move the whole configuration to one of my Linux servers. Looking at the options you can manually install Openhab from a Zip file which looks like it may introduce the potential for disaster with so many moving parts  or you can install using apt-get (automated installation). I decided to go with the latter.

After installation I was expecting to just be up and running but that was far from the case. It took me ages to figure out what was going on. You must have Oracle’s Java installed, this is not difficult but once you have it installed you have to make sure that the paths are correct to make it work. Once you have Java working you can install the Openhab software by following their instructions. I did all that, added the services to my Linux machine and nothing, so I checked all the logs (syslog proved to be the most helpful) and found that the software was not running properly. I ran the start script in debug mode as root and for the first time I was able to access the Openhab interface. It seemed to be operating so I shut it all down and let the systemctl start it. Nothing started, I went through the logs again and found there were all kinds of permission problems, it seems running it as root a lot of files were created by root and now inaccessible to the openhab user. Lots of clean up later, I made openhab the owner of all the obvious files and deleted some that seemed to be temporary. This time everything started. – You probably just read that section in a matter of minutes, this was two days of work!!!

So now I have a “working” Openhab but what does that mean. It doesn’t have anything that it can do yet. Here comes the fun part. The openhab installation had 3 UI’s by default, the basic, classic and paper UI’s. Which one should I use? Which one is best? What’s the difference? I have no idea why they have 3 different interfaces, it seems to me that it would be better to pick one and run with it. So I delve into each of them and notice there is nothing in there however, in the paper UI I can go into the configuration and bindings and add some bindings. – So, what does something that doesn’t need to much tinkering. There’s the system binding that appears to show various stats for the local computer and the Yahoo weather binding which seems to show the weather (in Celsius). So I installed these binding and went to the control and they are there quite pretty. I can see the weather and stuff about my computer but I can’t control anything.

Being the proud owner of the TP-Link HS100 I look for the “item” on the already approved items, guess what? It’s not there. Lot’s of other smart stuff including the Wemo smart plug but I don’t want to go and have to buy another smart plug I already have one! A quick search on the Internet and sure enough I find a very cool script that can switch the TP-Link plug on and off. Using the very simple instructions I am able to run the script and turn the light on then off and query it’s status to know if the plug is on or off (this could be useful later).  OK, that was easy now all I have to do is install the exec binding (the one that lets you run any script) and we should be good right? I went into the paper UI and installed the exec binding. Back in the UI under edit bindings there is no sign of the exec binding. OK, no problem, I will just add the switch (script) and that will work. Um, how do I do that? There is apparently no easy way to add an item or site map for that matter. I had to go and research a site map and how that works then how to add an item. Fortunately the forums are full of questions like that and there is a lot of info on github. The only issue you run into is that a lot of the information out there pertains to Openhab 1 not 2 but I finally managed to get through all of that and came up with a starter site map, an item and the script to work it. I added all of it to the relevant places in /etc/openhab restarted Openhab and went into the paper UI to see where my sitemap was.  There was no sign of any of it and no evidence that anything showed up in any of the logs. My sitemap is called default.sitemap and according to the documentation that should be the one loaded but it wasn’t. I tried using the url and including the sitemap name but that didn’t load it either. I read there is a way in the basic UI to select a sitemap. I tried that and finally found my sitemap, after a couple of tweaks I was able to access the switch and turn the living room light on and off. – Now that’s progress!

This is where I am now, I need to research the Echo link so I can have Alexa do what she can already do but then we have opened the door to be able to do a lot more. I will update the blog when I have more. In the meantime I am going to document exactly how I set this up here so I can replicate it on another machine.

UPDATE**

I have continued down the path with home automation. I am getting more familiar with openHAB2 which in itself is a dynamic ever growing system. After getting the first plug to work I added two others, these were different make and model but worked in the same way. Very simple on and off using a script to drive them. So far so goo. Then I wanted to automate some light switches. In order to do that the easiest route is to replace the in-wall switch with a zwave switch.

Of course to use zwave at all you must have a zwave controller device. I looked on ebay and found a controller switch that I thought was compatible, it turned out that the device was not compatible and so I had to look for another device  (sigh). I found the Aeon Labs DSA02203-ZWUS Z-Stick which is a popular device among openHAB users. Once I bought this device I could set up a zwave network.

I looked on-line and found that the Zooz dimmer switches were a good value. I bought my first one and wired it into the wall. You have to ensure that you have neutral wire in the wall or you will not be able to use the switch. Fortunately I did, so I was off to the races, or so I thought. The first road block was that the Zooz switch was not recognized. openHAB has a database of devices and if your device is not in there it won’t recognize it. The database is required to describe to the controller what the capabilities are of the zwave item. Eventually I was able to get the Zooz device added to the database, got the controller to recognize it using HABmin and sure enough I could then expose the switch to Alexa and say “Alexa turn off the dining table light” – This worked so well that I bought another switch for the kitchen lights and did the same thing. As it was already in the database this worked straight away. Once you have a few devices working with your home automation the fun can begin.

openHAB2 has an http binding that allows you to send http requests to devices that understand them. Well, the Roku is one such device, so with careful setup I was able to get the Roku working and then I purchased a Harmony Hub to work my IR devices (TV, Tuner etc,). Now with one simple sentence, “Alexa turn on Movie Time” I can turn off the lights, turn on the TV, the tuner and tune the Roku to PSVue ready to watch a movie/tv. – Very cool.

In addition to all of the other things, I have been able to install and configure a zwave thermostat so now Alexa can turn on the heat/cooling, home today, or vacation mode. One point to note, anyone can ask Alexa to do this, “oh the security concern” I hear you say. Well, think back to before Alexa could control this anyone in my house could turn on the lights, the TV or the heat. I like being able to have Alexa do all this stuff for me and some of it automated based on time, or the elevation of the sun, or whether someone is home or not.

I intend to keep automating and have Alexa do as many chores as she can. I wish she could control our robot vacuums but they just don’t speak network yet 😉