OpenHAB Installation

From Scottworld
Jump to navigation Jump to search

OpenHAB Installation on Raspberry PI 4

This is a guide to install OpenHAB 4 (Using repositories) on a Raspberry PI 4. This seems to work better than using the Habian image at the moment, (this may change in further releases)

Installation on Raspbian Lite

Download latest image of Rasbian Lite,

https://www.raspberrypi.org/downloads/raspbian/

Burn image to SD card using "balenaEthcher"
To enable the SSH server on boot, find the letter that is the SD boot drive, (may need to re-insert card for windows to detect it) In the root of this create an empty text file called "ssh" with no extension

- Eject and boot card in the Pi. ( it may take a few mins to configure and boot)

If you have trouble you can use NOOBS and select the Rasbian (Lite) option.

Test ssh and change password

Run a ssh session (via putty) and change the hostname / password

(you can do this via standard UNIX commands) but and easier way is..

sudo raspi-config

Select options and change password / hostname and check "locale / keyboard settings"

reboot

Update and apply upgrades

apt update
apt dist-upgrade
apt autoremove

Reboot when done.


Pre-Requisites

Install Zulu embedded JAVA.

Details can be found here..

https://docs.azul.com/zulu/zuludocs/ZuluUserGuide/PrepareZuluPlatform/AttachAPTRepositoryUbuntuOrDebianSys.htm 

Its a simple install, we need to add the key / repository and install java from the repo.

Import Azul's public key.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9

Add the repository to your sources.list

sudo echo 'deb http://repos.azulsystems.com/debian stable main' > /etc/apt/sources.list.d/zulu.list

Refresh the sources.

apt update
apt install 

Install Zulu JAVA 8

apt install zulu-embedded-8

Check the install with

java -version

Install arping (for use with the Network Binding in OpenHab)

apt install arping

And set it so that non-root can run it. (if it is not already done so)

chmod u+s /usr/sbin/arping

NB: (This is potentially still broken for "discovery" .. ) but as it may get fixed in OpenHAB 2.5 we might as well get it ready.

Install UNZIP (needed for backups)

apt install zip

OpenHAB 2.5 install

Install the OpenHAB repo keys

wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
sudo apt-get install apt-transport-https

Add the stable release stream to your sources.list

echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list

Refresh the repo and then run the install.

apt update
apt install openhab2

Now we need to configure OpenHAB to start on a restart.

sudo systemctl daemon-reload
sudo systemctl enable openhab2.service
sudo systemctl start openhab2.service

I would do a reboot at this point and make sure it comes up. Note you will need to WAIT 5 mins for the 1st start for OpenHAB to setup and initialise itself. Once this is completed you can try connecting to.

http://ceres.scottworld.net:8080

Add the OpenHAB user to the DIALOUT group (so it can use the USB ports) If it has not done so during the installation.

adduser openhab dialout

RFXCOM Unit Config'

If you have multiple USB devices these may come up on different port after a reboot. We can help with this, by forcing it to bind to a set port. Add the RFXCOM unit so it gets the same USB name assignment (this will stop it all breaking if you add more USB devices later)

Plug in the RFXCOM unit to your USB of choice. Find out its serial number..

dmesg | grep -i usb

Find the RFXCOM unit and get its Vendor ID / Product ID and Serial Number

[ 1080.901450] usb 1-1.4: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[ 1080.901467] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1080.901480] usb 1-1.4: Product: RFXtrx433
[ 1080.901492] usb 1-1.4: Manufacturer: RFXCOM
[ 1080.901504] usb 1-1.4: SerialNumber: A1XPT0UR

Now create a UDEV rules file

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

In here put

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A1XPT0UR", SYMLINK+="ttyUSB-RFX433"

This will assign a USB id of /dev/ttyUSB-RFX433

Reboot and check it with

ls /dev/ttyUSB*

You should have the unit now listed ...under this reference.

OpenHAB Configuration

Return to the OpenHAB web interface

http://ceres.scottworld.net:8080/

Select the Standard (Recommended Setup) - Wait a few mins.

Now select the "PAPER UI" for further config.

System Settings

Under Configuration / System .. set the Regional Settings

Time/zone locations
Network settings (select the IP address to bind openHab)
Set the regional settings and your location. (handy for sunrise / sunset etc.)

Add the RFXCOM Binding

Next we will add the basics to get the RFX unit working. We have to add the RFXCOM unit manually.

Addons / Bindings / RDXCOM Binding - (add this binding.)

Next we need to add the RFXCOM unit as a THING manually.

Inbox, Search for Things,RFXCOM binding, (click Add thing Manually) and select the RFXCOM USB Transceiver. 

Set the following..

Serial Port should be set to what ever the USB was set earlier (/dev/ttyUSB-RFX433) or /dev/ttyUSB0
Turn OFF Skip transceiver config
Turn Transmit power to 0 (or higher if required)
Enable protocols you want to listen.  (AD Lightwave, Oregon Scientific, X10 Messages)

The RFXCOM "Thing" should now be showing "ONLINE"

Bindings

Now lets add some functionality, and add some more bindings. Under Configuration/Add-ons/Bindings and install the following.

Astro Binding (for sunrise / sunset times)
LG webOS Binding (for my TV)
Mail Binding (as we want to send some email alerts)
Network Binding (Allows us to right rules about devices, that appear / disappear on our network)
RFXCOM Binding (we should already have this working)
Wake-onLAN (WOL) Binding.  (So we can send WOL to the LG TV)
WiFi LED Binding, (for the lights)

Backups

There is a backup script in

sudo openhab-cli backup

Which places a file in /var/lib/openhab2/backups, which can then be restored using:

sudo openhab-cli restore /var/lib/openhab2/backups/filename.zip

You can add a cron job that does this every week

crontab -e
0 0 * * 6 openhab-cli backup
Usage:  openhab-cli command [options]

Possible commands:
  start [--debug]     -- Starts openHAB in the terminal.
  stop                -- Stops any running instance of openHAB.
  status              -- Checks to see if openHAB is running.
  console             -- Opens the openHAB console.
  backup [filename]   -- Stores the current configuration of openHAB.
  restore filename    -- Restores the openHAB configuration from a backup.
  showlogs            -- Displays the log messages of openHAB.
  info                -- Displays distribution information.





Become root

sudo -s

Generate a key

 ssh-keygen

Accept the defaults with NO passphrase. Key should be saved in..

/root/.ssh/

Copy the key to solaris via a login.

ssh-copy-id sysadmin@solaris.scottworld.net

Test it .. with a login (you should get not password prompt)