How to build an openHAB 4 appliance (openHABian with touchpanel) on a Raspberry Pi 4

What do I mean with openHAB 4 appliance?

The openHAB 4 appliance is an all in one system combining the openHAB 4 server based on openHABian with a lightweight touchpanel solution based on HABpanel on a Raspberry 4 to control your house, in a case that also gives home to the original Raspberry touchpanel. If you already run an openHABian based openHAB 4 installation on a modern Raspberry Pi you can upgrade it following just the parts of this tutorial beyond the installation of openHABian. But, you can take a backup of an existing openHABian based server, too, to install a new Pi or start from scratch, by following the tutorial completely. If you already own a running system, I would highly suggest making a backup of the SD-card first, so that you can return to that, if anything went wrong during the further steps.

The part of the touch client GUI of the openHAB 4 appliance is based on an article in the ct magazin 12/22 p. 160 “Raspi als wartungsarmes Kiosksystem“. I choose HABpanel as a frontend, but you can use every GUI you want, as long as it is web based with this solution.

For earlier versions, I used the official Raspberry case.

My latest version uses the SmartiPi Touch 2 case that has three advantages.

  1. While the original case demands a bottom up installation of the touchscreen that leads to a reduced picture quality, the SmartiPi case takes the screen in the correct orientation.
  2. It also allows adjusting the screen.
  3. There are two backpanels available with more or less space for some additional hardware. E.G. I use the Razberry hat attached to the GPIO-Pins of the Raspberry for z-wave instead of an USB don-gle to keep it compact.

Warning:

openHABian is not intended as a basis for „something else“ and therefore not supported if you use it for „something else“ by adding a user interface or anything else on the same machine. If you follow this tutorial, you will have to take care of any additional components in the future by yourself and there could be situations in which an update via openHABian could interfere with the additional components you installed for your openHAB appliance or vice versa. So as always: Make backups!

But:

Since openHAB 1.8 I built such devices for myself, first from scratch, now based on openHABian, and they work well as long as you do not put too much load on the system. My actual appliance is based on a Raspberry 4 with 4GB.

BTW:

If you need additional touch terminals in the house to control openHAB you can use the minimal image of Pi OS without GUI instead of the openHABian image on an old Pi and follow this tutorial leaving out the parts specific to the openHAB server.

What you need:

  • Raspberry Pi (take advantage of a fast modern model with more memory, my model 4 with 4 GB works well)
  • Original Raspberry touchscreen
  • Original Raspberry case or SmartiPi case or similar solutions for Pi, screen and additional components
    Attention: As there is no access to the SD-card slot after the Raspberry Pi is installed in the case, do not install the components in the case before everything works as expected! Use a “flying” setup of the hardware components instead for installation by connecting the touch screen and additional wanted components like the Razberry z-wave hat to the Raspberry Pi lying on a nonconductive surface (the box of the touchscreen can be used as a stand for it) and take care of static electricity by grounding yourself. There are different wiring options for the touchscreen. With the original case comes a short USB cable to daisy chain from the screen to the Raspberry. The power supply is connected to the interface board of the screen. With the SmartiPi you get a Y-cable to connect the screen and the Raspberry in parallel to the power supply. Install the cable for the power to the screen and the Raspberry now, but do not power on the system yet.
  • Power supply with enough power for Pi, screen and additional components
  • SD card (use a high quality manufacturer and an “endurance model” as always requested for use in a Raspberry, as you hardly will find a card below 32 GB these days, size does not matter)
  • A PC (I use and describe using a Windows PC) connected to the internet with a reader/writer for SD cards and a SSH client like Putty and an editor like Notepad++ installed.

Let us start:

Installation of openHABIAN:

Open https://www.raspberrypi.com/software/ and download the Raspberry Pi Imager for your OS.

Install the Raspberry Pi Imager and start it.

If you want to build the appliance: Under OS choose “other specific-purpose OS” first and then “Home assistants and home automation” and finally “openHAB”. This tutorial is based on the 32-bit version of the image; the 64-bit version was not tested, so go for the 32-bit version, if in doubt.

If you want to build a touch client only, choose “Raspberry Pi OS (other) first and then Raspberry Pi OS light (32-bit)

Put your SD-card in your SD-card reader/writer and choose it as the SD-card to use in Pi Imager and then click on “Write”.

After the Pi Imager has finished writing the SD-card, close it, open a file browser and go to the SD-card. It’s first partition is named “boot”, now and can be accessed under windows, too.

To install the openHAB 4 appliance: Open openhabian.conf with an editor and change the name of the server to install to your needs, if you want.

At:

timezone=Europe/Berlin
locales="en_US.UTF-8 de_DE.UTF-8"
system_default_locale="de_DE.UTF-8"

you can define settings for localisation of the system to be installed.

If you would like to connect to your new server via Wifi you can enter the data of your Wifi, too, under:

wifi_ssid=""
wifi_password=""
...
wifi_country=""

If you want to use a backup of an already existing openHABian installation, you can copy the backup ZIP-File to the boot partition of the SD-card, rename it to initial.zip and uncomment the following line

# initialconfig=/boot/initial.zip

Save your changes and exit the editor. If you would like to change other settings please refer to the openHABian documentation https://www.openhab.org/docs/installation/openhabian.html.

Attention: You can also change the password for the openhabian user here. But that did not work (at least in the last version I tested), so stay with the standard here and change the password later.

If you use the original Raspberry Pi case in which the screen is installed bottom up you have to open config.txt and add the following line under Display setting:

lcd_rotate=2

Save the change and leave the editor.

Hint: If you get yellow flashes on your screen indicating low power from the power supply but your system runs stable, you can also add a line

avoid_warnings=1

to config.txt.

Now take the SD-card out of your PC and put it in the Raspberry Pi. Attach the power supply and the LAN cable (if you use a wired LAN) and if you want to perform the following steps directly from the Rasberry, a keybboard and a mouse (I prefer using SSH to connect from my PC using a SSH-Client like putty) and the installation process of openHABian (or Pi OS for a pure touch client) will start. Wait until the installation progress has finished and you are able to log in to the system after an automatic reboot has occurred.

Configure the openHABian server (just for the Appliance):

If you did not connect a keyboard and a mouse to your Rasberry, open a SSH session to your new server by using the server name previously given (or the standard openhabian, if not changed). Log in with the standard credentials for openHABian (user openhabian, password openhabian)

Start the openHABian config menu with

sudo openabian-config

Go to „30 System Settings“ and „34 Change passwords“ to change the password for the openHABian user first.

If you use the Razberry z-wave hat, go to „30 System Settings“ and “35 Serial port“ and activate the options serial console and Bluetooth to be able to use the Razberry.

Now reboot the system to activate all the changes.

If you did not use a backup of a configuration of an already existing openHAB server as include.zip above and also do not want to restore a backup manually now within openhabian-config, now is the time to install the bindings you need, add the devices you have as things, connect items to the channels of the thing, representing its functions, and take care of a first GUI. Note the name and path of the page you would like to show as the homepage of your home automation touch panel for later.

Installing the GUI

First, we need a GUI-User with limited rights on the system that logs in automatically every time the system is started. We call it kiosk and give it a password

sudo useradd -m kiosk
sudo passwd kiosk (openhabian_kiosk)

To make this user log in, every time the system boots up in the future

sudo mkdir – p [/etc/systemd/system/getty@tty1.service.d](mailto:/etc/systemd/system/getty@tty1.service.d)

cd [/etc/systemd/system/getty@tty1.service.d](mailto:/etc/systemd/system/getty@tty1.service.d)

Now we have to change the config
sudo nano override.conf

You need a line as follows under

[Service]

ExecStart=/sbin/agetty --skip-login --login-options "-f kiosk" %I 38400 linux

Save changes and leave the editor (in nano + to write the changes to the file and then + to exit)

The last thing you need is a .hushlogin file:

cd /home/kiosk

touch .hushlogin

Now it is time to install openbox

sudo apt install --no-install-recommends xserver-xorg x11-xserver-utils xinit firefox-esr-l10n-de openbox –y

To configure it for our needs

cd /etc/xdg/openbox
sudo nano menu.xml

Edit the file that it looks as follows:

<?xml version="1.0" encoding="UTF-8"?>

<openbox_menu xmlns="http://openbox.org/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://openbox.org/
                file:///usr/share/openbox/menu.xsd">

<menu id="root-menu" label="Openbox">
  <item label="Web browser">
    <action name="Execute"><execute>x-www-browser</execute></action>
  </item>
</menu>

</openbox_menu>

Save your changes and leave the editor.

To set the language for displaying messages, … you can edit the environment file

sudo nano environment

Change the settings to your needs, for example:

#
# Set system-wide environment variables here for Openbox
# User-specific variables should be placed in $HOME/.config/openbox/environment
#

# To set your language for displaying messages and time/date formats, use the following:
LANG=de_DE.UTF8

# To set your keyboard layout, you need to modify your X config:
# http://www.google.com/search?q=how+to+set+keyboard+layout+xorg

Now, to be able to start openbox, we have to add the kiosk user to the video group:

sudo usermod -a -G video kiosk

To get openbox started automatically

cd /home/kiosk
sudo nano .profile

At the end of the file add:

echo "Waiting 3 Minutes for the openHAB server to start before desktop is started ..."
sleep 240
exec startx -- -keeptty >~/.xorg.log 2>&1

to give the openHAB server enough time to start up before the GUI is loaded. You may have to optimize the number of seconds to wait in the sleep command depending on your individual system. Do not be too short with this delay. Otherwise, the browser will not be able to open the webpage of your GUI and you will just get an error message instead, stating that the page could not be found.

Finally let openbox know what should be started inside it at start:

cd /etc/xdg/openbox
sudo nano autostart

At the end of the file a line like the following is needed:

firefox http://192.168.0.249:8080/habpanel/index.html#/view/Homeautomation --kiosk &

whereas firefox means the firefox webbrowser. The following part describes the page and its view to load within firefox. In my case it is a HABpanel named Homeautomation which was previously configured within HABPanel and saved on the server in the default location under the IP of the server using port 8080, which is the default port for the openHAB GUIs under the path and view
/habpanel/index.html#/view/Homeautomation

Give your system a final reboot and it should come up with the openHAB server first and then starts the GUI.

Openbox in this tutorial is configured for turning off the screen after a while and reactivating it by a touch to save energy and to protect the screen.

A final note: There have always been discussions on (not) adding a GUI to an openHAB server. These are well understood and there is no need to start them again. There are also enough alternatives for a touchpanel to use with openHAB based on all different kinds of devices and noone has to use a Raspberry. But I wanted to do it, I did it, it works and perhaps others would like to do the same.

4 Likes

An awesome guide… I have been looking for something almost the same for years.

I have a 24" Philips muliti-touchscreen, (with build-in webcam) which I had planed to use and mount an Rpi on the behind, before it goes to the wall-mount.
The Philips monitor is connected through HDMI to the Rpi. And as far as I recall there is a linux driver for the monitor.

Unfortunatly it required to much Linux knowlegde for me. So I´d put the project on a hold, untill I have better time to “study” this.

Now may be the time, as I think much of what you have ind this guide could be used. The only difference is, that my monitor will be connected to the HDMI port. Other than that, it seems likewise.

I’ve been using an Acer 24" touch screen monitor with Rpi4 running plain raspbian os. It is only acting as a web browser, not to run openhab. It displays photos (taken from Facebook, so anything I posted to select albums automatically gets into the photo rotation) + house power stats, security camera, etc. using MainUI’s Page.

This monitor provides USB-C PD which powers the rpi.

1 Like

Thats what I was planning. It doesnt have to be the “openHAB server” Rpi connected to the monitor.
The issue I faced was to get it to start the browser automatically in kiosk mode. I really suck at Linux.

Thats awesome, unfortunatly my monitor doesnt provide that option. So I have to provide power as usual.

Here’s my note about how to set up rpi to open a browser in kiosk mode, starting from a clean / plain install of a raspbian os, configure your ip address (I have a note about how to do that too) then the following. The raspbian os is otherwise plain no other customisations.

Set X11 to autostart Chromium Browser

sudo cat <<EOF > /etc/xdg/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash

@xset s off
@xset -dpms
@xset s noblank

@unclutter -idle 10

@/home/pi/bin/start-browser.sh
EOF
sudo apt remove chromium-browser -y
sudo apt-get install chromium unclutter -y

mkdir ~pi/bin

cat <<EOF > ~pi/bin/start-browser.sh
#!/bin/sh

# Remove exit errors from the config files that could trigger a warning
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences

/usr/bin/chromium --kiosk \
    --noerrdialogs \
    --disable-session-crashed-bubble \
    --disable-infobars \
    --check-for-update-interval=31536000 \
    'http://192.168.1.10:8484/#!/page/photo_page'
EOF

chmod 755 ~pi/bin/start-browser.sh

Turning screen on/off

To turn the screen off, issue this command (via ssh)

vcgencmd display_power 0

To turn it on:

vcgencmd display_power 1
2 Likes

The usual way to use such devices is a driver that emulates a mouse (plus x if we talk about multitouch, …). And with such a driver the monitor should work with openbox, … The driver for the original Raspberry touchpanel works exactly this way and as long as you do not deactivate it, you will see the mousepointer on the screen, when you touch it.

1 Like

For my Philips multitouch monitor, it should also have a screensaver (turning of the screen after 1 minute or something simular). And then turn it on again when touching the screen.
But that may be rather basic settings in Linux?

If you use the official full GUI installation of Pi OS as described by @JimT, the X-Screensaver is part of it. In my setup I do not use it, as I always had problems with it and the original Pi touchscreen. Either it switched it totally off, so I could not wake it up by touching it, or the backlight of the screen did not turn off (the screensaver just displayed a black image), costing money for nothing and wear down of the backlight. Without it, my setup now turns off the backlight and the screen keeps responsive to touching it.

Hmm that sounds like the exact same problems I have with my tablets, even running Fully Kiosk browser… It works like hell.
Either it dont turn off the screen, or it doesnt turn on by the use of camera (motion sensor build-in Fully Kiosk brower) or when touching the screen.

Wonder how it will work with my Philips monitor.

I disabled the screensaver (in the commands above). I then use the room’s motion sensor. When no motion for a while, send the “display off” command to the pi via ssh. When motion detected and the screen is off, send the “display on” command.

So there’s never a need to “wake” the screen by touching it. If it had gone to sleep, just wave at the motion sensor :slight_smile:

The touch / cursor seems to work fine. I can use it to swipe the photos left/right, show security camera feeds, etc.

1 Like

That might be an option I can do fine with. Thank you.