Connecting Emoncms with openHAB

In this post I’ll explain how energy data from Emoncms can be made visible in openHAB. My scenario is as follows: I have Emoncms running on a dedicated Raspberry Pi and openHAB running on another server. This will also work if you have both systems running on the same machine. My goal was to make the energy data visualized in Emoncms available in openHAB and display it there, too.

Find the MQTT Configuration

First, we need to find the MQTT configuration for EmonHub. This can be found on the Emoncms web interface by navigating to Setup | EmonHub | Edit Config | Section [[MQTT]]

We will need this data later to connect the MQTT broker.

Install the MQTT Binding in openHAB

On your openHAB web interface, open the Paper UI and install the MQTT binding:

Add an MQTT Broker

In the openHAB Paper UI, add a new thing of type MQTT Broker. As broker hostname/IP, enter localhost or 127.0.0.1 if your Emoncms installation is on the same device. Otherwise, enter the local IP address of the machine running Emoncms.

Also, the username and password you configured in the MQTT configuration of your EmonHub (see above) must be entered:

Add a MQTT Thing

Now we can create a thing representing your Emoncms / EmonPi. Select the broker you just created as bridge.

Create channels for each value you want to transfer between Emoncms and openHAB. For example, for my first power value I created a new Number Value Channel and entered the following MQTT State Topic:

emon/node1/power1

The exact name depends on your Emoncms configuration. In the example, a node named node1 is configured which receives power values in a channel named power1.

We now have a number value channel in openHAB which looks like this:

Add openHAB Items

For each channel we can now create items an openHAB items file. For the channel above, my item looks like this:

Number:Power Energy_Power1 "Power 1 [%d W]" <energy> (gEnergy) { channel="mqtt:topic:fc2fe9b1:power1" }

Note that I have defined a group named gEnergy in my openHAB configuration. You can read more about group configurations here. Now we can use the item Energy_Power1 in openHAB (for example in sitemaps). Create other channels and items accordingly. Now you can monitor your energy data in Emoncms and openHAB at the same time 🙂

New WordPress-based site

Hey folks,

finally I made it to setup my new website. I decided to use a wordpress publishing system now and I must say I’m pretty happy with it! I guess now I can share my ideas, music tracks, videos and code snippets much faster than before. I’m looking forward to that!

Cheerz,
Dave