openHAB and Z-Wave

wpsuperadmin HomeAutomation, openhab 1 Comment

Now that openHAB is chugging along nicely, I would like to be able to start controlling devices using off the shelf parts. There seems to be two standards widely used Z-Wave and Zigbee. So far it appears light bulbs are mostly Zigbee and switches/thermostats/door locks are Z-Wave. You can get Z-Wave light bulbs but as of this post, they cost twice as much. Zigbee is what the Xbee is based on and it isn’t as standardized across manufacturers like Z-Wave. To be as flexible as possible in the end, I want to have both radios available to openHAB.

One way to do this is via a rooted Wink Hub. My co-worker really likes the Wink Hub as it has worked out well for him, but he is solely using it and not integrating it. If I had gone with this solution, it would of cost me less but in the end it wouldn’t have been as flexible – depending on their device database, require polling, and requiring another app and point of failure. Also unless you root it you are using their cloud service, plus its hard to root after its been updated. The nice thing is it has all the radios: Z-Wave, Zigbee, and Bluetooth. What would be cool is to root it and take control of everything directly (found openWink). Of course there are other controllers like SmartThings by Samsung that has an API and the ability to add unsupported devices. The last one I came across was the VeraLite. These are all more expensive than the Wink.

Upon reviewing many bytes across the web, I decided upon the Aeotec Z-Stick Gen5 Z-Wave USB controller. This works directly with openHAB, it’s even listed on their site. Using HABmin you can setup the device and the Z-Wave network. Upon looking at their other products I am quickly liking them and I’d like to order more. One of each please! I ordered the older version of the Smart Outlet Energy Switch for testing. They even have a smart film for controlling the transparency of glass. Just like the movies! This is one of those times I wish I was younger just so I can see what the future will be like when home automation is mainstream.

The Z-Stick is an interesting device. It has a battery so you can go to the remote device and pair it. The thought is, you want to pair the device where it will be used so that it can build the mesh network in relation to its neighbors. Currently, I only have one Z-Wave device so my network map isn’t very interesting.

As with other add-ons to openHAB, make sure and load the Z-Wave binding. I had HABmin installed already and it had included an older version of the binding so I had to remove that as it was conflicting. The USB stick gave me a bit of a headache trying to get openHAB configured to the correct serial port. With Linux you will have to give the openHAB user the dial-out group so I can even talk to the Z-Stick. In my case it ended being /dev/ttyAM0. The issue is it may change to /dev/ttyAM1 after a reboot or if you reinsert it. The solution is to create a symlink so that no matter the name, openHAB can find it. I have yet to set that up yet.

The configuration is held in the openhab.cfg file found in /usr/share/openhab/configuration/. Here is what my Z-Wave section looks like.

openhab.cfg

 
################################ Z-Wave Binding ######################################
#
# The Z-Wave controller port. Valid values are e.g. COM1 for Windows and /dev/ttyS0 or
# /dev/ttyUSB0 for Linux
zwave:port = /dev/ttyACM0
zwave:masterController=true

# Z-Wave nightly heal time. This is the hour (eg 2AM) at which the automatic nightly
# network heal will be performed.
zwave:healtime = 2

Just as before, the items file has to be setup first so openHAB knows about the device to link to it. The Smart Energy Switch has three elements: power switch, energy usage(kWh), and current energy(W). I wish it could report Volts and Amps or at least one of the two so you can calculate the rest. This config took awhile to figure out and get going – so here it is to save you the trouble/time.

livingroom.items

 
Switch switch_living "Switch" {zwave="2:command=SWITCH_BINARY,meter_reset=true"}
Number watt_living "Living Lights [%.2f W]" {zwave="2:command=METER,meter_scale=E_W,refresh_interval=60"}
Number kwh_living "Switch [%.2f KWh]" {zwave="2:command=meter,meter_scale=E_KWh,refresh_interval=60"}
String energy_switch "Energy [%s]"

Long story short, I wanted the energy readings on the same line as the switch but you can’t have different types together. So I settled for one line for the switch and one for the energy readings. I should be able to add the date/time (for last seen status) to that later on. For this to work you have to create a rule to doing the combining every time there is an update. In the above items file you can see the last line has an extra variable. That is to store the combined energy readings.

combine.rules

 
rule "Merge items"
when
Item watt_living received update or
Item kwh_living received update or
Item switch_living received update
then
energy_switch.postUpdate(watt_living.state.toString + "W " + kwh_living.state.toString + " kWh")
end

Then we have the sitemap to display the values. I left the original text items that can be used during testing.

default.sitemap

 
Frame label="Livingroom" icon="sofa" {
Switch item=switch_living
//Text item=watt_living
//Text item=kwh_living
Text item=energy_switch label="Energy [%s]"
}

That is pretty much the basics of getting a USB Z-Wave controller working. I can’t wait to add some more devices. The next post will be about adding a Zigbee radio or at least a way to bridge over to a Zigbee network.

Here are some of the links I used in my travels to get this all working.
https://github.com/openhab/openhab/wiki/Z-Wave-Binding
https://github.com/cdjackson/HABmin2/wiki/ZWave-Device-Installation
https://github.com/cdjackson/HABmin/wiki/Z-Wave-Configuration
http://www.homeautomationforgeeks.com/openhab_zwave.shtml
http://smarthome.hallojapan.de/category/openhab/
http://smarthome.hallojapan.de/2015/06/setting-up-the-aeon-labs-z-wave-multisensor-for-openhab/

One last note: I am seeing an issue that the Z-Wave switch item isn’t being updated if I use the manual override button on the device itself. I will have to look into this.

Comments 1

  1. Just stopping by to say thanks for the content! I had already purchased a Raspberry Pi 2 + the Z Wave stick you mentioned and am waiting on it to show up tomorrow. I also had ordered the exact same Aeon switch you did for testing. What are the odds? Look forward to delving into openHAB with you!

Leave a Reply