Skip to content

Instantly share code, notes, and snippets.

@SierraNL
Last active November 14, 2016 09:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SierraNL/c6cb175eb5cac717d785 to your computer and use it in GitHub Desktop.
Save SierraNL/c6cb175eb5cac717d785 to your computer and use it in GitHub Desktop.
Running OpenHAB on a NUC

##Introduction Basicly a step by step plan to install OpenHAB 1.7.1 on a Intel NUC using the following bindings. The content is mostly copy&paste from the OpenHAB wiki:

Operating System

I used to run OpenHAB 1.x on Windows, because of other services, but Ubuntu should work fine. I've picked the LTS version for stability.

Install Ubuntu LTS

Pick the following options:

  • OpenSSH server (To administrate the server using PuTTY)
  • Samba Fileserver (To get access to the OpenHAB config files from Windows)

If you want to use wifi

sudo nano /etc/network/interfaces

and write:

auto wlan0
iface wlan0 inet dhcp 
                wpa-ssid <ssid>
                wpa-psk  <password>

and reboot

reboot

Dependencies

###Java We need Java 8, which is not included in Ubuntu 14.04 LTS, so we add a repository and install it.

sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

###MySQL for persistence

sudo apt-get install mysql-server

Start the Mysql commandline as root

mysql -u root -p

Create a database for OpenHAB

CREATE DATABASE OpenHAB;

Create a user for OpenHAB

CREATE USER 'openhab'@'localhost' IDENTIFIED BY 'yourpassword';

Grant the user permissions for the database

GRANT ALL PRIVILEGES ON OpenHAB.* TO 'openhab'@'localhost';

Quit the Mysql command prompt

quit

###Mosquitto as MQTT broker

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto

####Setup TLS on Mosquitto (optional) copy the SSL CA to /etc/mosquitto/ca-certificates copy the SSL certificate and private key (.crt and .key) to /etc/mosquitto/certs

Protect your SSL certificate

cd /etc/mosquitto/certs
sudo chmod 600 *
sudo chown mosquitto *

Configure TLS

sudo nano /etc/mosquitto/conf.d/tls.conf

Add the following

listener 8883
tls_version tlsv1
cafile /etc/mosquitto/ca-certificate/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate false

Restart Mosquitto (check how, /etc/init.d/mosquitto restart doesn't work)

####Portforward Make sure you portforwarded the default mosquitto port 8883 (or 1883) to your server!

Install OpenHAB

###Configure the repository

wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo tee /etc/apt/sources.list.d/openhab.list
sudo apt-get update

###Install the runtime

sudo apt-get install openhab-runtime

Get needed addons

sudo apt-get install openhab-addon-binding-astro
sudo apt-get install openhab-addon-binding-dsmr
sudo apt-get install openhab-addon-binding-http
sudo apt-get install openhab-addon-binding-hue
sudo apt-get install openhab-addon-binding-mqtt
sudo apt-get install openhab-addon-binding-mqttitude
sudo apt-get install openhab-addon-binding-netatmo
sudo apt-get install openhab-addon-binding-networkhealth
sudo apt-get install openhab-addon-binding-plex
sudo apt-get install openhab-addon-binding-samsungtv
sudo apt-get install openhab-addon-binding-sonos
sudo apt-get install openhab-addon-binding-wol
sudo apt-get install openhab-addon-binding-xbmc
sudo apt-get install openhab-addon-binding-zwave
sudo apt-get install openhab-addon-io-myopenhab
sudo apt-get install openhab-addon-persistence-mysql

Get the correct configuration

cd /etc/openhab/configurations/
sudo cp openhab_default.cfg openhab.cfg

openhab.cfg

  • Set security option external, for my.openhab
  • Set default persistince to mysql
  • Set mysql server, username and password
  • Set MQTT Transport
  • Set HTTP Binding cache items for weather and the 2 solar inverters
  • Set Philips Hue ip and secret
  • Set Sonos UDN
  • Set Samsung TV host
  • Set Z-Wave port
  • Set netatmo clientid, clientsecret and refreshtoken
  • Set astro binding latitude and longitude !!
  • Set plex host
  • Set DSMR port and gas channel

Create items, sitemaps and rules

I copied my existing items, sitemaps and rules from https://github.com/SierraNL/openhab

###symlink com ports for Zwave and DSMR

sudo nano /etc/udev/rules.d/50-usb-serial.rules

And add for the Aeotec Z-Stick II

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{product}=="CP2102 USB to UART Bridge Controller", SYMLINK+="usb_zwave", GROUP="dialout", MODE="0666"

And for the DSMR cable

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{product}=="FT232R USB UART", SYMLINK+="usb_dsmr", GROUP="dialout", MODE="0666"

Add the symlinks to the Java args

sudo nano /etc/init.d/openhab

Look file the lines starting with -D and add one

-Dgnu.io.rxtx.SerialPorts=/dev/usb_dsmr:/dev/usb_zwave

###Get a certificate for Netatmo

wget https://www.startssl.com/certs/ca.pem
sudo keytool -import -keystore /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts -alias StartCom-Root-CA -file ca.pem

Type changeit if asked for a password Type y to trust the certificate

###Set autostart

sudo update-rc.d openhab defaults

##Share the configuration using Samba

sudo nano /etc/samba/smb.conf

Go to the bottom of the file and add

[OpenHAB]
comment = OpenHAB Configuration
path = /etc/openhab/configurations
browseable = yes
writeable = yes
guest ok = no
create mask = 0777
directory mask = 0777

Restart Samba

sudo /etc/init.d/samba restart

Change permissions on the OpenHAB config to 777

cd /etc/openhab
sudo chmod -R 777 configurations/

Now you can go to your NUC using \nameofyournuc\OpenHAB from your Windows machine (use your Ubuntu credentials) and edit the configuration files. Use Notepad++ since most files have Unix linefeeds

##Dashing dashboard

It runs on ruby and requires make, so we need to install that

sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo apt-get install build-essential
sudo apt-get install bundler
sudo gem install dashing

###Todo figure out how to call Openhab from dashing, using websockets.

##Want to haves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment