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

The following acticle describes the process of installing Java 8, OpenHAB2, Aeon Labs Z-Stick Gen5 and a Fibaro Door/Window sensor on a Synology DiskStation OS 6.1 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.

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: Install 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. A Fibaro Door/Window sensor will be integrated to complete a small home automation scenario (Requirements: Install Aeon Labs Z-Stick and Fibaro Door/Window sensor).

Refer to the Links section to get pointers.

Prerequisites

  1. This article assumes a Synology DiskStation DSM version 6.1 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 installation procedure described in this article: Set up a Virtual Machine running Synology DiskStation OS 6.x

From the DSM-Help: SSH/Telnet only supports logging into the system with accounts belonging to the administrators group. To switch to a root account, please log into the system with SSH/Telnet as a user belonging to the administrators group, run the command sudo -i, and then enter the password of the account used to log in..

Besides any other workarounds spread on the internet you can do the following to log into disk station via SSH:

                                        # Suppose the ip address of your disk station is 192.168.100.100
                                        ssh admin@192.168.100.100
                                        admin@192.168.100.100's password: ...
                                        admin@192.168.100.100:/$ sudo -i
                                        Password: ...      # Usually the same as the admin's password
                                        root@192.168.100.100:~#
                            

Now you're prepared to proceed!

Create a RAID Group and a Volume

  1. Storage Manager → RAID Group → Create
  2. Select "RAID Group for single volume or iSCSI LUN (Block Level)" → Next
  3. RAID Type: Basic → Next
  4. Drag your 2nd HDD (>=8GB) to the RAID Group → NextOK
  5. Perform disk check: Yes/No → NextApplyOK
  6. Storage Manager → Volume → Create
  7. File system: ext4 → OK

Install Oracle JAVA 8

  1. Refer to pcloadletter.co.uk for detailed instructions
  2. Create a shared folder named "public" and assign r/w permissions to user group "users"
  3. File Station → Upload ejdk-8uxyz-linux-i586.tar.gz and jce_policy-8.zip to folder "public"
  4. Package Center → Settings → Package sources → Add values pcloadletter/http://packages.pcloadletter.co.uk
  5. Package Center → Settings → General → Trust level → Any publisher (includes setting for manual install later on) → OK
  6. Package Center → Community → Refresh → Java SE Embedded 8 → Install
  7. 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 (6.1) to download the proper OpenHAB version
  2. Create shared folders
                                                cd /volume1/public
                                                mkdir -p openHAB2/conf openHAB2/addons
                                                chmod -R 775 openHAB2
                                            
  3. Package Center → Manual Install → Choose File → Select the previously downloaded openHAB .spk file (at the time of this writing: OpenHAB-2.1.0.004-SNAPSHOT-DSM6-syno-noarch-0.001) → "Run after Installation" →

    If you like to take a closer look of what happens while installation of OpenHAB2, download openhab-syno-spk-2.0.0.001-DSM6.zip, extract the files and inspect file /script/installer.sh. The next steps depend on what is already set and done after OpenHab is installed. At the time of this writing the following steps had to be executed to get a configured system. This might change in the future.

  4. Although the installation announces to use the folder /volume1/public/openHab2/conf to store configuration files if it exists, this folder is empty after the installation. In order to take advantage of having configuration files in the public folder, we mount the folders manually:
  5.                                             cd /volume1/public/openHAB2
                                                mount -B /volume1/@appstore/openHAB2/addons ./addons
                                                mount -B /volume1/@appstore/openHAB2/conf ./conf
                                            
  6. Go to the Web Interface → Control Panel → Group and check if groups dialout and uucp exist. If not, go to the command line and enter:
                                                synogroup --add dialout openhab2
                                                synogroup --add uucp openhab2
                                            
  7. Open the OpenHAB dashboard: http://192.168.100.100:8080 → You should see the "Welcome to openHAB 2 - Initial Setup" page
  8. Go ahead and configure basic settings in OpenHAB (e.g. choosing "Recommended Setup" and "Paper UI " is a good start)

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[AU]* >> /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/local/etc/rc.d/S98openhabzwave.sh
                                                chmod 755 /usr/local/etc/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" → Add-ons → Bindings → Z-Wave Binding → Install
  3. Open "Paper UI" → Configuration → Things → Add Things → Z-Wave-Binding → Z-Wave Serial Controller
  4. In field "Serial Port" enter /dev/ttyACM0

Install Fibaro FGK101 Door Opening Sensor

  1. Prepare sensor as decribed in the manual
  2. Open "Paper UI" → Things → Z-Wave Node 2: FGK101 Door Opening Sensor →
  3. Location → Enter some informational text
  4. Set value of "3: Visual LED indications" to 0 to save battery →
  5. Open "Paper UI" → Things → Z-Wave Node 2: FGK101 Door Opening Sensor (Click on the title)
  6. Activate channel "Door Sensor" by clicking on the blue radio box on the left
  7. Create a new item: Enter some text at "Label" and/or "Category"
  8. Open "Paper UI" → Control → Check sensor status by opening and closing the sensor → the corresponding status ("Open"/"Closed") should be displayed

Start up script (readable)

#!/bin/sh
start_modules(){
	echo ls -l /dev/tty[AU]* >> /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

Enter Karaf command line from remote

  1. Edit file vi /volume1/@appstore/openHAB2/userdata/etc/org.apache.karaf.shell.cfg
  2. Change entry sshHost=127.0.0.1 to sshHost=0.0.0.0.

    Please be aware, that the console will now be accessible from all devices in your subnet and is only secured by the password defined in users.properties (same path). You should thereby change the password.

    From OpenHAB - The Console
  3. Try to login at command line as follows
                                            ssh openhab@192.168.100.100 -p 8101
                                            Password authentication
                                            Password: habopen
                                        
  4. Checkout some commands:
                                            openhab> bundle:list | grep Binding     # List bindings
                                            101 | Active   |  80 | 0.9.0.201703201701    | Eclipse SmartHome AutoUpdate Binding
                                            102 | Active   |  80 | 0.9.0.201703201701    | Eclipse SmartHome Core Binding XML
                                            183 | Active   |  80 | 2.1.0.201703212140    | ZWave Binding
                                            openhab> smarthome:status zwave_device_114187e7_node2_sensor_door # item name
                                            CLOSED
                                            openhab> smarthome:status zwave_device_114187e7_node2_sensor_door # opening the door should give
                                            OPEN
                                            openhab> smarthome:status zwave_device_114187e7_node2_battery_level
                                            94
                                            openhab> logout
                                        

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. Path to Z-Wave node config xml files : /volume1/@appstore/openHAB2/userdata/zwave
  4. DSM commands: synouser synogroup

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 latest release
    https://github.com/openhab/openhab-syno-spk/releases/latest
  5. Using Karaf console from remote host
    https://github.com/openhab/openhab-docs/pull/38/files
  6. OpenHAB - The Console
    http://docs.openhab.org/administration/console.html
  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-