En route to a smart home with the Z-Wave protocol
Turn On
![](/var/linux_magazin/storage/images/issues/2016/184/perl-z-wave/schilli_michael_5.png/665594-1-eng-US/Schilli_Michael_5.png_medium.png)
Whether you want to control your lights or water your house plants remotely, home automation is making inroads into nerd households. Z-Wave technology offers devices for reliable control – a quick Perl script gets you started.
Now that inexpensive mini Linux platforms like the Raspberry Pi are readily available, I can think of dozens of home automation projects I'd love to be working on in the near future. For example, how could I use my cellphone – while out and about – to check whether my surfing wetsuit drying device is still doing its job, and how could I switch it off when all the moisture is out? Is the front door really closed and locked?
I just love to whip up applications like this, and I have explored similar topics in the past. Regular readers may recall the – now somewhat dated – articles on an Internet-controlled power switch [1] and a weather-controlled plant watering system [2].
At the end of the day, the procedure for these and similar applications is always the same: A sensor measures a value, such as brightness or moisture, and reports the values to a controller, which then trips an actuator – say, a relay – which in turn switches on a lamp or a pump. At this point, you may be faced with the problem that the control unit is quite a distance away, and you need a wireless approach to transmitting the signal to the actuator. Or do you really want to have the controlling computer in your plant pot?
Standards Confusion
A number of more or less standardized technologies deal with this topic [3]. After years of disappointment with the X10 method, which is popular in the United States but uses an unreliable method of communicating over power cables, I recently discovered Z-Wave technology, which is widespread in both the U.S. and Europe. In addition to using a totally reliable wireless handshake protocol, it is also fairly inexpensive.
To get started, I purchased a Z-Wave-certified mini-controller by the name of Z-Stick [4] from Aeon Labs for $35 (Figure 1), along with a Smart Energy Switch [5] for switching electrical consumers for $24 (Figure 2).
![](/var/linux_magazin/storage/images/issues/2016/184/perl-z-wave/figure-2/665600-1-eng-US/Figure-2_large.png)
The Z-Stick is a USB dongle that plugs in to a PC USB port. The PC then receives data from sensors and forwards signals to actuators wirelessly via the stick.
Installing on Ubuntu
The USB dongle more or less installed itself on Ubuntu 14.04, which immediately detected the Z-Stick and created a new device entry in /dev/ttyUSB0
, as you can see from the syslog entry shown in Figure 3.
Because the entry belongs to root, as well as the dialout group, and the permissions are crw-rw----
, you should run any scripts wanting to access the device under an account belonging to the dialout group. If you are not worried about which user account switches the devices on and off, you can relax the access permissions by typing
sudo chmod a+rw /dev/ttyUSB0
instead.
Getting Started
For my first steps in the Z-Wave communication universe, I went for the zwave_s
Perl script, which a company called Bigsister.ch offers on its website [6]. After installing a CPAN module for communication on the USB port using cpanm Device::SerialPort
, the script worked perfectly. Figure 4 shows the zwave_s add
command initializing the USB dongle. It then outputs a message telling the user to push a button on the device it is about to control – this was the energy switch in my case.
![](/var/linux_magazin/storage/images/issues/2016/184/perl-z-wave/figure-4/665606-1-eng-US/Figure-4_large.png)
I complied, and zwave_s
assigned the energy switch the number 3, as you can see from the output. I then typed zwave_s switch 3 on
, and the USB controller sent a wireless signal to the switch. As if by magic, the controller switched on the electrical consumer plugged in next door. The stick's range is claimed to be 100 feet, but you'll get less if it needs to penetrate solid walls. I then typed zwave_s switch 3 off
to switch the consumers off again and the plugged-in desk lamp promptly turned off.
On GitHub, there is a Perl project named p5-ZWave-Controller
, although it is struggling and has not been maintained for years – "abandonware" sort of sums this up. Instead, I quickly put together a new CPAN module named ZWave::Protocol and uploaded it just before this issue went to press. Listing 1 shows a practical application of the module that switches the Aeon energy switch on and off [7].
Listing 1
zwave-test
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.