The Basic First post

Hacking With My Z-Way

The Gist

This is my first post on a new blogging engine Hexo.

I’ve been automating things at home and adding some Z-Wave switches and a Raspberry Pi 3 with a ZWay hat and some GE Z-Wave Switches. The switches are frustratingly expensive, but watching for sales helps, and spreading the conversion over time keeps it reasonable assuming you’re handy enough to do it yourself. If you need an electrician to do it, it’s be best to have all the hardware on hand so its a single pass. And, of course, its hard to buy the switches anywhere near locally; I used Amazon.

One of the more fustrating issues is the needlessly complex interfaces available to hook all the disparate bits together. There is a growing number of disconnected tools and languages used. Lots of Bash scripts, Python, and a growing field of JavaScript applications and tools. Many of the tool sets tend to be cloud based which, I think, is one of the worst options; your data goes to someone else’s stack and those stacks are closed so you can’t use your own data to cross a boundary. If they don’t offer functionality, you’re locked out even if someone else does. Then you get the limited “standards” like Lutron; almost z-wave, but its not compatible with anything else, really.

Another problem is there are a limited set of hardware that seems to survive. I’ve tried several Automation hubs that promised a lot, but they’ve all disappointed. One of the big limitations is everyone thinks your phone is an ideal interface … but they’re all using a different app so you end up with you spend too much time unlocking the phone, find apps, getting the settings done, and changing apps and doing more settings … you can’t do much without a phone in your hand. And they still “own” your data and if the cloud server goes away … you’re hardware is pretty useless. Google’s Nest bought and killed the Resolv smart hub and didn’t even offer a discounted upgrade path. Normally, this kind of transaction is “buying the customer list” more than anything else; but pissing those customers off seems counter-productive.

This is where the Raspberry Pi and Z-Way come in. The pair is quite compatible, relatively inexpensive, almost completely open source, and simple to set up. The Z-Way software is a breeze to install and update, and there are decent Android and IOS apps. There is a cloud in the ZWay stack, but it just acts as a broker for remote access rather than holding your family jewels in its cold little hands… and they give you a fair bit of freedom to use your data in your way.

An up-and-coming competitor is the Matrix-Creator which will eventually support ZWave, ZigbBee, and a bunch of sensors – the software layer is still in development, so neither Z-Wave or Zigbee currently work.

It took a fair bit of reading and too much trial and poking about to find something very simple: turning a particular light on and off.

For a dimmer light #13:

http://raspberry:8083/ZWaveAPI/Run/devices[13].instances[0].Basic.Set\(99\)

http://raspberry:8083/ZWaveAPI/Run/devices[13].instances[0].Basic.Set\(0\)

Of course, this means you can set any level in between, too. That works well for MultiLevelswitvh (dimmers). For BinarySwitchs, the same URL (other than device number) works if you change the “on” value from 99 to simply 1.

Why?

Knowing the simple URL gives you access to a RESTful API, and that helps simplify all your connections between pieces. Being able to simply say, “this URL turns it on” took me too many days to find, but it makes hooking things together far easier.

What doesn’t work? I tried attacking URLs like:
http://raspberry:8083/ZWaveAPI/Run/devices[13].instances[0].MultiLeveSwitch.data.level.Set\(0\)

The way to set the value seems to be only available through the Basic URL. Something I never found clearly stated.

For example, I’ve used cron and wget to turn my lights on in the morning. You need to provide the username and password with the URL.
wget --auth-no-challenge --user ${ZWAY_USER} --password ${ZWAY_PASSWD} -P ~/tmp/ ${URL_SET}

This was my first use to fill in for a problem I’ve seen using the ZWay software: when you turn a Scene on, it is constantly being sent/reset. For example, I had a scene for “All off” that I started at 10am on weekdays since everyone was away for the day. Then, on a government holiday, I got yelled at because ZWay repeatedly turned off the bathroom light - I had assumed when the conditions were met, the scene was set until it was asked for again. In reality, it was while the condition is met, the scene is sent repeatedly.

My eventual goals are a bit broader. In addition to my ZWay Raspberry Pi, I also have another one running HomeAssistant which has some interesting capabilities. Having access by RESTful access is allowing me to play with bridging from HomeAssistant to ZWay.

Another of my servers hosts a RabbitMQ broker which supports both MQTT and AMQP message queues. MQTT is an older Telemetry protocol, that is, a light weight method to send a message from a (usually small) device to the broker where other processors can subscribe and react to the messages. MQTT devices can publish to the server and/or subscribe to messages from the server; so a thermostat can publish its own temperature and subscribe to changes in the desired setpoint for the area. MQTT’s big advantage are speed (simpler that HTTP) and low bandwidth use when compare to something like HTTP and REST. MQTT is an older protocol and, in some people’s opinion, too limited. That has opened a number of more advanced and modern like AMPQ which address limitations without adversely impacting bandwidth.

In the end, I want to build my own hub system that doesn’t need an phone app to run. It should be able to figure out when I want lights on, and turn them on like I like them. Or knows when I leave, and turns things off. I’ve been digging deeper into Artificial Intelligence (AI), Neural Networks (NN) and the various Recurrent Neural Networks (RNN) and Hidden Markov Chains/Layers (HMM). None seem to be applicable to the problem. There is a lot about learning algorithms that can review time sequences of data and pick out the outliers (ie. Credit Card fraud detection), but not much on learning how to determine when something should be done next.

Some things I want to have:

  • when a motion sensor fires, turn on the right lights until after motion stops. Ideally, this could be include when the bedroom senses motion, light up the bathroom and start the coffee maker.
  • in the morning, when lights come on they should be full on and white.
  • in the early evening, lights should be bright and white until after 8pm or so.
  • in the later evening, light should be dimmed and colored until bed time.
  • Once the sun is up beyond a certain point, most lights in the house should be shut off.
  • once we leave for the day, the lights should go off.
  • When the oven is on, alert me if no one has been in the kitchen for 15-minutes.
  • I should never need to change a clock when the time changes ;-), afterall, all my other computers can change themselves. [Dream big!].