Installing Openhab on Pi

This tutorial is a section of my wider series on creating a home automation solution for heating and watering in my house.  Refer to the index here.

In this post we install a new Raspberry Pi from scratch, and get OpenHab running on it.  We choose to use Wifi, and we install it headless (no GUI and no monitor).  We install by connecting the card reader to a linux machine, which gives us access to the file system as we build it.

I bought a new Raspberry Pi 3.  I’m choosing to run Raspbian on that, and for a variety of reasons I’m preferring to run headless (most importantly, because this Raspberry Pi will typically have no monitor at all).

We start by downloading the raspbian lite version and copy it onto our memory card using the instructions at  In my case the memory card was on /dev/sdi, and at the conclusion of that copy I have two partitions – /dev/sdi1 at 60MB and /dev/sdi2 at 1.2G.

In my case I had a 16GB memory card, and the lite version is a 2GB disk image – we need to resize the partition table so that /dev/sdi2 uses the remainder of the card otherwise we’re wasting space.  We follow the instructions from geekpeek to do this.  We start by listing the current partitions, and taking note of the start sector for /dev/sdi2

  sudo fdisk -l /dev/sdi

In my case that partition starts at sector 131072.  We then run fdisk proper and delete the partition, recreating it with a larger size:

  sudo fdisk /dev/sdi
  d   (for delete)
  2   (delete partition 2)
  n   (create a new partition)
  p   (primary)
  2   (partition 2)
  131072 (first sector)
  enter (default last sector on card)
  w    (write partition table

Run fsck on the filesystem to make sure it’s not busted.

  sudo fsck -f /dev/sdi2

Extend the filesystem to use the whole partition.

  sudo resize2fs /dev/sdi2

Since we have a pi3 we want to use the wireless network rather than the wired network.  We want to configure the wireless network before we put the card into our pi and boot it, so that it will come up straight away on the network.

First we mount the drive so that we can edit the contents:

  sudo mkdir /mnt/pi
  sudo mount /dev/sdi2 /mnt/pi
  cd /mnt/pi/etc/wpa_supplicant

Then we follow the instructions for setting up wifi from the command line, we edit /mnt/pi/etc/wpa_supplicant/wpa_supplicant/conf to add the following lines to the bottom:


We also set the hostname (to raspberrypi2) while we’re at it by editing /mnt/pi/etc/hostname.

We then unmount the filesystem, and sync to make sure everything is written:

  cd /
  sudo umount /mnt/pi
  sudo sync

Now we put our card into our pi, and see if it boots.  We should be able to connect to it over ssh using:

  ssh pi@raspberrypi2

The password will be “raspberry”, you can change this with the command “passwd”.

First we install java onto the machine:

  sudo aptitude update
  sudo aptitude install oracle-java7-jdk

Next, we install openhab onto the machine.  We follow the instructions to use the openhab apt repository:

  sudo wget -qO - '' | sudo apt-key add -
  echo "deb stable main" | sudo tee /etc/apt/sources.list.d/openhab.list
  sudo aptitude install openhab-runtime

Finally, we start up openhab and see whether we can see the web page:

  sudo /etc/init.d/openhab start

Then check the webpage at http://raspberrypi2:8080/ (use your machine name if you chose a different hostname for your raspberry pi, and note that this assumes your wireless router automatically gives your machine the correct hostname on your local network, you may need to find and use the ip address instead).

You should see an openhab error page telling you that you have no default sitemap.

We can check the logs in /var/log/syslog, and /var/log/openhab/* if we’re getting problems.






1 thought on “Installing Openhab on Pi

  1. Pingback: Using Pi and OpenHab to control radiators and watering | technpol

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s