Install Home Assistant and Open Z-Wave on CentOS 7

I've had enough. I can't take it anymore. I just had to re-install Home Assistant on CentOS 7.

Okay, that's probably a little over dramatic. It bothered me that my PINE A64 wasn't a rack-mount piece of gear, so I grabbed a Dell R210 II 1U server to use as my new Home Assistant Host. Inside I packed it with a Xeon E3-1240v2 CPU, 32GB of UDIMM DDR3 RAM, a 128GB Crucial MX100 for a boot drive, and 2 525GB Crucial MX300 SSD's (in a ZFS mirror) for Linux Container (LXC) storage. This allows me to have more power for Home Assistant (although hass isn't really that power hungry), but ultimately better control in my network for my setup. My post for installing hass on DietPi is still valid, but likely won't be updated over time.

As a refresher...
Home Assistant is an open-source home automation platform based on Python 3. It interfaces with many different types of home automation modules and products, and is a comparable product to OpenHAB (for those that are familiar). It's a vendor-agnostic, self-hosted, DIY alternative to systems such as Vera, SmartThings, or Iris.

This guide is for installing Home Assistant to use with Z-Wave bindings, utilizing an Aeon Labs Z-Stick, Gen5 as my Z-Wave controller. I will be installing in a CentOS 7 LXC and will discuss USB passthrough of the Z-Stick in a separate post.

As with other guides, I am not including setup for SELinux so I assume you have that disabled. Likewise, I have not included firewalld rules since I manage that at my hypervisor (Proxmox) level, so please know that by disabling both SELinux and firewalld/iptables, you are doing so at your own risk.

Let's Get Started!

1.) updates and pre-requisites:
yum -y install https://centos7.iuscommunity.org/ius-release.rpm   # IUS Repo (for python3 packages)
yum -y install epel-release && yum -y update   # EPEL repo and updates
yum -y groupinstall "Development Tools"   # Dev tools
yum -y install git gnutls-devel htop libgcrypt-devel libyaml-devel python35u-devel python35u-pip systemd-devel wget   # other pre-reqs
2.) install home assistant:
pip3.5 install --upgrade pip   # Update PIP
pip3.5 install homeassistant python-openzwave   # Install Home Assistant and other additional requisites
mkdir /opt/homeassistant   # Home Assistant config directory
vi /etc/systemd/system/hass.service   # Create hass (Home Assistant) systemd file
---
[Unit]
Description=Home Assistant (hass) Daemon
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/usr/bin/hass -v --config /opt/homeassistant --pid-file /var/run/hass.pid --daemon
PIDFile=/var/run/hass.pid

[Install]
WantedBy=multi-user.target
---
chmod +x /etc/systemd/system/hass.service && systemctl daemon-reload   # Reload systemd files
systemctl start hass.service && sleep 15 && systemctl stop hass.service   # Generate configration files
3.) install openzwave control panel:
cd /opt && git clone https://github.com/OpenZWave/open-zwave.git   # Grab open-zwave
cd /opt/open-zwave   # Change dirs to open-zwave
PYTHON_EXEC=$(which python3.5) make build   # Compile open-zwave
PYTHON_EXEC=$(which python3.5) make install   # Install open-zwave

cd /opt && wget ftp://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.19.tar.gz   # Grab libmicrohttpd (dependency for OZWCP)
tar xf libmicrohttpd-0.9.19.tar.gz   # Extract libmicrohttpd
mv libmicrohttpd-0.9.19 libmicrohttpd && cd libmicrohttpd   # Rename package
wget -O config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'   # Grab updated config.sub file
wget -O config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'   # Grab updated config.guess file
./configure && make   # Complie libmicrohttpd
make install   # Install libmicrohttpd

cd /opt && git clone https://github.com/OpenZWave/open-zwave-control-panel.git   # Grab open zwave control panel (OZWCP)
cd /opt/open-zwave-control-panel && vi Makefile   # Edit Makefile
# Edit lines 24-25 to be
---
OPENZWAVE := /opt/open-zwave  
LIBMICROHTTPD := /usr/local/lib/libmicrohttpd.a
---

# Uncomment line 33, and edit to be
---
GNUTLS := -lgnutls -lgcrypt
---

# Uncomment lines 37-38, and Comment out lines 44-45
make   # Compile OZWCP
ln -s /usr/lib64/python3.5/site-packages/python_openzwave/ozw_config config   # Create symlink for openzwave configs
./ozwcp -p 8888   # Start ozwcp as a test (note, OZWCP and HASS should never both be running at the same time -- stop HASS before starting OZWCP, and kill OZWCP before starting HASS)
4.) configure home assistant:

Now you will need to create a symlink for the Zwave device/module you are using, so Home Assistant is more easily configurable. If you are using an Aeon Lab Z-Stick Gen5 like I am, you can run this one command:

echo 'SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="zwave"' > /etc/udev/rules.d/99-usb-serial.rules

Which will create a symlink from /dev/* device to /dev/zwave, so you don't have to worry about the device name changing (aka, persistant device). If you are using a Zwave device other than the Z-Stick Gen5, you will need to find the idVendor and idProduct of your device. Fortunately, ou should be able to find these attributes using dmesg after plugging the device in. Otherwise, I would recommend searching around Google.

Now that the device name has been statically set (well, once we reboot), let's configure HASS to be able to speak with the Zwave device.

HASS uses a configuration.yaml file for much of it's user-configurable settings. For our install, this file exists at /opt/homeassistant/configuration.yaml. This file requires restarting the HASS service to reload any changes.

vim /opt/homeassistant/configuration.yaml   # Open the file for editing
# Add this to the bottom of the file:
---
zwave:
  usb_path: /dev/zwave
  config_path: /usr/lib64/python3.5/site-packages/python_openzwave/ozw_config
---

This will tell HASS that the usb_path of our Zwave device, is our symlinked name of /dev/zwave. The config_path key points to the path containing several Zwave device configs, so HASS knows how it can interact with the device.

systemctl enable hass.service   # Enable HASS to run at system start
rm -rf /opt/libmicrohttpd*   # Cleanup unnecessary libmicrohttpd files
systemctl reboot   # Reboot server

Once system is back up, HASS should be running on port 8123. Visit http://IP:8123 to access web UI. Home Assistant is now installed and configured to work with your Zwave device, although no Zwave devices/modules have been added yet. To add a device, we will use the Open Zwave Control Panel (OZWCP) that we previously installed. To do this, first stop Home Assistant:

systemctl stop hass.service   # Stop the HASS service
cd /opt/open-zwave-control-panel && ./ozwcp -p 8888   # Start OZWCP

Browse to http://IP:8888 and you should now see the Open Zwave Control Panel.

Under Device name, input /dev/zwave and click Initialize.

OZWCP should now be connected to your Zwave controller (i.e., Aeon Labs Z-Stick Gen5). You should see it listed under the Devices list below. To put the controller into inclusion mode (this is how you add devices), select Add Device from the drop-down menu in the Controller section, and click Go. You are now ready to add Zwave devices/modules, by performing whatever action is needed to include the device/module (i.e., press a button, power on the device, etc -- This will vary for each different Zwave module). Once included, you should see your new device/module listed in the Devices section. Once you've added all your devices/modules, click the Save... button in the top right, under the Backup Controller setting. This will tell OZWCP to write the Zwave config to a file, which isn't always neccessary when adding devices, but it is neccessary when doing other tasks, so get in the habit of doing this every time you finish up in OZWCP. Click Close under the Controller section, and go back to your SSH session. Kill OZWCP (usually by hitting CTRL-X), and OZWCP is no longer running.

Inside /opt/open-zwave-control-panel you should see a new file, with a randomly generated name. Something like zwcfg_0xdaa2b3d3.xml. This is the file that was generated when you clicked Save... from OZWCP. One of the biggest reasons I personally care about this file is because I like to rename my Zwave devices to something more meaningful. I'm referring to the Entity ID within HASS, which can't be change within HASS. You can still assign a friendly_name in the configuration.yaml, but that only affects the frontend view.

The easiest way for HASS to know about this zwcfg_0xdaa2b3de.xml file is to create a symlink. You should be able to do this by running:

ln -s /opt/open-zwave-control-panel/zwcfg_*.xml /opt/homeassistant/.

Which will create the symlink regardless of what random values are in the name (zwcfg_ is also the start of the file, the bit after is a HEX code which I'm guessing is specific to each different Zwave controller module).

Lastly, let's startup HASS and we should see our Zwave device(s)!

systemctl start hass.service   # Start HASS service

That's a wrap for this guide. Leave any eedback below.


Related Posts


Share on: Twitter | Facebook | Google+ | Email


comments powered by Disqus