Basic - OpenHAB on Raspberry Pi

The heart of the intelligent house is the OpenHAB project, which runs on Raspberry Pi board. In this article, we will prepare image, launch OpenHAB and set up basic services. This will give us a stable base whether we use wired sensors, relays or wireless standard like Z-Wave, etc.  Raspberry Pi is most popular mini PC with enought power for our application. Power consuption is  ~ 5 W. Thanks to its fair price and miniature dimensions, it is recommended to double it in the switchboard for backup. Currently, the Raspberry Pi 3 Model B+ is more than enough.

What we'll need

RPi 3 B+ or 4 B with case (optional DIN holder)

SSD disc or SSD flash disc (or better quality microSD card but this is not as reliable as SSD disc)

USB HUB with external power (at least 25 W) or USB adapter

Power and scheme

The Raspberry Pi is ideal for this application to be powered from USB hubs with external power. The consumption for the RPi 3 B+ is around 2.5 A at 5 V. The Raspberry Pi USB port is also connected to a USB hub to communicate with Arduino Mega boards see the wiring scheme. All communication between boards is done through the LAN.

Pi-Home - schéma zapojení OpenHAB

Software

1) Download the image of openhabian (openhabian = operating system raspbian with OpenHAB installation)

https://github.com/openhab/openhabian/releases

The current version for RPi 3 B+ at the time of writing this manual is 1.6. Look for .img.xz format and version 32-bit.


2) Connect the SSD disc or microSD for OpenHAB to your computer and download the Etcher software. For Linux users on Debian there is .deb package available. I recommend a Portable version for Windows (without installation). Simply run Etcher, select the .img.xz image and press Flash!

Note: If you want to unpack the image on the SSD USB drive and can't see it, set the "Unsafe mode" in the Etcher configuration. Be careful not to overwrite any other disk! I recommend disconnecting all other external disks and double-check what you do!)

3) Plug the SSD disc with openhabian, ethernet cable and USB power into the RPi. When you connect the RPi to the monitor/TV via HDMI, all you see is the command line. But if we have an ethernet cable plugged in, our OpenHAB probably got the address from the DHCP router. Join to your home router to see the list of connected devices and check device with hostname "openHABianPi". For me, let's say 192.168.4.30. Wait about 30 minutes, downloading the necessary packages and configuring the first boot. When finished, type in the browser:

http://192.168.4.30:8080

Select Standard!

What else do we need? SSH!

Use SSH to access your RPi. You'll use this every time you develop/debug your smart home, so adopt SSH. Perhaps it's time to familiarize yourself with the terminal (command line in Linux), for example try this guide. It looks scary, but it's the most beautiful thing on Linux. It just works always and everywhere with same results.

SSH support already exists for Windows 10 users built into the shell. For other Windows users, I recommend Putty. I don't have to write any more for Linux users.

So, we connect via SSH in terminal. Replace the IP address with your address for openHABianPi from router.

Login: openhabian

Pass: openhabian

ssh openhabian@192.168.4.30

Enter a command when logged in

sudo openhabian-config

Here we will do the basic setup. In System Settings, you can change the hostname (the name of the OpenHAB in the network) and possibly change the time, location or layout of the keyboard, but most importantly, change the default password! for all services from openhabian to your custom password, which is ideally not used on the internet and will be primarily for the smarthome. Select Change passwords to do this.

Pi-Home - nastavení OpenHAB

In Optional Components, the important part is to install the Mosquitto service. During installation, this will ask you for your MQTT Broker password. The default user is openhabian choose your own password to protect data transfer from sensors and to relays!

Pi-Home - nastavení OpenHAB - MQTT

(OPTIONAL)

If you want to use Arduino and upload sketches from Raspberry Pi, you can't do without the arduino package. On RPi, where we have OpenHAB running, log in via SSH and install a utility capable of uploading sketches to Arduino. Add openhabian user to the dialout group.

sudo apt-get install arduino-core arduino-mk

sudo usermod -a -G dialout openhabian

In the home directory /home/user/ , create directories with a specific label for the Arduino board, such as Ard0, Ard1, Ard2, etc. These folders will contains: folder:

Makefile - contains board type information, used libraries and path in /dev/serial

Sketch -  .ino file containing your program (sketch)

Nahrávání skecthů Arduina z Raspberry Pi

if you run the make upload command in this directory, a build-xxy folder is created and the sketch is uploaded to the appropriate Arduino. If you need any more libraries for Arduino, download them to your /usr/share/arduino/libraries/ folder.

Tip: Add the /usr/share/arduino/libraries/ folder to Samba by adding:

[lib]
 comment=opt folder
 path=/usr/share/arduino/libraries
 writeable=yes
 only guest=no
 public=no
 create mask=0664
 directory mask=0775
 veto files = /Thumbs.db/.DS_Store/._.DS_Store/.apdisk/._*/
 delete veto files = yes

to the end of the file smb.conf. You can use nano editor:

sudo nano /etc/samba/smb.conf

confirm changes by pressing CTRL+O and exit from editor pressing CTRL+X

To explain:

Samba

You can read what Samba is, for example, here. Samba is already enabled on openhabian, you can simply share files with it over the network with Windows, PiKodi, PiNAS and other devices. It also supports authentication and encryption, but I wouldn't publish Samba to the internet definetely. It's ideal in the internal network. In the Windows File Explorer, just type in \\192.168.4.30\ to see the shared folders from OpenHAB. Authentication by defaulting login/pass.

Mosquitto

We will use the MQTT protocol (3.1.1 so far) to communicate between Arduino and OpenHAB. Later, with other devices. A huge amount of stuff communicates through the MQTT. You just listen to the values in OpenHAB and take some action, or somehow display it, save it on a graph, etc. In practice MQTT is used for a few nodes (home automation, for example) up to industrial use (thousands of nodes).

In this step, we have an OpenHAB installed and operational. If you make a backup of your SSD disk/SD card and put it in a second RPi, you have a robust backup. Remember to always backup the SSD drive continuously!

Add comment

Nejlepší články z blogu

Centrální tablet pro chytrý dům
Wall tablet to controll your smart homeRating: 
100%

Wall tablet or older smartphone is perfectly suited as a central indicator of the state of the home, as well as controlling it. It usually replaces the video doorbell and as example, you can play your favorite music or read recipes on it during cooking in your kitchen. In the article, we describe a functional example of such a "wall" tablet and its settings in so-called kiosk mode so, display doesn't run at night and only reacts when someone is nearby. Centrální tablet nebo starší smartphone se perfektně hodí jako centrální ukazatel informací o stavu v domě a také k jeho ovládání. Zpravidla nahrazuje videovrátného a můžete si na něm pustit například oblíbenou hudbu při vaření nebo číst recepty. V článku popíšeme funkční příklad takového "wall" tabletu a jeho nastavení v tzv. kiosk módu, aby nesvítíl po nocích a reagoval jenom když je někdo poblíž.

Jablotron and smarthome synchronization
Connecting Jablotron with OpenHABRating: 
0%

In this article we will show you how to install Jablotron binding in OpenHAB. This binding helps us to synchronize states from Jablotron alarm to OpenHAB. Typically, you can force to switch off lights, close water pipe and circulation, switch off sockets or whatever you want to do when you leave home and set alarm.

Advanced disk cloningRating: 
0%

The classic disk cloning tool in linux is the dd command. This command creates a image of disk or extracts the contents from the image to disk. The dd tool needs to be handled carefully and you need to understand its use. We'll show a more advanced technique of creating a disc image that contains unallocated space. A classic example is when I have a Raspbian operating system installed on a 250 GB disc, but there's only a tiny boot partition (e.g. sda1) and my own operating system partition (sda2) which together have 15 GB. Instead of saving a 250 GB image, I would like to save only two partitions with 15 GB, so that the image is smaller and can be expanded to 16 or 32 GB flash.

iOS OpenVPN Connection SettingsRating: 
0%

In this article you will find detailed instructions on how to connect to OpenVPN from iOS devices.

Android OpenVPN Connection SettingsRating: 
40%

In this article you will find detailed instructions on how to connect to OpenVPN on Android.

OpenVPN on MikroTik routersRating: 
100%

If you have a smart-home, NAS, etc., it's a good idea to think about safe access to your network when you are not at home. Currently I recommend commercial router like Turris or a cheaper option of MikroTik routers. In the other hand, Raspberry Pi can be used as OpenVPN server too. In this article, we will show how to set up secure access to your home network from the internet using OpenVPN on MikroTik routers.

Video intercom Doorbird in OpenHABRating: 
0%

Native support for OpenHAB is provided by video intercom by Doorbird company. The solution is powered and connected by a UTP cable and has its own IP address to make it easier for you to install at the gate. OpenHAB is then able to import images from the intercom, visit history, manage gate opening on the button and by the phone, do not disturb feature during night, alarm feature etc. In the instructions we guide you how to use OpenHAB with Doorbird D101.

Advanced PIR sensors features in OpenHABRating: 
0%

The HC-SR501 PIR sensor contains mechanical adjustement for detect range and time. But in an intelligent house, we want to be able change time how long the light will be active and change whether the light will be controlled by PIR or not. Below it's shown how to program the PIR sensor to enable this features.

Measure tank level water OpenHAB
Measuring the water volume in reservoirRating: 
100%

In this article, you can find how to solve the measuring the water level in the reservoir (e.g. rainwater reservoir). The values are converted into the volume in liters. This enables you to fill the volume tank when needed or predict any other situations.