121
make.co
will see each other and live happily ever after. My
lights acknowledge this by blinking twice. Newer
devices may require a PIN to connect, which
should be physically printed somewhere on the
device itself.
Two little gotchas: First, each time you do this,
only one device will be included. If you have a
single switch that controls multiple smart bulbs,
that’s a little messy. Step 1 will reset all the bulbs
at once, but you’ll have to repeat steps 2 and 3
multiple times until all bulbs in the group have
been included. Don’t worry, we’ll add some code
later so you can easily turn the whole group on
or off with one command. If you’re starting from
scratch, though, using a Z-Wave switch and
regular bulbs may be simpler.
Second, inclusion (and exclusion too) can be
quite sensitive to proximity; the gateway needs to
be pretty close to the device you want to include.
When I’m adding devices, I sometimes plug the
gateway into a portable power station (such as
Sean Nolan
E
F
G
Amazon #B07T8XSWFN) so I can easily carry it
around the house.
Talking to the Gateway
OK, first let me say that there is a lot going on in
the Z-Wave protocol, and about a million ways
to dig in with code, using everything from C++
to JavaScript. I’ve added some links to various
options at the end of the article, but because
my development scenario is quite constrained
— manage a bunch of dimmable lights — I’ve
chosen the Z-Way VDev (virtual device) API.
VDev simplifies things by providing a
normalized and simplified view of the device set;
and a consistent set of REST commands across
device types. These commands are exposed on
port 8083:
/devicesreturns a list of all devices on the
network, including a mapping of friendly names
to internal IDs used in control commands.
/devices/IDreturns the device status in a
consistent JSON format.
/devices/ID/updatetells the device to
report its current status back to the gateway.
/devices/ID/onturns the device on (for
some device types this may mean “do your thing”
e.g., as the command to press a toggle button).
/devices/ID/off — turns the device off.
/devices/ID/exact?level=#asks the device
to apply an integer value from a range, if the
device supports it. For example, this might be a
0–100 percentage value for a dimmer switch, or a
temperature for a thermostat.
With the RaZberry installed on our Pi, devices
added and an API selected, we are finally ready
to write some code. I’ve used Java, but of course
pretty much any environment can call those REST
interfaces. You can download and build my code
(github.com/seanno/shutdownhook/tree/main/
zwave) on your Pi or anywhere that has Maven,
Git, and Java installed:
sudo apt install git maven default-jdk
# if needed
git clone https://github.com/seanno/
shutdownhook.git
cd shutdownhook/toolbox
mvn clean package install
cd ../zwave
mvn clean package
M83_118-23_SB_Z-Wave_F1.indd 121M83_118-23_SB_Z-Wave_F1.indd 121 10/11/22 12:17 PM10/11/22 12:17 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.19.23