76 KiB
layout |
---|
tutorial-beginner |
{% include base.html %}
openHAB2 Raspberry beginner’s walkthrough – Using Raspberry Pi 3 and openHAB2 to create a home automation controller for Z-Wave, WiFi LED, 433MHz plugs, Yahoo Weather and meteoblue.com weather widget
Chapter 1: Before you start
Is openHAB2 the right choice for my home automation project?
Be aware that openHAB2 is an OPEN home automation solution which is strongly living from a very supportive community. If you want to have a plug and play solution with supplier guaranteed service level and a high likeliness that all the features are working and all the hardware is compatible, you might be better off in getting a ready to use home automation kit including the designated controller (like e.g. devolo or homematic IP). Consider this especially if you are planning to do safety related automation or emergency detection like fire alarm. If you, on the other hand, are willing to spend a few hrs/days in learning how to do a little installation and coding yourself and have no problems with the service level of a Raspberry Pi 3 (it is not as failsafe as other controllers) you might find a perfect environment with openHAB2 for your low cost, very flexible and continuously improving home automation environment.
Introduction:
This tutorial is targeting beginners like me to get a step by step guideline to get all the things installed. Since I am no coding expert and have no experience in Raspberry and Raspbian I am trying to go through the things step by step, so you should be able to get everything done, even without exactly having to go into all the details. That is one of the reasons I am also using the graphical GUI PIXEL for Raspbian since I think it makes it easier for the beginners to get started (and you might want to use PIXEL anyway when you are using the Raspberry 7” display as interface for your home automation controller) This tutorial is also based on having a Windows PC to support the setup process. You might be able to completely do it without the support of an extra PC, if you can get a MicroSD card with a pre-installed Raspbian OS and use the display options (the Raspberry 7” display or HDMI Display) for the Raspberry.
DISCLAIMER: This tutorial might contain some typos, errors or ways of setting up, which can be done in a better way. I am just reflecting my process of starting from scratch and slowly working my way through hundreds of online tutorials, manuals, forum threads etc. and on the way, highlighting the issues I had in getting things working. There will be no guarantee that the given instructions are working for your project as well.
Anyway I hope this tutorial will help some beginners to enjoy home automation with openHAB2.
A few words about the 2 in openHAB2:
The 2 in openHAB2 is important! The tutorial is based on the openHAB2 and will not go into all the details of the old version. You just have to be aware, that a lot of online documentation is still for the openHAB version and will not be applicable for openHAB2! So the best thing is always to go to the official webpage of openHAB2 and start from there, and only if you really can’t find the information or the link there, go to google and search for other solutions. I was always using the search setting (last year) so it was more likely to the results considering openHAB2 and not openHAB.
Chapter 2: Preparation
Shopping list: As mentioned before, I am basing this tutorial on the graphical GUI of Raspbian named PIXEL so the shopping list is also containing parts for this optional setup:
Hardware list:
Minimal hardware setup of the controller with external display:
Additional hardware for optional setup of the controller with 7” Raspberry display:
(I found it very useful to have one permanent GUI interface mounted on your controller, you can also use this touchscreen interface directly to interact with your home automation):
Z-Wave Controller hardware
If you want to use the Z-Wave technology for your home automation project you have to have one Z-Wave controller connected to your Raspberry NOTE: Be aware that the details serial numbers or item names may vary since you have to always make sure to use the hardware which is allowed in your country!
Z-Wave sensors, switches and actuators
NOTE: Be aware that the details serial numbers or item names may vary since you have to always make sure to use the hardware which is allowed in your country! Since I am doing a German based home automation project you may find that some Z-Wave devices are not sold in your required country configuration ( e.g. Z-Wave NodOn Smart Plug not available e.g. in the US)
NOTE: If you want to by other Z-Wave devices always make your they are listed in the Z-Wave device list of the openHAB2 Z-Wave binding to make sure they are supported correctly in the context of openHAB2:
http://www.cd-jackson.com/index.php/zwave/zwave-device-database/zwave-device-list
LAN devices (cable or WiFi)
A lot of things you are using at home are already connected to your LAN and can be integrated into your openHAB2 home automation project if the right binding is available for that device. You can find an overview on
http://docs.openhab.org/addons/bindings.html
NOTE: Be aware that not all the bindings to include devices are already included in the stable version of openHAB2 and may require a manual installation of a so called snapshot version of the binding (how to install snapshot bindings is explained later in this tutorial since we will need it for the WiFi LED controller)
433MHz devices
NOTE: Be aware that the details serial numbers or item names may vary since you have to always make sure to use the hardware which is allowed in your country!
Software list:
NOTE: This list is just an overview. The details in how to download and install the software are included later in the document so don't start downloading now.
Windows Download list:
My tutorial is using a MS-Windows windows machine for the PC part (You should be able to get it done with Mac or Linux PCs as well, but you have to go online to look up the differences and do some adaptions on the tutorial e.g. mounting the Raspberry file system to PC)
Description | URL |
---|---|
The latest Raspbian (Raspberry OS) image. You have to download the “Raspbian Jessie with PIXEL - Image with PIXEL desktop based on Debian Jessie” since this tutorial is using PIXEL | https://www.Raspberrypi.org/downloads/Raspbian/ |
Etcher (to write the Raspbian image to the SD-Card) | https://etcher.io/ |
Eclipse Smart HomeDesigner (optional but strongly recommended for easy editing of OpenHAB2 configuration files; incl. syntax highlighting). You have to choose the right version for your PC | https://www.openhab.org/downloads.html |
To use Eclipse Smart HomeDesigner you need Java Runtime Environment JRE (if not already installed on your PC) | https://java.com/ |
PuTTY or KiTTY portable to access the Raspberry console from your PC | http://www.putty.org/ or https://portableapps.com/apps/internet/kitty-portable |
WinSCP portable to access Raspberry file System directly from your PC (might become obsolete if you use a SAMBA server on your Raspberry, see tutorial) | https://winscp.net/eng/download.php |
Raspberry downloads:
How to download software will be explained in the tutorial, but as a reference you will use:
- openHAB2 Package repository based installation or manual installation (be aware that the file locations on the Raspberry will be different based on which kind of installation you choose)
- Samba server (for access of Raspberry files from Windows machine; needed for Eclipse Smart HomeDesigner)
- git-core to get code from the git repository (needed for the 433MHz controller)
- wiringPi to send commands using via GPIO (needed for the 433MHz controller)
- 433Utils to communicate with the 433MHZ controller (needed for the 433MHz controller)
- xscreensaver (optional if you are using the display setup, to easy control screen blackening or screen savers)
Chapter 3: Raspberry hardware and Raspbian OS installation
General information about Raspberry interfaces and GPIO pins:
Raspberry input Overview:
Raspberry GPIO pin Overview:
Preparing MicroSD card - writing Raspbian image to MicroSD card (PC required):
Connecting the hardware to the Raspberry
Basic hardware setup:
433MHz devices preparation and setup:
Description | Image |
---|---|
Solder the 433MHz antennas to the circuit boards of the transmitter and receiver | |
Connect the transmitter and receiver according to the wiring table below |
433MHz Transmitter
Transmitter Pin | Raspberry pin number | Raspberry pin name |
---|---|---|
GND | 9 | GND |
VCC | 4 | 5V PWR |
DATA | 11 | GPIO 17 |
433MHz Receiver (permanently)
NOTE: If you are running the 7” Raspberry display setup, you will not be able to connect the receiver permanently since the display is using the same power supply pins. You will have to build (solder) yourself a Y-patch cable to fit into the display cover (A breadbord might not fit into the case). But be aware that a temporarily installation of the receiver will work as well for this setup. See section 433MHz Receiver (temporarily).
Receiver Pin | Raspberry pin number | Raspberry pin name |
---|---|---|
GND | 6 | GND |
VCC | 2 | 5V PWR |
DATA | 13 | GPIO 27 |
433MHz Receiver (temporarily)
NOTE: Sice we do need the receiver only in the setup process for reading the code of unknown 433MHz remote controls you might not need the receiver installed permanently.
If you have to read codes from a unknown 433MHz remote control you can temporarily use the power sockets of the transmitter. How to read the codes will be explained later in the section Adding 433MHz things.
Receiver Pin | Raspberry pin number | Raspberry pin name |
---|---|---|
GND | 9 | GND |
VCC | 4 | 5V PWR |
DATA | 13 | GPIO 27 |
After reading the codes you can remove the receiver completely from your raspberry and reconnect the transmitter to the power supply pins.
Optional: Installation of 7” Raspberry display and display case:
The full tutorial will be found on:
https://www.element14.com/community/docs/DOC-78156/l/Raspberry-pi-7-touchscreen-display
and a clip on YouTube:
https://www.youtube.com/watch?v=tK-w-wDvRTg
Remark: I had an issue with plugging in the power supply to the micro USB power input on the circuit board of the display (like shown in the video). The Raspberry was still showing me the low power symbol (lightening symbol on the upper right corner) SOLUTION: I had to plug in the power supply to the micro USB power input on the Raspberry itself. The display is now powered via the jumper cables. The standard display case is also allowing for both micro USB power inputs to be used.
NOTE: If the image on the display is having the wrong orientation, you can rotate the image by changing the configuration of Raspbian (see tutorial section Initial configuration of Raspbian > Change display orientation)
Display installation pictures:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8: Assembly of the standard display. (Make sure you have inserted the MicroSD card since you won’t have access to the slot as soon as you mounted the case!)Just pull the back plate off the case, insert the display including the mounted Raspberry (make sure that the path cables and the display cables are not crushed between case and board), tighten it with the 4 screws and put the back plate into place. Here is a good clip on YouTube: https://www.youtube.com/watch?v=wpSxibZOmoo
Chapter 4: Raspbian basic configuration
Starting up Raspberry or the first time – Raspbian PIXEL desktop
Since this tutorial is focussing on using the PIXEL GUI here are a few basic tips.
Raspberry start-up screen:
PIXEL basic desktop (including the programs used in this tutorial) not unlike other PC OS desktops:
NOTE: If you are working with the 7” Raspberry display setup you might need to flip/rotate the display orientation. Just check the section” Optional: Change display orientation” later in this chapter
Working with the Terminal:
NOTE: As soon as you have connected the Raspberry to the network you might find it easier to open the Terminal remotely using PuTTY. This also allows you to directly paste command lines from this tutorial into the Terminal. (Right click in PuTTY terminal is pasting the content of the clipboard into the terminal)
Basic terminal commands and functions:
The full list can be found on:
https://www.Raspberrypi.org/documentation/linux/usage/commands.md
Command | Description |
---|---|
help |
Is showing you basic commands |
sudo *othercommand* |
is allowing you to run other commands as super user aka root user |
ls -la |
Shows the files in a directory incl. additional information |
cd |
Is changing the shell working directory. It can be used with attributes |
cd |
No attribute => working directory is changed to user root directory. |
cd .. |
Working directory is changed to directory one level above |
cd *directory* |
Working directory is changed to the named directory inside the current directory |
cd */directory/directory* |
Working directory is changed to the directory defined by the full path /directory/directory |
nano *filename* |
Is stating a basic editor in the terminal to open or create a simple text or configuration file. Closing the editor is done by Ctrl+x and then choosing whether you want to save your changes or not |
sudo nano *filename* |
Is stating a basic editor with write access in the terminal to open or create a simple text or configuration file with root user rights. Closing the editor is done by [Ctrl+x] and then choosing whether you want to save your changes or not |
Initial configuration of Raspbian
The following steps make sure, that basic Raspbian configuration is done.
NOTE: There may be many tutorials in how to set-up and configure Raspbian and going into more details about user rights and other Raspbian features. This tutorial is showing the way which worked for my project aiming to run openHAB2 on the Raspberry. Since this tutorial is using the PIXEL GUI I always refer to the PIXEL way of configuring and only go back to the terminal way (text only) if it is required.
Localisation:
The first thing you want to do is changing the localisation settings to make sure your keyboard layout and WiFi settings are matching.
NOTE: Do not change the password before you have changed the keyboard layout since you might put in a different password than you expect (e.g. US qwerty vs. German qwertz results in “Raspberrz” instead of “Raspberry”)
Changing Password:
This is important to secure your standard Raspberry user “pi” before you connect the Raspberry to the network.
NOTE: Make sure you have changed the keyboard layout to your requirements before change the password.
Enabling interfaces:
This is required for the communication to the PC (SSH) and to the Z-Wave stick (Serial)
Connect Raspberry to network:
Either by plugging in a Ethernet cable or by connecting to a WiFi network:
Description | Image/Command |
---|---|
Click on the network symbol | 3 lines and 2 red crosses if no connection is available |
Select WiFi network | [yourwifi] |
Enter WiFi password | yourwifipassword |
Check the IP address of the Raspberry:
To do so you have to check the IP address of the Raspberry in the terminal:
NOTE: You might want to set your IP address of the Raspberry to static, if you get problems with the lease time setting of your gateway (IP address is changing whenever you reconnect to the network)
Update / Upgrade Raspbian:
Raspbian is proving online updates so make sure that you have the latest installed before you go further in the configuration.
##Optional Raspberry settings and configuration:
The following settings and configuration is just for additional information and might not be needed to setup openHAB2. Some of the settings and configuration might still be useful.
Change display orientation
If you are working with the 7” Raspberry display setup you might need to flip/rotate the display orientation for specific cases
Check partition size on MicroSD card:
Make sure Raspbian is using the full capacity of the MicroSD card (normally while starting up Raspbian for the first time, it is done automatically and the Raspberry will restart automatically):
Create a Desktop icon and link it to a application
To be able to create a Icon you have to first create a yourdesktopfile.desktop file NOTE: This example is creating the desktop icon for the user “pi”
Example file content:
[Desktop Entry]
Name=YourShortcutName
Comment=Your Shortcut Comment
Icon=/usr/share/pixmaps/YourIcon.png
Exec=/usr/bin/YourShortcutApp
Type=Application
Encoding=UTF-8
Terminal=false
Enabling root user:
Since by default the “root” disabled it can’t be used. You might want to enable it for certain purposes like e.g. enabling the root user for samba file server to get full access to the directories from a PC (see chapter setup samba server) NOTE: There is a reason for the “root” being disabled! Enabling the user is allowing full access to the Raspbian and therefore creating a security risk. Please always consider whether you really want to enable this user!
Enabling remote SSH access for root user:
NOTE: There is a reason for the “root” not being enabled for SSH! Enabling the user for SSH is allowing full remote access to the Raspbian and therefore creating a significant security risk. Please always consider whether you really want to enable this user for SSH!
Optional: Raspbian PIXEL screensaver (xscreensaver)
If you are working with the 7” Raspberry display setup you might want to use a screensaver as well. Installation of xscreensaver:
Configuration of xscreensaver:
I am showing an example configuration which is first switching on a screensaver and then turning off the display completely.
Optional: Start Chromium Web server on Raspbian boot
Configure the autostart file:
Select the start URL for Chromium web browser:
NOTE: You can also select the URL in the autostart file, but using the browser functionality is giving you a simpler access (no terminal) and you can check the result without rebooting
Chapter 5: Setting up Raspbian for access via PC
Connect to the Raspberry terminal your windows system using, KiTTY or PuTTY:
Optional: Connect to the Raspberry file system from your windows system using WinSCP:
NOTE: The connection can only access the rights of the Raspberry user. So the standard user “pi” will not have the writing rights for multiple directories. For full access you have to use the user “root” (user needs to be enabled since it is disabled in standard setup, procedure shown later in the tutorial), but enabling this user for SSH access is opening up a significant security risk, so it is recommended to use as Raspberry based Samba server for full access to specific directories (shown later in the tutorial).
Optional: Generic setup of Samba server on Raspbian
To have access to the Raspberry file system using the PC file explorer you have to install a Samba server on Raspbian. With the server installed you can map the selected folders (share) on your Raspberry as a network drive. NOTE: Skip this section to the end of this chapter, if you only want to use the Samba server for openHAB2 purpose. You will find an openHAB2 centric installation guide later in this document.
Command | Description |
---|---|
sudo systemctl status smbd.service sudo systemctl status nmbd.service |
Check if all the services are running |
sudo systemctl restart smbd.service sudo systemctl restart nmbd.service |
Restart the samba services |
sudo systemctl stop smbd.service sudo systemctl stop nmbd.service |
Manually stop the samba services |
sudo smbpasswd -a sambausr |
Create a new Samba user mapping |
sudo smbpasswd -d sambausr |
Disable a Samba user |
sudo smbpasswd -e sambausr |
Enable a Samba user |
Optional: Mapping Raspbian samba directories to Windows (IOS and Linux mapping process can be found online):
Description | Image/Command |
---|---|
One time map the Raspberry folder to a windows drive (in this case Z) enter in the CMD Prompt (just put CMD in the search of Windows 10 to open the command prompt) | net use Z: \\xxx.xxx.xxx.xxx\RaspberryPiDirectories /user:sambausr sambausrpassword /persistent:no |
Persistent map the Raspberry folder to a windows drive (in this case Z) enter in the CMD Prompt (just put CMD in the search of Windows 10 to open the command prompt) | net use Z: \\xxx.xxx.xxx.xxx\RaspberryPiDirectories /user:sambausr sambausrpassword /persistent:yes |
You can also create a simple .bat file for easy double clicking. Open the editor by just putting notepad in the search of Windows 10. Enter the line. Save as yourmapping.bat | net use Z: \\xxx.xxx.xxx.xxx\RaspberryPiDirectories /user:sambausr sambausrpassword /persistent:no |
Chapter 6: Installation of openHAB2 on Raspberry
This tutorial is only focussing on the package repository installation of the stable version and only on the add-ons for the listed hardware. All other installations are described on the openhab.org site installation for Linux:
http://docs.openhab.org/installation/linux.html#package-repository-installation
For the Raspbian you have to go for the “Apt Based Systems” part of it.
NOTE: All the commands in this chapter are terminal commands, so you have to open the terminal:
First, add the openHAB2 bintray repository key to your package manager and allow Apt to use the HTTPS Protocol
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
sudo apt-get install apt-transport-https
I choose the stable Official (Stable) build. The stable builds contain the latest official release with tested features.
echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
Next, resynchronize the package index:
sudo apt-get update
Now install openHAB2 with the following command:
sudo apt-get install openhab2
Optional but recommended: When you choose to install an add-on, openHAB2 will download it from the internet on request. If you plan on disconnecting your machine from the internet, then you will want to also install the add-ons package.
sudo apt-get install openhab2-addons
If everything went well, you can start openHAB2 and register it to be automatically executed at system startup:
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service
Common openHAB2 service commands:
Command | Description |
---|---|
sudo systemctl status openhab2.service |
Shows the status of openHAB2 |
sudo systemctl start openhab2.service |
Start the service of openHAB2 |
sudo systemctl stop openhab2.service |
Stops the service of openHAB2 |
sudo systemctl restart openhab2.service |
Restarts the service of openHAB2 |
sudo apt-get purge openhab2 |
This commands uninstall openHAB2 from your Raspbian |
sudo rm /etc/apt/sources.list.d/openhab2.list |
and delete the source list |
openHAB2 configuration for the samba server:
This is required to grant the PC based Eclipse Smart Home Designer access to the requested configuration folder on your Raspbian. NOTE: This is for using samba for openHAB2 ONLY. If you already have set up a samba with a different user and a full access to raspberry, this might be obsolete.
The shares are configured to be not open for guests nor to the public. Let’s activate the “openhab” user as a samba user
sudo smbpasswd -a openhab
Enter the password openhabpassword which will be used to map the share on your PC
New SMB password:
Retype new SMB password:
Added user openhab.
Be aware, that creating and later using a specific user will ensure that permissions are honoured. Make sure, the “openhab” user has ownership and/or write access to the openHAB2 configuration files. This can be accomplished by executing:
sudo chown -hR openhab:openhab /etc/openhab2
Restart the samba service to allow the changes to be utilized
sudo systemctl restart smbd.service
Map the Raspberry folder to a windows drive (in this case Z) enter in the CMD Prompt (just put CMD in the search of Windows 10 to open the command prompt)
net use Z: \\xxx.xxx.xxx.xxx\RaspberryPiDirectories /user:openhab openhabpassword /persistent:no`
openHAB2 Privileges for Common Peripherals
An openHAB2 setup will often rely on hardware like a modem, transceiver or adapter to interface with home automation hardware. Examples are a Z-Wave, Enocean or RXFcom USB Stick or a Raspberry Pi add-on board connected to the serial port on its GPIOs. In order to allow openHAB2 to communicate with additional peripherals, it has to be added to corresponding Linux groups. The following example shows how to add Linux user openHAB2 to the often needed groups dialout and tty. Additional groups may be needed, depending on your hardware and software setup.
Adding openhab user to groupds dialout an tty
Enter command (This is adding the openhab user to the group dialout)
sudo adduser openhab dialout
Enter command (This is adding the openhab user to the group tty)
sudo adduser openhab tty
Optional: Enter command (If you are looking to enable sound privileges for openHAB2, it will also be necessary to add openHAB2 to the “audio” group.)
sudo adduser openhab audio
Granting java environment access to serial ports
Change to directory
cd /etc/default/
Open openhab2 file in nano editor
sudo nano openhab2
Change the text from (nothing between the “”)
EXTRA_JAVA_OPTS=""
To (something between the “”
EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0"
Exit and save the file [Ctrl+x] > y
> [Enter]
Reboot the Raspberry for the changes to take effect
sudo reboot
Chapter 7: Installation of Eclipse Smart Home Designer
(Optional but strongly recommended for easy editing of openHAB2 configuration files; incl. syntax highlighting)
The complete installation guide can be found on:
http://docs.openhab.org/installation/designer.html#setup
Installation guide for windows (Eclipse Smart Home Designer and Java Runtime Environment):
Download Smart Home Designer
Download the Windows 64 bit version
Optional: Download the 32 bit version since there are reports about the “stable” 64 bit version running not stable
Optional, but not recommended for beginner: Download a snapshot version
Unzip the downloaded file to a destination of your choice
yourpcdrive:\yourdestionation\eclipsesmarthome
Optional: Download the offline Java Runtime Environment.
NOTE: If you do not have a java environment installed, you have to additionally install Java Runtime Environment to be able to run Eclipse Smart Home Designer. In this case we will install the Java files directly into the Eclipse Smart Home Designer folder which will create a “portable” version of the Eclipse Smart Home Designer. (The folder can be copied/moved to different locations or machines without the need of reinstalling).
Go to the java homepage download section https://java.com/en/download/
Optional: Go directly to: https://java.com/en/download/manual.jsp
Download the 64bit version (something like jre-8u131-windows-x64.exe ) or the 32bit depending on your system
Install the Java Runtime Environment to the Eclipse Smart Home Designer folder Start the Java installer. Select on the first screen “Change destination folder”
[Change destination folder] & [Install]
Change the folder to \jre inside your Eclipse Smart Home Designer folder yourpcdrive:\yourdestionation\eclipsesmarthome\jre
since this is the location the Eclipse Smart Home Designer is expecting the JRE.
[Change]
yourpcdrive:\yourdestionation\eclipsesmarthome\jre
[Next]
Launching Eclipse Smart Home Designer first time:
Execute the SmartHome-Designer.exe
yourpcdrive:\yourdestionation\eclipsesmarthome\SmartHome-Designer.exe
Link the Eclipse Smart Home Designer to the configuration folder on your Raspberry NOTE: Make sure that you have mapped the samba drive before (see openHAB2 setup for the samba server)
Example: If you have chosen Z:\ as drive letter the path would be:
Z:\etc\openhab2
Eclipse Smart Home Designer should now recognize the file structure inside the configuration folder and augment the different folders with different icons.
Chapter 8: Initializing openHAB2 (finally: first startup)
To open the openHAB2 you have to access the web GUI with a browser on your PC or directly from your Raspberry, depending on your setup. The URL will be:
http://xxx.xxx.xxx.xxx:8080/start/index
Just replace the xxx.xxx.xxx.xxx with the IP of your Raspberry. First the GUI will ask you to select the initial setup configuration. This will install a standard set of GUIs in openHAB2.
After a few minutes of installation the standard openHAB2 start GUI will come up, showing you the icons for the pre-installed GUIs: [BASIC UI], [PAPER UI] and [HABPANEL]
NOTE: Now you are ready for the configuration of your home automation project in openHAB2!
Chapter 10: General information about configuring openHAB2
NOTE: Make sure to double check with the official website of openHAB2 since in the end this is where you will find the correct answers if something in this tutorial is not working:
As a start you should read the beginners tutorial form beginning to end so you understand the basic concept of things, items, rules etc. and how they are mend to work together;
http://docs.openhab.org/introduction.html
openHAB (no 2) vs. openHAB2
One of the most important things I had to learn is that there is also an openHAB (no 2)! So here are a few things if found out to be considerable if you are using openHAB2:
- Always make sure, that you are looking at the right version of openHAB when it comes down to documentation, since a lot of older online documentation is refereeing to the openHAB (no 2). When a few things might be done the same/similar way in openHAB2, other things have changed and will not work in openHAB2
- You will also encounter two different ways of storing configuration in openHAB. -- In openHAB (no 2).configuration was stored in files only -- In openHAB2 you can still use the files, but also can use database storage for certain typs when you do the configuration with PAPER UI. This now might lead to some confusion since you will not be able to change e.g. items in PAPER UI which were configured using a text file. Also you would not have the correct syntax highlighting in the Eclipse Smart Home Designer is expecting file configuration only an items configured in PAPER UI will show up as errors. -- But be aware that some configuration in openHAB2 still has to be done via text file like e.g. rules. You might find already some progress in the snapshot release of openHAB2, but I decided to base this tutorial on the stable release with limited functionality in PAPER UI database
- Regularly check the website of openHAB2 for news since a lot of new features are expected to be implemented.
- Meanwhile be not afraid to go and sign up the openHAB community: https://community.openhab.org and ask your questions there. I got replies to my problems within days, sometimes even within hrs. There is also a designated area for beginners.
Chapter 11: Configuring openHAB2 using PAPER UI
Since the online documentation is mostly referring to PAPER UI GUI I will try to stick to this GUI as long as possible.
- HABmin GUI will be needed for Z-Wave network management
- HABPANEL GUI will be used to create the final user frontend for this project NOTE: Since you will be regularly starting and switching the GUIs I highly recommend creating quick links in your browser for each GUI
Installing Add-ons:
Start PAPER UI
http://xxx.xxx.xxx.xxx:8080/paperui/index.html#/inbox/search
Installing Bindings:
Select >[Add-ons] >>[BINDINGS]
Install the Bindings: [Exec Binding] , [YahooWeather Binding] , [YamahaReceiver Binding] and [Z-Wave Binding]
Result: The icons of the bindings should change to blue The install option should change to uninstall. (Sometimes you have to reload the page if the update is not coming up for a few minutes).
NOTE: If you already have connected devices to the same LAN as the Raspberry, a message in the inbox will show up, telling you a new thing was found (e.g. Yamaha Receiver) How to add this thing will be explained later.
Install Bindings manually (snapshot bindings):
NOTE: Since we have installed the stable version, we have to manually install the WiFi LED Binding for openHAB2.
Open the terminal:
Change to the openHAB2 add-ons directory:
cd /usr/share/openhab2/addons
Download the addon to the add-ons directory:
sudo wget https://openhab.ci.cloudbees.com/job/openHAB2-Bundles/lastSuccessfulBuild/org.openhab.binding%24org.openhab.binding.wifiled/artifact/org.openhab.binding/org.openhab.binding.wifiled/2.1.0-SNAPSHOT/org.openhab.binding.wifiled-2.1.0-SNAPSHOT.jar
Restart the openHAB2 service:
sudo systemctl restart openhab2.service
NOTE: The restart of the service can take several minutes. You will not be able to access the PaperUI GUI during the restart.
Check the openHAB2 service status:
sudo systemctl start openhab2.service
Remark: This binding will not show up in the >[Add-ons] >>[BINDINGS] tab but will show in the >[Configuration] >>[Bindings]
Check the installed bindings:
Select >[Configuration] >>[Bindings]
Result: You should see now all the installed bindings.
NOTE: You should also see the [WiFi LED Binding which] we installed before manually.
Installing User Interfaces:
Select >[Add-ons] >>[USER INTERFACES]
Install the User Interface [HABmin] (Required for Z-Wave network administration)
Result: [HABmin] GUI is installed.
General process of adding new things to the configuration
NOTE: To be able to add new things to openHAB2 depends on whether they are connected to the LAN (if you use IP), whether they are included in the Z-Wave network of the Z-Wave controller or whether your Raspberry is online if you use online sources like YahooWeather
Select >[Inbox] and click on the >>[+] (the blue plus icon) to start adding things.
Result: This will now show you all the installed Bindings which can be used to add things.
Select [>] (arrow to right) next to the required binding and go through the binding specific adding process for new things.
Checking the added things
Select >[Configuration] >>[Things]
Result: You should see now all the installed things.
Adding local things connected via network (IP):
NOTE: Make sure that the device is connected to the Raspberry network via IP.
Result: The connected devices should come up automatically in the inbox.
Adding Things using YamahaReceiver Binding:
Select >[Inbox] and click on the Yamaha Receiver [checkmark] (the blue checkmark icon).
Result: The YamahaReceiver Binding dialogue will open, allowing you to enter/edit the name.
Confirm the adding by clicking on the [ADD AS THING] button
Adding Things using WiFi LED Binding:
Select >[Inbox] and click on the WiFi LED [checkmark] (the blue checkmark icon).
Result: The WiFi LED Binding dialogue will open, allowing you to enter/edit the name.
Confirm the adding by clicking on the [ADD AS THING] button
Adding online things connected via network (IP)
NOTE: Make sure the Raspberry is online.
Adding Things using YahooWeather Binding:
Select >[Inbox] and click on the >>[+] (the blue plus icon) to start adding things.
Result: This will now show you all the installed Bindings which can be used to add things.
Select [>] (arrow to right) next to the YahooWeather Binding.
Select [>] (arrow to right) next to the Weather Information.
Now you have to configure the thing. In this case you have to enter the WOEID which is a 32-bit reference identifier of the weather information location. You can look up the WOEID on e.g. http://www.woeidlookup.com/
Remark: More information on WOEID on: https://en.wikipedia.org/wiki/WOEID
In this case we choose Berlin WOEID: 638242
Add the thing by clicking on the [checkmark] (the blue checkmark icon)
Adding 433MHz things
Install additional code and configure Raspbian
Open the terminal:
Install git-core
sudo apt-get update
sudo apt-get install git-core
##### Install WiringPi
Change to home directory and download wiringPi
```bash
cd
sudo git clone git://git.drogon.net/wiringPi
Change to wiringPi
directory execute build wiringPi
cd wiringPi
sudo ./build
Install 433Utils
Change to home directory and download 433Utils
cd
git clone https://github.com/ninjablocks/433Utils.git --recursive
Change to 433Utils/RPi_utils
directory and execute make
cd 433Utils/RPi_utils
make all
Change to home directory and move the 433Utils to the /opt/433Utils
directory to make the command line works for every user
cd
sudo mv 433Utils /opt/433Utils
Allowing openHAB2 to send commands to the 433MHz transmitter
Since the 433Utils send tool is using sudo (root) rights you have to allow the openhab user to execute the sent tool with those sudo (root).
Open the sudoers config file:
sudo nano /etc/sudoers
Search for the chapter:
# User privilege specification
root ALL=(ALL:ALL) ALL
Add the line:
openhab ALL=NOPASSWD: /opt/433Utils/RPi_utils/codesend*
openhab ALL=NOPASSWD: /opt/433Utils/RPi_utils/send*
Exit and save the file [Ctrl+x] > y
> [Enter]
Determining the device code and testing the setup
The 433Utils tool is able to process two different kind of codes:
send
comand is processing an unaltered codesystemCode unitCode command
which can directly taken from some 433MHz devices. Thecommand
will determin to switch the device ON1
or OFF0
codesend
comand is processing a single Ninja Blocks compatibledecimalcode
which can be sniffed using the 433MHz remote controll and the 433MHz receiver with thesniff
command.
Determining the systemCode
and unitCode
directly form the 433MHz devices
Since I am running a German setup I only can use devices witch a German certification. I can confirm the Brennenstuhl RCS 1000 N Comfort or Elro AB440S will have the code setting with 10 bit dip switches like shown in the picture.
From this 10 bit dip switches you can directly read the unaltered code from the device.
Dip switch 1-5 is defining the systemCode
, the same code you will have to set at the 5 bit dip switch of the genuine 433MHz remote controller of the set.
Dip switch A-E is defining the unitCode
. NOTE: As specified in the genuine 433MHz remote controller manual, only one dip switch is allowed up to define the unit number.
bit | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
dip name on device | 1 | 2 | 3 | 4 | 5 | A | B | C | D | E |
systemCode dips |
x | x | x | x | x | |||||
unitCode dips |
x | x | x | x | x | |||||
unitCode decimals |
1 | 2 | 3 | 4 | 5 |
Example: Refering to the picture above, the dip setting is:
bit | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
dip name on device | UP | DOWN | DOWN | DOWN | DOWN | UP | DOWN | DOWN | DOWN | DOWN |
This represents the systemCode
10000
and the unitCode
1
Remark: You might be able to determine manually the systemCode
and unitCode
for non 10 bit dip devices following instructions on this sites (German only):
https://wiki.fhem.de/wiki/Intertechno_Code_Berechnung#Original_Intertechno_System https://isn-systems.com/tools/it2elro/
Optional: Determining decimalcode
for unknown 433MHz devices by sniffing the remote control code
NOTE: before you can start sniffing, you have to make sure, the receiver is connected to the GPIO of the Raspberry.
Start the sniffing:
sudo /opt/433Utils/RPi_utils/RFSniffer
Press the required button on the 433MHz remote control.
You will recieve a decimalcode
while you keep the button pressed and one ohter decimalcode
when you release the button.
You will have to use the decimalcode
while you keep the button pressed, in this example 1394001
Repeat the process for all buttons you want to sniff:
Stop the sniffing process by pressing [Ctrl+c]
Test sending the codes by terminal command line
Unaltered code systemCode unitCode command
Sending an unaltered code systemCode unitCode command
sudo /opt/433Utils/RPi_utils/send systemCode unitCode command
Example: If you want to switch a device with the dip setting.
bit | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
dip name on device | UP | DOWN | DOWN | DOWN | DOWN | UP | DOWN | DOWN | DOWN | DOWN |
To switch the device ON:
sudo /opt/433Utils/RPi_utils/send 10000 1 1
To switch the device OFF:
sudo /opt/433Utils/RPi_utils/send 10000 1 0
Single Ninja Blocks compatible decimalcode
Sending a single Ninja Blocks decimalcode
sudo /opt/433Utils/RPi_utils/codesend decimalcode
Example: If you want to switch a device with the sniffed code 1394001
.
sudo /opt/433Utils/RPi_utils/codesend 1394001
Adding 433 MHz Things using Exec Binding:
Open the PaperUI and select >[Inbox] and click on the >>[+] (the blue plus icon) to start adding things.
Result: This will now show you all the installed Bindings which can be used to add things.
Select [>] (arrow to right) next to the Exec Binding.
Select [>] (arrow to right) next to Command.
Enter the [Command] sudo /opt/433Utils/RPi_utils/send 10000 1 1
(The same command line you used in the terminal to test the 433MHz setup).
Set the [Interval] to 0
so the command is not repeated.
Add the thing by clicking on the [checkmark] (the blue checkmark icon)
Adding things connected via Z-Wave controller
NOTE: first you have to use the Z-Wave binding to add the Z-Wave controller as a thing. After this you will use HABmin to further include things into the Z-Wave network. These things should show up automatically in the inbox of PAPER UI.
Adding Z-Wave controller
Open the PaperUI and select >[Inbox] and click on the >>[+] (the blue plus icon) to start adding things.
Result: This will now show you all the installed Bindings which can be used to add things.
Select [>] (arrow to right) next to the Exec Binding.
Select [>] (arrow to right) next to Z-Wave Serial Controller.
Now you have to configure the thing
In this case you have to enter the serial Port of the Z-Wave controller
The standard port where the UBS-Z-Wave controller should come up is:
/dev/ttyACM0
Add the thing by clicking on the [checkmark] (the blue checkmark icon)
Adding Z-Wave things to the Z-Wave Network using HABmin UI
To include further devices to your Z-Wave network and make them available as openHAB2 things you have to use the HABmin inclusion functionality. Please also consult the online documentation for general information about Z-Wave :
** https://github.com/openhab/org.openhab.ui.habmin/wiki/ZWave-Device-Installation**
Using a standard Z-Wave controller like UZB Z-Wave PLUS USB stick by Z-Wave.Me
Start HABmin
Direct URL: http://xxx.xxx.xxx.xxx:8080/habmin/index.html#/home
Select >[Configuration] and >>[Things]
HABmin will show you all the things which are available in PAPER UI as well
To start the inclusion mode of your Z-Wave controller in HABmin you have to select the add thing icon of HABmin [magnifying glass]
Select the [Z-Wave Binding]
This now is triggering the inclusion mode of your Z-Wave controller
Put the Z-Wave devices in inclusion mode to be detected by the Z-Wave controller. Please refer to the Z-Wave devices manual how to put them in inclusion mode.
When the device is included in the Z-Wave network, the [plug icon] will show a green box with the number of the included devices.
Click on the icon to show the details of the included devices.
Just select the green [Add] button to include this device as a thing for openHAB2
NOTE: some devices may come up as “unknown device” at first. The normal reason for this is that the device was not able to finish the communication with HABmin during the inclusion process. This might be very likely for battery powered devices since the will go to sleep mode after a certain amount of time. You can still add the device because there is a way to cure this device by manually waking up the device (see device manual) multiple times (up to 10 times) so the communication can be completed and the device is recognized as a proper thing in HABmin.
The newly added thing should now be visible in the HABmin GUI things tab Now you can switch to the PAPER UI and find the new things in the inbox or check the new things in the things tab.
Using the Aeotec by Aeon Labs Z-Stick Gen5 Z-Wave controller
The special feature of the Aeotec by Aeon Labs Z-Stick Gen5 which is the offline inclusion. This means that the battery powered stick must not be plugged in for the Z-Wave network inclusion process. You have to unplug the stick and press the inclusion button on the stick to start the inclusion mode of this Z-Wave controller. (Please refer to the Aeotec by Aeon Labs Z-Stick Gen5 documentation for further details.)
To start the adding ot the included things to openHAB2 you have to again plug in the stick and make sure the stick is not offline but online.
Open the PaperUI GUI and select >[Configuration] >>[Things]
The Z-Wave Serial Controller must be [ONLINE]
NOTE: If the Z-Wave Serial Controller shows up as [OFFLINE]
Restart the openHAB2 service with the terminal command sudo systemctl restart openhab2.service
. After a few minutes when the service is restarted the controller should show up as [ONLINE].
Now start the standard inclusion process in HABmin.
NOTE: Since the Aeotec by Aeon Labs Z-Stick Gen5 is using offline inclusion almost every battery powered item will come up as “unknown device” because the timespan between including the battery device to the stick and starting the inclusion process in HABmin inclusion after you plugged the stick back in will be too long and most of the devices will have gone back to sleep. You might prevent this by manually waking up the device again just seconds before you start the inclusion on HABmin. If this does not work you can always cure this device by manually waking up the device (see device manual) multiple times (up to 10 times) so the communication can be completed and the device is recognized as a proper thing in HABmin.
The newly added thing should now be visible in the HABmin GUI things tab Now you can switch to the PAPER UI and find the new things in the inbox or check the new things in the things tab.
For details documentation on the Z-Wave Binding usage in HABmin consult:
http://www.cd-jackson.com/index.php/openhab/habmin/10-habmin-zwave-binding-initialisation
Creating items form things
The concept of Things, Channels, Items and Links:
Before we start please read first the concept of Things, Channels, Items and Links which is directly tanken from the openHAB2 User Manual page
http://docs.openhab.org/concepts/index.html#things-channels-items-and-links
Things are the entities that can be physically added to a system and which can potentially provide many functionalities at once. It is important to note that things do not have to be devices, but they can also represent a web service or any other manageable source of information and functionality. Things provide their functionality through a set of Channels. Channels are “passive” and can be regarded as a declaration of a Thing, what it can offer. It is up to the individual setup, which of the Channels are actively used through Items (see below). Items represent (fine-grained) functionality that is used by applications - as user interfaces or automation logic. Items have a state and they can receive commands. The glue between Things and Items are Links. Links are associations between exactly one Thing Channel and one Item. If a Channel is linked to an Item, it is “enabled”, which means that the functionality that the Item represents is handled through the given Channel. Channels can be linked to multiple Items and Items can be linked to multiple Channels. To illustrate these concepts, take a two-channel actuator that controls two lights:
The actuator is the Thing. This might be installed in the electrical cabinet, it has a physical address and needs to be setup and configured in order to be used. The user is instead interested in the two lights, which are located at different locations in his home. These lights are the desired functionality, thus the Items and they are linked to the Channels of the actuator. A Link can be regarded like a physical wire in this example.
The basic process of creating Items in PAPER UI:
http://docs.openhab.org/tutorials/beginner/configuration.html
This beginner tutorial is showing a general quick overview of the complete configuration process.
Creating the required items for this project
For a walkthrough level of detail you can find one complete example for an item creation and a mapping table thing to item.
Open the PaperUI GUI and select >[Configuration] >>[Things] and select the KeyFob_Gen5 thing:
A list of all the available channels of the thing will be shown:
Now click on the blue icon in front of the channel number to link this channel to an item:
A link channel window will come up. Select the pull down option for the item:
The next window coming up will allow you to select already existing items or: In our case [+ Create new item…]
The next window will allow you to configure the item you want to link to the thing channel. You can also change the name of the item if you are planning to run with your own naming convention. Select [LINK] button to create your new item:
Now the blue icon to the left of the name will change [white dot in the center]. By clicking on this icon the channel will expand and show you the linked items to this cannel:
Select >[Configuration] >>[Items] to check the new created item:
Now go on creating the items according to the list below:
Thing | Channel | Item |
---|---|---|
KeyFob_Gen5 | zwave:device:39e18a8c:node9:scene_number | KeyFob_Gen5_SceneNumber |
Weather Information | yahooweather:weather:c5d26906:temperature | Yahoo_Temperature |
Weather Information | yahooweather:weather:c5d26906:humidity | Yahoo_Humidity |
Yamaha Receiver RX-V581 | yamahareceiver:yamahaAV:9ab0c000_f668_11de_9976_00a0dedc57ff:power | YamahaReceiverRXV581_Power |
Yamaha Receiver RX-V581 | yamahareceiver:yamahaAV:9ab0c000_f668_11de_9976_00a0dedc57ff:volume | YamahaReceiverRXV581_Volume |
Yamaha Receiver RX-V581 | yamahareceiver:yamahaAV:9ab0c000_f668_11de_9976_00a0dedc57ff:mute | YamahaReceiverRXV581_Mute |
Z-Wave Node 2: FGS223 Double Switch 2 | zwave:device:39e18a8c:node2:meter_watts | DoubbleSwitch01_LeistungGesamt |
Z-Wave Node 2: FGS223 Double Switch 2 | zwave:device:39e18a8c:node2:switch_binary1 | DoubbleSwitch01_Relais1 |
Z-Wave Node 3: MSP-3-1-X1 Z-Wave Plus Micro Smart Plug ON/OFF | zwave:device:39e18a8c:node3:switch_binary | SchuKo01 |
Z-Wave Node 3: MSP-3-1-X1 Z-Wave Plus Micro Smart Plug ON/OFF | zwave:device:39e18a8c:node3:meter_watts | SchuKo01_Leistung |
Z-Wave Node 6: ZW100 MultiSensor 6 | zwave:device:39e18a8c:node6:sensor_relhumidity | MultiSens_Luftfeuchte |
Z-Wave Node 6: ZW100 MultiSensor 6 | zwave:device:39e18a8c:node6:sensor_temperature | MultiSens_Temperatur |
Z-Wave Node 6: ZW100 MultiSensor 6 | zwave:device:39e18a8c:node6:sensor_luminance | MultiSens_Helligkeit |
HF-LPB100-ZJ200 | wifiled:wifiled:F0FE6B314910:power | HFLPB100ZJ200_Power |
HF-LPB100-ZJ200 | wifiled:wifiled:F0FE6B314910:color | HFLPB100ZJ200_Color |
HF-LPB100-ZJ200 | wifiled:wifiled:F0FE6B314910:white | HFLPB100ZJ200_White |
End of walkthrough
Markdown syntax examples start from here:
General header
Github specific syntax
Fenced Code
Fenced code bash highlighting
Strikethrogh
- Tasklist
- Tasklist
Header 1
Header 2
Header 3
Header 4
Header 5
Header 6
Strong-Bold
Emphasize
inline code
Blockquote
Blockquote
Blockquote
- Ordered List
- Ordered List
- Unordered List
- Unordered List
Page Break before
Page Break after
Section Break before
Section Break before
Sentence Break before
Sentence Break before
column | column | column |
---|---|---|
left | centered | right |
- | - | - |
text | picture |
---|---|
blabla |