wolfgang ziegler


„make stuff and blog about it“

How to manage openHAB running on a Raspberry Pi from Ubuntu

March 2, 2018

TL;DR:

  • A couple of weeks ago I blogged about how to get started with home automation.
  • This blog post is about one of the first problems I had to solve for myself before actually getting productive.
  • My openHAB server is running on a Raspberry Pi but my development environment is running locally on my Ubuntu PC. So question is, how can I comfortably edit the remote configuration files?

The Setup

The openHAB installation is hosted on a Raspberry Pi which I had already running for a couple of other server jobs in my network. Thus, this Raspberry Pi is the system where openHAB stores all its configuration data (items, things, sitemaps, rules, ...) you typically want to edit when setting up or improving your smart home routines.

My work PC (from which I am currently writing this blog post) is an Ubuntu desktop PC. That is where I have all my editors and tools and where I want to do the openHAB configuration. This means I needed remote (write) access to the Raspberry Pi's file system. But before we get into the details of that let's look at the software we can use for this scenario.

The Software

The most popular option for editing openHAB's configuration still seems to be Eclipse SmartHome Designer. Eclipse SmartHome Designer
But honestly, I have had a very "complicated relationship" with Eclipse ever since and wasn't at all intrigued by the idea of using it for managing openHAB.

Luckily, there is an openHAB extension for my favorite editor Visual Studio Code and I have to say I am quite happy with it.

Your mileage may vary, so choose what works best for you. That said, whichever editor or IDE we are using, we now need a directory to point it to, so we can start configuring our smart home.

The Raspberry Pi

This is where the openHAB installation is running and it should have a directory /etc/openhab2, which holds all the configuration files we care about.

$ cd /etc/openhab2

$ ll
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 html
drwxr-xr-x 3 openhab openhab 4096 Nov  1 16:05 icons
drwxr-xr-x 2 openhab openhab 4096 Nov  1 21:08 items
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 persistence
drwxr-xr-x 2 openhab openhab 4096 Dec 10 11:43 rules
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 scripts
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 services
drwxr-xr-x 2 openhab openhab 4096 Nov  1 21:09 sitemaps
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 sounds
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 things
drwxr-xr-x 2 openhab openhab 4096 Nov  1 16:05 transform

So we are going to make these file available on the network via NFS (Network File System)

  • Install an NFS server.
$ sudo apt-get install nfs-kernel-server
  • Set access rights correctly.

We want to share this folder with write access for the user openhab, so let's go and find out their user id (uid) and group id (gid).

$ id -u openhab
111

$ more /etc/group | grep openhab
openhab:x:117:

Now that we have found out these ids we set up the actual NFS share with the correct permissions. So let's open the config file ...

sudo nano /etc/exports

... and add this line ...

/etc/openhab2       *(rw,no_subtree_check,all_squash,anonuid=111,anongid=117)

... to share the folder /etc/openhab with write access as the mentioned user openhab.

  • Propagate these changes and restart the NFS service.
$ sudo exportfs -ra
$ sudo service nfs-kernel-server restart

The Ubuntu PC

This will be the NFS client which we connect to the network share we just created.

  • Install the NFS client software.
$ sudo apt install nfs-common
  • Create a mount point directory.

This is the local directory that will point to the remote file share and in which we will work with our editor or IDE.

$ mkdir /mnt/openhab
  • Check one.

We want to make sure if we did all the previous steps correctly and the NFS shared folder is actually available.

$ showmount -e hugopi.local
Export list for hugopi.local:
/etc/openhab2 *
  • Mount the directory.

Everything looks good, the directory showed up, so let's try and mount it.

$ sudo mount -t nfs hugopi.local:/etc/openhab2 /mnt/openhab/
  • Check two.

Can we actually make changes to this directory and the files in it?

$ touch /mnt/openhab/foo.txt

Everything looks great, we are good to go!

Success]

You probably want to create a shell script with the above mount instruction because > you are probably as lazy as me and do not want to type this every time you boot your PC.

What's Next?

So now that we are able to setup and configure out smart home routines remotely this is what we will look at in a future blog post. Or rather I will pick out a couple of use cases I solved for myself and you can tell me why I suck and how to do it correctly.