Add Java 8, OpenHAB and Z-Wave on a Synology DiskStation OS 5.2 Virtual Machine

The following acticle describes the process of installing Java 8, OpenHAB2 and a Aeon Labs Z-Stick Gen5 on a Synology DiskStation OS 5.2 running as VirtualBox VM.

Using a Synology DiskStation to control a home automation environment is a good choice, since it usually runs 24 hours a day. However - as cautious as I am - I would first like to use a test environment to allow the experience gained there to be used into the later installation. In particular, problems can be identified in advance. This all results in a bunch of requirements.

The guys from XPEnology provide an .iso file as a loader for a patched Synology DSM v. 5.2 operation system which allows us to run a DS3615xs NAS in a virtual machine. (Requirements: A running Synology DiskStation OS 5.2)

A very interesting controller software for home automation is OpenHAB. The advantage of OpenHAB is, on the one hand, the possibility to run it on a DiskStation and on the other hand the large number of supported home automation protocols (bindings). It is written in Java and based on the OSGi framework (Equinox) (Requirements: Oracle Java 8, OpenHAB).

My choice for a wireless communications standard that unites the sensors and actuators in a common network fell due to the large number of available components on Z-Wave. As a controller, the Aeon Labs Z-Stick Gen5 USB stick will be used (Requirements: Install Aeon Labs Z-Stick).

Refer to the Links section to get pointers.

Prerequisites

  1. This article assumes a Synology DiskStation DSM version 5.2 running in a VirtualBox VM
  2. For the ip address of your disk station the value 192.168.100.100 is assumed. You should replace this value with the actual value of your installation.
  3. You are logged into the DiskStation and have access via SSH and the web interface

One way to meet the prerequisites is to follow the instructions in this article: Set up a Virtual Machine running Synology DiskStation OS 5.2

Install Oracle JAVA 8

  1. Refer to pcloadletter.co.uk for detailed instructions
  2. Storage Manager → Create a volume (if not already done)
  3. Create a shared folder named "public" and assign r/w permissions to user "admin"
  4. File Station → Upload ejdk-8uxyz-linux-i586.tar.gz and jce_policy-8.zip to folder "public"
  5. Package Center → Settings → Package sources → Add values pcloadletter/https://packages.pcloadletter.co.uk
  6. Package Center → Settings → General → Trust level → Any publisher (includes setting for manual install later on) → OK
  7. Package Center → Community → Refresh → Java SE Embedded 8 → Install
  8. Due to various hints throughout the web, "Unlimited Strength JCE Policy" should be chosen when requested to select "Java Cryptographic Strength Selection" policy → NextApplyOK

Install OpenHab

  1. Note the DSM version (5.2) to download the proper OpenHAB version
  2. Create shared folders
                                                cd /volume1/public
                                                mkdir -p OpenHAB2/configurations OpenHAB2/addons
                                                chmod -R 775 OpenHAB2
                                            
  3. Package Center → Manual Install → Choose File → Select the previously downloaded openHAB .spk file (at this time OpenHAB-2.0.0-beta3-DSM52-syno-noarch-0.001.spk)
  4. "Run after Installation" →
  5. Tweak permissions of OpenHAB2 folders:
                                                chown -R openhab2:users OpenHAB2
                                                cd /volume1/@appstore/
                                                chown -R openhab2:users OpenHAB2
                                                chown -h openhab2:users OpenHAB2/configurations OpenHAB2/addons
                                            
  6. Create groups dialout and uucp and add user openhab2:
                                                synogroup --add dialout openhab2
                                                synogroup --add uucp openhab2
                                            
  7. Restart the DiskStation (Two alternatives):
    • Type reboot at command line
    • Open the DSM-Web-Frontend http://192.168.100.100:5000 in a browser → Login → Upper right corner: User icon → Restart
  8. Open the OpenHAB dashboard: http://192.168.100.100:8080

Install AeonLabs Z-Stick Gen5

  1. If you haven’t already, plug your controller into your Host-PC
  2. To pass-through the Z-Stick to your virtual machine, go to the VM guest window menu → Devices → USB and click on "Sigma Designs, Inc." to share the device
  3. The Diskstation should integrate the Z-Stick as /dev/ttyACMx device (where x is a number, e.g. /dev/ttyACM0, /dev/ttyACM1, ...), hereinafter referred to as /dev/ttyACM0. You can check the attached device by entering ls -l /dev/ttyACM*
  4. Create UDEV rules and a start up script to set Z-Stick device permissions on each startup (you can find a readable version of the script at the end of this article). At command line enter (most probably you'll copy and paste):
                                                # UDEV rules directly echoed to the target file
                                                echo 'ACTION=="add", KERNEL=="ttyACM[0-9]*", MODE="0660", OWNER="openhab2", GROUP="dialout"' >> /lib/udev/rules.d/99-aeon-z-stick.rules
                                                chmod 755 /lib/udev/rules.d/99-aeon-z-stick.rules
                                                # Start up script directly echoed to the target file
                                                echo -e '#!/bin/sh\nstart_modules(){\n\techo ls -l /dev/tty* >> /volume1/public/zwavelog.txt\n\tchown -R root.uucp /run/lock\n\tchmod -R g+w /run/lock\n\tchown -R root.uucp /var/lock\n\tchmod -R g+w /var/lock\n}\nstop_modules(){\n\techo "do nothing"\n}\ncase "$1" in\n\tstart)\n\t\tstart_modules\n\t;;\n\tstop)\n\t\tstop_modules\n\t;;\n\t*)\n\t\techo "usage: $0 { start | stop }" >&2\n\texit 1\n\t;;\nesac\nexit 0' >> /usr/syno/etc.defaults/rc.d/S98openhabzwave.sh
                                                chmod 755 /usr/syno/etc.defaults/rc.d/S98openhabzwave.sh
                                                # Set owner of device once
                                                chown openhab2.dialout /dev/ttyACM0
                                                reboot
                                            
  5. Wait while the DiskStation reboots and login again via ssh

Install Z-Wave binding and controller in OpenHAB

  1. Open the OpenHAB dashboard: http://192.168.100.100:8080
  2. Open "Paper UI" → Extensions → Bindings → Z-Wave Binding → Install (Refresh the page after a while to see if it has installed successfully)
  3. Open "Paper UI" → Configuration → Things → Z-Wave-Binding → Manually Add Thing → Z-Wave Serial Controller
  4. In field "Serial Port" enter /dev/ttyACM0 → Disable "Soft Reset" → Controller is Master: Yes →

Start up script (readable)

#!/bin/sh
start_modules(){
	echo ls -l /dev/tty* >> /volume1/public/zwavelog.txt
	chown -R root.uucp /run/lock
	chmod -R g+w /run/lock
	chown -R root.uucp /var/lock
	chmod -R g+w /var/lock
}
stop_modules(){
	echo "do nothing"
}
case "$1" in
	start)
		start_modules
	;;
	stop)
		stop_modules
	;;
	*)
		echo "usage: $0 { start | stop }" >&2
	exit 1
	;;
esac
exit 0

Usefull commands and infos

  1. Path to OpenHAB2: /volume1/@appstore/OpenHAB2
  2. Take a look at the openhab.log file:
                                                # Inspect the last 25 entries added
                                                tail -n 25 /volume1/@appstore/OpenHAB2/userdata/logs/openhab.log
                                                # Clear log
                                                cp /dev/null /volume1/@appstore/OpenHAB2/userdata/logs/openhab.log
                                            
  3. DSM commands: synouser synogroup
  4. Built-in shell (ash) commands:
    alias break cd chdir continue eval exec exit export false getopts hash help let local printf pwd read readonly return set shift source test times trap true type ulimit umask unalias unset wait

Links:

  1. PcLoadLetter
    https://pcloadletter.co.uk/2011/08/23/java-package-for-synology/
  2. Oracle Java SE Embedded Downloads
    http://www.oracle.com/technetwork/java/embedded/embedded-se/downloads/index.html
  3. Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 8 Download
    http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
  4. OpenHAB - Installation Overview
    http://docs.openhab.org/installation/index.html
  5. OpenHAB v2.0.0-beta3 Synology DiskStation Package for DSM <= 5.2
    https://github.com/openhab/openhab-syno-spk/releases/tag/2.0.0-beta3
  6. OpenHAB - File Locations
    http://docs.openhab.org/installation/linux.html#file-locations
  7. [German] Grundlegende Befehle auf der Kommandozeile
    http://www.synology-wiki.de/index.php/Grundlegende_Befehle_auf_der_Kommandozeile
  8. Z-Stick Gen 5 user manual
    https://aeotec.freshdesk.com/support/solutions/articles/6000056439-z-stick-gen-5-user-manual-