Things Gateway, Part 3 - Z-Wave

In Part 2 of this series , I demonstrated loading and running the Things Gateway by Mozilla software onto a Raspberry Pi.  I showed how to use a DIGI XStick, which implements the Zigbee protocol, to run a light bulb and smart plug.

Today, I'm going to take that system and make it work with the Z-Wave protocol, too.  Then I'll demonstrate how to use a rule to make a Z-Wave switch follow the same state as a Zigbee switch.

Goal : add an Aoetec Z-Stick to the existing project, pair it with some Z-Wave devices, and, finally, demonstrate a rule that crosses over the barrier between the two protocols.  This addition to the project will maintain total local control so there should be no communication outside to the Internet.
Requirements & Parts List :

Item What's it for? Where I got it
The Raspberry Pi and associated hardware from Part 2 of this series. this is the base platform that we'll be adding onto from Part 2 of this series
Aeotec Z-Stick an adapter that enables the Things Gateway to talk Z-Wave Amazon
Aeotec Smart Switch 6 ZW096-A02 a Z-Wave switch to control Amazon
GE ZW1403 Smart Switch a Z-Wave switch to control (this device has been temperamental & may not be the best choice) Amazon

This part of the project is going to be ridiculously easy. We're starting with the system as it stood at the end of the last posting: a Things Gateway on an Raspberry Pi that only understands Zigbee devices.

To start, I unplugged the Raspberry Pi from its power supply.  I plugged the Aoetec Z-Stick into a USB port on the Raspberry Pi - recognizing that the existing DIGI XStick had to be repositioned for both to fit.  I then reapplied power to the Raspberry Pi and it booted.  I assembled all the lights for this experiment.

From left to right: a grocery store LED bulb on the Z-Wave Aeotec Smart Switch 6 to be called AEO 007; an LED bulb disguised as a old fashioned filament bulb on the Zigbee Sylvania Smart Plug to be called SYLV 002; a Zigbee CREE dimmable bulb to be called CREE 006; a bulk Costco compact fluorescent from 2013 on a bulky and sideways Z-Wave GE Smart Switch to be called GE 001.

The Aoetec Z-Stick is a feature packed USB device that implements the Z-Wave+ protocol.  My first advice, though, is to not read the instructions.  You see, the Things Gateway support for Z-Wave is still in infancy and doesn't particularly fit well into the pairing methods traditionally used by Z-Wave devices.

The Z-Stick instructions will tell you to pair  Z-Wave devices in a manner that the Things Gateway does not yet understand.  I suggest that you hold off and pair Z-Wave devices only through the Things Gateway software.  This will save you a lot of pain.

I went back to my browser and entered "gateway.local" in the URL bar.  I had to login using the credentials that I provided during the previous setup.  That lead me to this screen:
I pressed the "+" button to start pairing the two new Z-Wave devices.  The GE device behaves differently than the Aeotec device.  Normally when pairing Z-Wave things, one must press a button on the device to be added to the system.  However the GE device comes from the factory ready to go without having this button pressed.  It shows up on the screen, but the Aeotec device does not.
To to keep track of the devices, I renamed this first Z-Wave device as "GE 001" and pressed the "Save" button.
Now I had to get the Aeotec device added.  I found out the hard way that the little spinner next to "Scanning for new devices..." must still be spinning. In an earlier trial for this demo, I had to press "Done" and then immediately press the "+" button to return to this screen.

The Aeotec Smart Plug uses a more traditional Z-Wave approach to pairing.  I pressed the circular indent on the corner of the plug itself.  Since I had a light plugged into the Smart Plug, it illuminated.  After a few moments, the Smart Plug appeared on the page.  If it doesn't appear for you, wait for the colored lights on the edge of the plug to calm down, and press the button again.

I renamed the plug to a more understandable name before pressing "Save" and "Done".
This gives me four devices connected to my Things Gateway: two that speak Zigbee and two that speak Z-Wave.  I played around with the controls, turning each on and off in turn.  I also made the discovery that support for the Sylvania Smart Plug was not as complete as I thought, as it was not registering anything but on or off.
Now the fun begins, I can cross the boundary between Z-Wave and Zigbee and make these devices work together using rules.

Setting up Rules

Let's make the compact fluorescent in the Z-Wave GE 001 plug follow whatever state the old fashioned bulb (actually it's LED) in the Zigbee SYLV 002 plug.

I clicked the Menu button and selected Rules
I dragged the SYLV 002 device up into the "device as input" section and then used the drop down box to select the "On" property.
Then I dragged the GE 001 device up to the "device as output" section and selected the "On" property.  Then went to the top of the box and named the rule:
Now I used the back arrow in the upper left to return all the way back to the Things screen.  I turned on the SYLV 002 light and immediately the GE 001 light came on, too.   Apparently, the rule system automatically implements the converse rule.  If SYLV 002 is turned off, then GE 001 is turned off too.
This rule, however, works only from the perspective of the SYLV 002 light. The GE 001 light can be operated independently. So the rule doesn't cover all the possibilities. Making another rule from the perspective of the GE 001 light as the leader creates a loop that can have some undesirable behavior. We can exploit this for some silly fun.  I made a set of four rules:
  • AEO 007 on  --->  SYLV 002 on
  • SYLV 002 on --->  CREE 006 on
  • CREE 006 on --->  GE 001 on
  • GE 001 on   --->  AEO 007 off
I was expecting sequencing behavior, but what I got was somewhat reminiscent of linear but with some chaos added for good measure.  It was hard to get it to stop.  I eventually unplugged the power to the Raspberry Pi.  On rebooting, I deleted the rules - I didn't think I had a practical application for such chaos.
What does this mean for rules?  Well it means that it is possible to create infinitely looping dependencies.  Think about how one would make two lights behave mutually exclusively: when one light is on, the other is off.  An initial rule would be like the first example above where one follows another.  The exception is that the target bulb is toggled to the opposite of the leader.  That works fine from the perspective of the leader.  However if the follower bulb is controlled independently, the leader's rule doesn't apply and both lights could be on at the same time.  It is temping to add another rule where follower becomes the leader and vice versa.  However, that sets up an infinite loop.  Try it and you'll see what I mean.

In my next blog posting, I'm going to add some color to this circus with some Phillips HUE lights.