Part 2 - 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.

 

What we'll need

Raspberry Pi 4 B 2GB or higher with case (optional DIN holder)

SSD disk (at least 64GB) (or better quality 16GB and higher microSD card, but this is not as reliable as SSD disc in production)

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 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 utility Pi Imager available for Linux, Mac or Windows.

https://www.raspberrypi.com/software/

2) Connect microSD card or SSD disc for OpenHAB to your PC. Run Pi Imager. Choose OS:

PiHome - Pi Imager

click Other specific-purpose OS -> Home Assistant and home automation -> openHAB -> choose 32bit variant.

In Choose Storage choose your microSD card or SSD disc and select Write!

 

Note: You will lost all data on your selected disc. 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.

Hint:  Network where you connect openhabian for first boot should have internet available. It is neccessary for first boot.

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

Create new user ans set password:

OpenHAB 3 - First Login​Set regional settings, you can select the location from the map and install the basic extensions. To start we will need these 7 Addons see below (click to enlarge):

OpenHAB - Bindings

After the installation, go to Settings->Things and create a new Thing with the + icon at the bottom right. Choose the type MQTT Binding->MQTT Broker. Fill in any UID and enter localhost as the server address. Confirm with the Create Thing button at the bottom.

OpenHAB - MQTT Broker Settings

Do we need something else? Sure, SSH access

Use SSH to access your RPi. You'll use this every time you develop/debug, so SSH is a must! It may be time to familiarize yourself with a terminal (command line in Linux), for example, here. It looks scary, but it's the most beautiful thing on Linux. It works always in the same way, everytime and everywhere.

For Windows 10 users, there is already SSH support built in through a shell. For other Windows users, we recommend Putty. For those who have Linux, I don't have to write any more. We connect via SSH with a command to a terminal. Attention: Replace the IP address below with yours from the router for openHABianPi device.

Login: openhabian, Pass: openhabian

ssh openhabian@192.168.4.30

After login, enter this command:

sudo openhabian-config

Here we 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 new password, which ideally you do not use on the internet and will serve primarily for your smarthome. You can change the password clicking to Change passwords item.

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:

 

[home]
comment=home folder
path = /home/openhabian
writeable=yes
create mask=0664
directory mask=0775
public=no
veto files = /Thumbs.db/.DS_Store/._.DS_Store/.apdisk/._*/
delete veto files = yes

[libraries]
comment=lib folder
path = /usr/share/arduino/libraries
writeable=yes
create mask=0664
directory mask=0775
public=no
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

Tailscale - remote access without public IP
Tailscale - remote access without public IPRating: 
80%

The Tailscale service solves access between individual devices if you don't have a public IP address. It's free for one user with support for up to 100 devices. We'll show you how to install Tailscale on a Raspberry Pi that you'll have at home and on a client (Android, iPhone) from which you'll want to access the home Raspberry Pi. Our example will be remote access to OpenHAB running on a Raspberry Pi. However, the same setup applies to many other applications - home NAS, PiHole, Home Assistant, Domoticz, NextCloud, and others.

Shelly OpenHAB MQTT
Shelly vs OpenHABRating: 
90%

The Shelly brand is known for its products that primarily communicate over WiFi, including smart plugs, relay switches, blinds control relays, and many other devices. One of the advantages for deployment is the ability to both read and control these devices using the universal MQTT protocol. Across existing add-ons for both OpenHAB and Home Assistant, we will demonstrate how to use Shelly devices without installing any additional extensions.

Victron & OpenHAB
Victron vs Smart HomeRating: 
0%

In this post, we will show you how to retrieve information from a photovoltaic power plant by Victron. We will connect to the Cerbo unit via MQTT. Based on these values, we can control various appliances (heating, boiler, etc.) and prevent the battery from being drained when they don't need to be.

Smart Home GoodWe inverter
Smart Home vs GoodWeRating: 
50%

In the post, we will demonstrate step by step how to communicate directly with the GoodWe inverter in a smart home setup and obtain real-time information (unlike the SEMS portal). This information is essential if we want to react to current parameters in a smart home, such as activating additional cooling or controlling a socket with a various load.

Voice control smart home
Voice control of the houseRating: 
60%

In this article, we will connect the Amazon Echo Dot voice assistant with open source home automation. We won't be using OpenHAB Cloud, so everything runs locally. In this case, a few additional settings are necessary, but the result is worth it!

MikroTik - Winbox, DHCP, Ranges
Basics - Winbox, DHCPRating: 
69.7%

In this series, we will look at the step-by-step setup of MikroTik devices for home users or a small business (up to 25 people). In the first article, we will focus on the initial setup - we will download Winbox and set up DHCP for the primary network and guest network. Similarly, we will also adjust the WiFi settings.

Alarm Smart Home PIR
Alarm from existing PIR sensors in a smart home.Rating: 
0%

In a your smart home, PIR sensors may not only be used to switch lights on and off based on motion, it is possible to utilize these sensors to detect the presence of motion in a particular room. This information can be used to create a relatively reliable uncertified home security system. In this guide, you will find the logic for how this can work in the OpenHAB software in our model smart home.

NFC Tag Example in Smart Home
NFC tags in smart homeRating: 
80%

NFC (Near Field Communication) tags are small plastic or paper stickers that can be used to automate various functions in the smart home. In this article, we will show you examples of use and a guide on how to write an action on an NFC tag using a mobile phone.

WireGuard iOS
WireGuard on iOS devicesRating: 
85%

In this article, you will find a detailed guide on how to connect to WireGuard VPN from iOS.

WireGuard on Android device
WireGuard on Android devicesRating: 
0%

In this article, you will find a detailed guide on how to connect to WireGuard VPN from Android.