Raspberry Pi, Arduino, Sensors and the data they produce

Monthly Archives: January 2016

OpenHAB Configuration Scenario

I have talked to the sensors and openHAB configuration builds through several blog entries, so today I will summarize my current “as built” situation, for anyone wanting to follow my path.  I will not go into extreme depth, as I detailed each build previously, but I will link to the source pages I used in this build.

Read more of this post

openHAB Success

Since the last blog entry, I have been consumed with building a working environment, and building additional sensors.  I am currently modifying the environment with those additional sensors.

One sensor was particularly difficult for me. It was not really the sensor, nor openHAB, but the way I went about studying the how-to-do-it pages. I’ll explain, just to show how hard you can make a task, even though it is relatively simple.

Read more of this post

openHAB Designer

openHAB Designer is a utility that I think is worthwhile to add to the environment. It allows the editing of the openHAB configuration files with much more ease that with “sudo nano x” on the RPi itself.  I completed my initial installation all from the command line, so I don’t want to hear any commentary on how I should stay true to the platform, I already can do it, now I want to do it easier!

Read more of this post

openHAB Alternate Installation

My last two posts were based on some pages found on the MySensors.org, written by a user who has had much success in getting started, and we good for me, as I really like to play from a script the first few times I mess in a new environment.

Not everyone thinks like I do, so here is an alternate way to start.


First, read through this openHAB getting started page. You can follow this exactly, and if you want to mirror my environment you can make these adjustments below to get rolling.
I used the distribution found here:


Read more of this post

openHAB Rules

When we last visited, I gave you a quick view of the details of the openHAB installation process for the Raspberry Pi, and we started configuration of the environment, but left when we got to the rules.  Rules are how openHAB lets you know about sensor data.  While there are lots of options here, let’s keep this look simple and stick to a simple sensor, the DHT11/DHT22 as built from the MySensors.org web site.

To begin, if you are where we left off – good. If not, you will need to be in the configurations directory, under /opt/openhab.

Now, you will need to make some entries.  I copied this from the mysensors.org forum, from user TimO:

cd rules
sudo nano demo.rules

Demo Rules – demo.rules

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.util.*
import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.items.*

String ArduinoUpdate = “”
var String sketchName = “”

var int V_TEMP = 0
var int V_HUM = 1
var int V_LIGHT = 2
var int V_DIMMER = 3
var int V_PRESSURE = 4
var int V_FORECAST = 5
var int V_RAIN = 6
var int V_RAINRATE = 7
var int V_WIND = 8
var int V_GUST = 9
var int V_DIRECTION = 10
var int V_UV = 11
var int V_WEIGHT = 12
var int V_DISTANCE = 13
var int V_IMPEDANCE = 14
var int V_ARMED = 15
var int V_TRIPPED = 16
var int V_WATT = 17
var int V_KWH = 18
var int V_SCENE_ON = 19
var int V_SCENE_OFF = 20
var int V_HEATER = 21
var int V_HEATER_SW = 22
var int V_LIGHT_LEVEL = 23
var int V_VAR1 = 24
var int V_VAR2 = 25
var int V_VAR3 = 26
var int V_VAR4 = 27
var int V_VAR5 = 28
var int V_UP = 29
var int V_DOWN = 30
var int V_STOP = 31
var int V_IR_SEND = 32
var int V_IR_RECEIVE = 33
var int V_FLOW = 34
var int V_VOLUME = 35
var int V_LOCK_STATUS = 36
var int V_DUST_LEVEL = 37
var int V_VOLTAGE = 38
var int V_CURRENT = 39
var int msgPresentation = 0
var int msgSet = 1
var int msgReq = 2
var int msgInternal = 3
var int msgStream = 4
var int alarmArmor = 1

// Internal Commands

var int I_BATTERY_LEVEL = 0
var int I_TIME = 1
var int I_VERSION = 2
var int I_ID_REQUEST = 3
var int I_ID_RESPONSE = 4
var int I_INCLUSION_MODE = 5
var int I_CONFIG = 6
var int I_FIND_PARENT = 7
var int I_LOG_MESSAGE = 9
var int I_CHILDREN = 10
var int I_SKETCH_NAME = 11
var int I_SKETCH_VERSION = 12
var int I_REBOOT = 13
var int I_GATEWAY_READY = 14

// Mappings
var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
“4;0;” -> “livingHum01”,
“livingHum01” -> “4;0;”,
“4;1;” -> “livingTemp01”,
“livingTemp01” -> “4;1;”

//receiving msg from mysensors gateway
rule “Arduino sends to Openhab”
Item Arduino received update
var String lineBuffer = Arduino.state.toString.split(“\n”)
for (String line : lineBuffer) {
var String[] message = line.split(“;”)
var Integer nodeId = new Integer(message.get(0))
var Integer childId = new Integer(message.get(1))
var Integer msgType = new Integer(message.get(2))
var Integer ack = new Integer(message.get(3))
var Integer subType = new Integer(message.get(4))
var String msg = message.get(5)
if(msgType == 1 ){
if (subType == V_TEMP){
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), msg)
println (“Temp item: ” + sensorToItemsMap.get( nodeId + “;” + childId + “;”) + ” temp: ” + msg )
if (subType == V_HUM){
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), msg)
println (“Hum item: ” + sensorToItemsMap.get( nodeId + “;” + childId + “;”) + ” hum: ” + msg )
// Internal Command
if(msgType == 3){
if(subType == I_SKETCH_NAME){
println(“Sketch name: ” + msg )
if(subType == I_SKETCH_VERSION){
println(“Sketch version: ” + msg )
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), sketchName+” ” +msg )

A note here about the mappings entry above. You will need to modify this for the ID of your sensor. I modofied the mysensors.org code to statically assign the ID of each sensor. You can also let openHAB set these ID’s, which the sensor will store in eeprom. You will have to match those IDs when attempting to display their data, so the above mappting will have to be customized to your environment, or you will not get any data to display.

Now move up a directory, then go to the sitemap directory.
cd ..
cd sitemap

And the final step for the base configuration is to put in what is called the sitemap. This will give you a display that can be read in a web browser.

sudo nano demo.sitemap

Raspberry Pi Gateway -Send-Recieve

sitemap demo label=”My House”
Frame label=”Weather” {
Text item=livingTemp01
Text item=livingHum01

Now start up your environment if it is not running:

Change back to the /opt/openhab directory and run openhab:

sudo ./start.sh

Using either the RPi browser or one from another computer, and call up this :


if you are using a different computer, simply change localhost to the IP address of your RPi.

You should be greeted with this display:

FIrst Screen builtvar

You now have an operational MySensors / openHAB installation!

OpenHAB Install and Configuration


The installation for openHAB is fairly simple.  You can use different methods, such as apt-get and download/extraction.  I chose the download/extraction method. I will use quotes to “bring” attention to specific entries, just know that they are not part of the text to be entered.

I started up my Raspberry Pi (RPi) and I established a session via putty from my PC.

Next I logged in with the default pi account.

I recommend using a version 1.7.1 (or higher if available).

Create a directory under /opt, label it “openhab”

sudo mkdir /opt/openhab

Now, how ever you want to do this step, you can.  I am lazy, so I started up a browser on the RPi, and went to the openhab web site [http://www.openhab.org/getting-started/downloads.html], and downloaded the following files:



Now you want to extract these. Change to our new directory.


sudo unzip /home/pi/downloads/distribution-1.7.1-runtime.zip -d /opt/openhab

Now make a directory for the addons:

mkdir addons

sudo unzip /home/pi/downloads/distribution-1.7.1-addons.zip -d /opt/openhab/addons

Okay, you now have an installation.

Let’s get the configuration started. change to the configurations directory.

cd /opt/openhab/configurations

Now we will edit the demo items to get our first sensor setup.

sudo nano items/demo.items

insert the information about your arduino gateway/ftdi interface, [Note this /dev device can be verified by examining dmesg];

String Arduino “Arduino” { serial=“/dev/ttyUSB0@115200” }

Next populate some sensor information:

Number      baseTemp01 “Temperature [%.1f °F]” <temperature>    Number      baseHum01 “Humidity [%.1f %%]” <temperature>

Now startup the environment, and watch for the INFO event to show up:

[INFO ] [runtime.busevents ] Arduino state updated to 0;0;3;0;14;Gateway startup complete.

Next post we will look into rules.

Most of this information came from TimO, within the mysensors.org forum:







A Fork in the Sensor Road

As you have seen in the prior posts, our group has been delving into sensors that we can use to secure our homes, as well as provide knowledge about what is happening in the home environment.

To recap the efforts to date:

  1. Created a group of sensors based on the MySensors.org information:
    1. Sound Sensor
    2. Temperature  Sensor
    3. Motion Sensor
  2. Created a Gateway device, to aggregate the sensor data and deliver it to the “controller” product (PiDome, openHAB)

Controller – the GUI-Dashboard  and Data Processing Engine

After some research, the prior post was about PiDome as the Dashboard for a group of sensors we have build based on the MySensors.org site.  One of the guys also had looked at openHAB project, and suggested we also evaluate that application and compare it to the PiDome.

At the end of the last effort, I was struggling to get enough info on the PiDome / MySensors gateway connection, which left me a bit frustrated.  Both parts seemed to work, but ran into trouble with the integration, so I decided to create a parallel environment with openHAB.

Now, I don’t want to disparage PiDome, in fact, I think it is a solid product, and intend to continue to learn about it and build on it, I just need to dig in and get better with it.

So the fork in the road led me to look for information on the openHAB installation on a Raspberry Pi, and I was rewarded with several different methods on installation, and multiple sets of documentation on how people did so (blogs, instructables, etc).

I started with this instructable as a reference:


This got me the demo system on Raspberry Pi, and I was able to do the demo setup and play around with it. I then went looking for details on how to use mysensors units and gateway with openHAB.  A “google” later, and I had a dozen good links to work with.

My next step was to delete the environment, and I  used the rmdir -Rf to wipe out the openHAB directory.

I then followed the installation steps (I will detail these in the next post) to get a much new release installed.  Basically requiring a directory creation, download of two zip files, and then hooking up the sensor “gateway” to the usb port on the Raspberry Pi.

Next, you need to setup the items & rules for the sensors you are monitoring.  A couple links here for reference materials:



All that being said, it is fairly easy, once you know the secrets!

Here are the basics to get you started (assumption you have loaded the demo configuration):

Check out the directory /opt/openhab/configurations

Note the sub-directories, /items & /rules, you will need to make sure they have what we need to get rolling.

TO “bind” the mysensor gateway, openHAB need to know about the device, and how to talk to it. TO do this you bring in the appropriate .jar file, in my case I brought in the entire group of these. I hope that later in the effort I can remove those I do not think are necessary.  so I have deployed the following:


These are all the components that are necessary to get the environment up and running.  Additional details to follow on the configuration needed to get this off the ground, but we can start by updating the demo.items to include a couple of sensors. we label them and give them an ID. Next we update the demo.rules to define the variable names for these items, as well as what to do when an item (sensor) delivers data.

Once that is completed, you start up the server, plug in the arduino gateway, and do some checks to make sure we are “seeing” the gateway, and then receiving the data:

Here is an example:

2015-04-02 20:19:47.057 [INFO ] [runtime.busevents ] Arduino state updated to 0;0;3;0;9;read:1011010s=0,c=1,t=1,pt=7,l=5:44.7 101;0;1;0;1;44.7 2015-04-02 20:19:47.114 [INFO ] [runtime.busevents ] livingHum01 state updated to 44.7 Hum item: livingHum01 hum: 44.7

Finally, you create the Dashboard page that relays the received sensor data to the user by configuring the “sitemap”.

Once this is completed, you can open a browser and see your data. It is running on Port 8080, which is a standard port.


SO that is in a nutshell what it takes to get openHAB up and running.  There is a bit of configuration to do to get a final setup completed, but most of those steps are just repeats of what was outlined above.  The next post will give the nitty-gritty detail of this installation.