Unfortunately, that’s pretty much what you can get from consumer-friendly — but as always, that’s where it comes in: we’ll show you how to get started with the ultimate smart home system that doesn’t have to be bought with money (because OpenHAB is 100% free — just supply the equipment).
The first part of this guide focused on how to set up OpenHAB with Raspberry Pi 2, but the rest of the tutorials and tips can be applied wherever OpenHAB is installed.
This guide covers three introductory topics and one more advanced one.
- Installing and running OpenHAB on the Pi and setting up a demo house configuration to test the functionality of the main systems.
- How to add bindings and profiles for devices. I will work with Philips Hue.
- Enable remote access and connect to IFTTT.
- Adding a DIY presence sensor using Bluetooth and an introduction to the REST interface.
- Setting up the OpenHAB mobile application.
What you need
At the time of writing, the latest stable version of OpenHAB is version 1.71; version 1.8 is expected soon and everything in this guide should still be up to date, although some bindings may have more features. Version 2 is also currently available as a very early alpha preview, but adopts a fundamentally different architecture compared to the OpenHAB 1 series: this guide is not compatible with version 2.
I highly recommend that you follow this guide slowly and methodically. Don’t try to jump into the deep end and add everything at once. Yes, this is a long guide — OpenHAB is a complex system that often needs tweaking to suit your needs, and the best way to ensure success is to work slowly and do one piece at a time.
The good news is that once it’s up and running, it’s incredibly useful and incredibly useful.
There is no preconfigured image for OpenHAB, so installation is done the old-fashioned way via the command line. I suggest you work without RPi support — the overhead of managing a graphical interface that you will rarely use is not worth it.
Start with the latest (full) Raspbian SD image (not the «lite» version, this does not include the Java Virtual Machine). Plug in the network cable, then boot up and SSH into it. Run:
Expand the file system; and from the advanced menu, change the memory division to 16. When you’re done, restart, and as a good practice, run a full refresh
sudo apt-get update sudo apt-get upgrade
The easiest way to install the OpenHAB runtime is via apt-get but first we need to add a secure key and a new repository:
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' |sudo apt-key add - echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo tee /etc/apt/sources.list.d/openhab.list sudo apt-get update sudo apt-get install openhab-runtime sudo update-rc.d openhab defaults
Curiously, everything was set to be owned by «root». We need to fix it with the following commands.
sudo chown -hR openhab:openhab /etc/openhab sudo chown -hR openhab:openhab /usr/share/openhab
Next, we’ll install Samba and share the configuration and user folders — this will make it easier to install add-ons and modify the sitemap remotely.
sudo apt-get install samba samba-common-bin sudo nano /etc/samba/smb.conf
Change the workgroup name if necessary, but otherwise enable WINS support:
wins support = yes
(you need to uncomment the line and change «no» to «yes»)
then add the following to the share definitions section (scroll to the very end of the long file):
[OpenHAB Home] comment= OpenHAB Home path=/usr/share/openhab browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no [OpenHAB Config] comment= OpenHAB Site Config path=/etc/openhab browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=noи
[OpenHAB Home] comment= OpenHAB Home path=/usr/share/openhab browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no [OpenHAB Config] comment= OpenHAB Site Config path=/etc/openhab browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no
I also commented out the «Printers» section. I did two promotions since the config files are actually kept separate from the add-ons.
Save and exit. Finally, we need to set the Samba password for the openhab user:
sudo smbpasswd -a openhab
I would suggest «openhab» as the password just for ease of use, but it doesn’t really matter.
Thanks to reader David L. — it looks like the Samba restart method has changed in the latest Raspian. Here are the updated instructions:
sudo update-rc.d smbd enable sudo update-rc.d nmbd enable sudo service smbd restart
After restarting Samba (older installations use restart samba service sudo ), check access to the shared drive. It may not be auto-detected on a Mac; but you can use Finder -> go -> Connect to Server and address
Log in with the openhab username and password of your choice, then open both of your folders to take a look around. You can even open http://raspberrypi.local:8080/ in your web browser, but you will run into an error because we haven’t created a sitemap yet. This is fine.
Now is a good time to learn the command to bind the OpenHAB log so you can keep an eye on the errors.
tail -f /var/log/openhab/openhab.log
Go ahead and always open it in a separate SSH window as you continue through the tutorial.
Set up a demo house
Before we get into the intricacies of config files, adding devices and bindings, etc.; Let’s test that everything works by adding some demo content. You will find «Demo Setup» in the download section of OpenHAB.org.
Once you have unzipped it, there are two folders: additions and configuration .
Using network resources copy configuration in OpenHAB Config shared folder and overwrite the existing folder. Copy additions to another general resource OpenHAB overwriting the existing folders again. If you are not prompted to overwrite something, you are doing it wrong. If you notice the debug log file, you should see a burst of activity as it notices new bindings and a buzz in action. Open raspberrypi.local:8080/openhab.app? Sitemap = demo to see a demo.
It’s a bit simplistic at the moment, but OpenHAB’s openness means we can install a great new theme later, or a completely alternative interface. For now, we just needed to know that everything was working. Please note that what we are looking at is called a map site (has nothing to do with the sitemap). The sitemap describes the user interface — not the actual devices on your network or sensors — only the interface for viewing them. Every part of it is fully customizable. To see how it was created, open the file sitemaps / demo.sitemap in general OpenHAB Config folder.
It’s pretty tricky, but for the most part, you’ll be copying code snippets from examples elsewhere to create your own interface. Here’s a technical overview of all the possible sitemap elements, but for now, it’s enough just to think about what kind of interface you want to create and what information you want to display.
While you’re there, open up items/demo.items too. Again, it looks scary, but here you create controls and define sensors for tracking.
So how does OpenHAB work?
Now that you’ve taken a quick look at the sitemap and items folder, let’s break down exactly what these files are and the other core OpenHAB components that come together to create a complete smart home. You will find subdirectories for each of them in the OpenHAB Config shared folder.
Items is an inventory of each control device, sensor, or information item that you want to use in your system. It also doesn’t have to be a physical device — you can define a web source like the weather or stock prices. Each element can be given a name, assigned to multiple groups (or none), and associated with a particular binding. (Beginner tip: Capitalization is important when it comes to anchors. I spent a lot of time trying to figure out why my «Hue» bulbs weren’t working; it was because they were supposed to be «hue» instead.)
Sitemaps only apply to the interface you will see when you open the OpenHAB mobile or web application. You can control exactly how you want the buttons to be positioned and the information to be presented. You can define top-level groups for each room in your house; by clicking on each of them, you will see a list of all the devices in that room. Or you might prefer to show groups for each type of device: a button for lights, another for electrical outlets. There may be some devices you use so often that you just need a toggle for them right on your home screen.
Rules This is where the home automation aspect comes into play, where you can define a schedule or conditions for an action to take place. Simple events like turning the bedroom lights on at 10pm a warm red; or more complex logic, such as turning on the heater if the temperature is below 0 and someone is present in this room. You will also find a folder scenarios which offers functionality similar to rules, but at a more complex level of programmable logic.
permanence is a complex topic that we won’t cover in this tutorial, but persistence defines the data you want to keep. By default, OpenHAB will only show the current state of something; if you want to track this value over time, you need to set up a persistence definition for this data source. In this you will specify things like how often a data point should be measured, or when to discard old data points — you will also need to specify what type of persistence mechanism to use, such as MySQL or simple file writing. ,
transformation contains mappings of data values to labels. For example file humidex scale defines the range of moisture index values and how they should be displayed in English: 29-38 is «some discomfort».