Compiling open-zwave for Home Assistant 0.45 on Docker

Home Assistant, Z-Wave, Docker

Home Assistant uses the open-zwave library to control Z-Wave home automation devices like light switches and door sensors. Unfortunately, this library's last release (1.5) was back in August 2016 and doesn't include configurations for many Z-Wave devices I use (like the Linear NGDZ00-4 Garage Door). I therefore needed to create a custom open-zwave fork, cherry-pick recent commits for the functionality I need, and have my fork compiled into a custom Home Assistant Docker image.

Doing this with Home Assistant 0.45 only required three quick tweaks:

Remove PyPI package

Home Assistant 0.45 now installs python_openzwave from PyPI, but we want to build it from source, so remove that from requirements_all.txt:

diff --git a/requirements_all.txt b/requirements_all.txt
index 6141e3d..2da4ce0 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -695,9 +695,6 @@ python-vlc==1.1.2
 # homeassistant.components.wink
 python-wink==1.2.4
 
-# homeassistant.components.zwave
-python_openzwave==0.4.0.31
-
 # homeassistant.components.device_tracker.trackr
 pytrackr==0.0.5
 

Add Build Script

Next, add a script to build open-zwave and the Python library:

diff --git a/virtualization/Docker/scripts/python_openzwave b/virtualization/Docker/scripts/python_openzwave
new file mode 100755
index 0000000..bd975fb
--- /dev/null
+++ b/virtualization/Docker/scripts/python_openzwave
@@ -0,0 +1,42 @@
+#!/bin/sh
+# Sets up and builds python open zwave to be used with Home Assistant.
+# Dependencies that need to be installed:
+# apt-get install cython3 libudev-dev python3-sphinx python3-setuptools
+
+# Stop on errors
+set -e
+
+cd "$(dirname "$0")/.."
+
+if [ -d build ]; then
+  rm -rf build
+fi
+
+mkdir -p build
+
+cd build
+
+git clone --branch v0.3.3 --recursive --depth 1 https://github.com/OpenZWave/python-openzwave.git
+cd python-openzwave
+
+git fetch origin
+git checkout v0.3.3
+
+git config --global remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
+git clone --recursive --depth 1 https://github.com/colinodell/open-zwave.git openzwave
+#git config --global --unset remote.origin.fetch
+
+cd openzwave
+git fetch origin
+git checkout V1.5-with-customizations
+git config --global --unset remote.origin.fetch
+cd ..
+
+pip3 install --upgrade cython==0.24.1
+PYTHON_EXEC=`which python3` make build
+PYTHON_EXEC=`which python3` make install
+mkdir -p /usr/local/share/python-openzwave
+cp -R openzwave/config /usr/local/share/python-openzwave/config
+
+rm -rf openzwave/.git
+

Run During Docker Build

Finally, add our custom build script to the docker build process:

diff --git a/virtualization/Docker/setup_docker_prereqs b/virtualization/Docker/setup_docker_prereqs
index a6bf716..0efb9bf 100755
--- a/virtualization/Docker/setup_docker_prereqs
+++ b/virtualization/Docker/setup_docker_prereqs
@@ -30,6 +30,7 @@ PACKAGES=(
 # Required debian packages for building dependencies
 PACKAGES_DEV=(
   cmake git
+  cython3
   # libcec
   swig
 )
@@ -50,6 +51,8 @@ if [ "$INSTALL_FFMPEG" == "yes" ]; then
   virtualization/Docker/scripts/ffmpeg
 fi
 
+virtualization/Docker/scripts/python_openzwave
+
 if [ "$INSTALL_LIBCEC" == "yes" ]; then
   virtualization/Docker/scripts/libcec
 fi

That's it!

(Gist mirror: https://gist.github.com/colinodell/8a72098921b484cedb3980228ab75419)

Enjoy this article?

About Colin O'Dell

Colin O'Dell

Colin O'Dell is a Senior Software Engineer at SeatGeek. In addition to being an active member of the PHP League and maintainer of the league/commonmark project, Colin is also a PHP docs contributor, conference speaker, and author of the PHP 7 Migration Guide.