MQTT - show data

I have an MQTT broker in my Emoncms Pi, and I am already able to connect from my Openhab Pi.
I am also able to send MQTT data from Emoncms Pi to the broker in my Openhab Pi.

mosquitto_sub -h localhost -d -t "#"
Client mosqsub/3703-openhab sending CONNECT
Client mosqsub/3703-openhab received CONNACK
Client mosqsub/3703-openhab sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
Client mosqsub/3703-openhab received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3703-openhab received PUBLISH (d0, q0, r0, m0, 'emonhub/rx/5/values', ... (16 bytes))
Client mosqsub/3703-openhab received PUBLISH (d0, q0, r0, m0, 'emonhub/rx/5/values', ... (17 bytes))

mosquitto_sub -h -d -v -t "#"
Client mosqsub/3712-openhab sending CONNECT
Client mosqsub/3712-openhab received CONNACK
Client mosqsub/3712-openhab sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
Client mosqsub/3712-openhab received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3712-openhab received PUBLISH (d0, q0, r0, m0, 'emonhub/rx/5/values', ... (16 bytes))
emonhub/rx/5/values 69,59,7,5,126,28
Client mosqsub/3712-openhab received PUBLISH (d0, q0, r0, m0, 'emonhub/rx/5/values', ... (16 bytes))
emonhub/rx/5/values 68,57,9,4,126,27

I have my Emoncms Transport config like this:


And my item like this:

String  mqttMessage     ""      <colorwheel>    { mqtt="<[localhost:/emoncms:state:default]" }

However in my Openhab interface it appears as blank, or like not waiting data.

What am I missing? Any idea? Thanx!

Where you have localhost in the item binding config string, it should be the name of the broker as defined in openhab.cfg, emonhub in this case. The second value, between the second and third : , should be the topic you are subscribing to from the emonhub broker. Whenever something publishes to the topic you’ve subscribed to with the item, it should appear as the state of your mqttMessage item. From the broker’s log, it looks like emonhub/rx/5/values would be the topic.

1 Like

It is working now with this format.

String  mqttMessage     "MQTT [%s]"     <pie>   { mqtt="<[emonhub:emonhub/rx/5/values:state:default]" }

It is receiving data, in my events.log:

2015-09-14 16:07:54 - mqttMessage state updated to 94,59,31,2,125,27
2015-09-14 16:07:57 - mqttMessage state updated to 91,58,26,10,126,27

Is there any method to use each item (each colon separated number) in this string as a number, showing each in a different item? Should be something like this?

Number mfase1 {mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,(.*),.*)]"}

Thanx for your help Watou.

I think that approach would work, where you would create as many items as values you want to extract from the string. Ideally, the publisher would put each item’s value in its own topic so you could avoid the REGEX transform, but the REGEX you gave ought to work to extract the second comma-delimited number.

1 Like

It works perfectly… now I have data from my OpenEnergy Monitor directly in Openhab.
Next… graphics. Thank you very much. :smiley:

Number  Emonhub_CT1     "Geral [%d Watts]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX((.*),.*,.*,.*,.*,.*)]" }
Number  Emonhub_CT2     "Cozinha [%d Watts]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,(.*),.*,.*,.*,.*)]" }
Number  Emonhub_CT3     "Sala e outros [%d Watts]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,.*,(.*),.*,.*,.*)]" }
Number  Emonhub_CT4     "Suite e outros [%d Watts]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,.*,.*,(.*),.*,.*)]" }
Number  Emonhub_VLT     "Voltagem [%d Volts]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,.*,.*,.*,(.*),.*)]" }
Number  Emonhub_TMP     "Temperatura [%d C]"      <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX(.*,.*,.*,.*,.*,(.*))]" }

Hi there
I am just starting to integrate my EmonCMS with OpenHab

I understand that the broker is active in EmonPI (for me at

I have this as config in openhab.cfg:

no other config

String mqttMessage “MQTT [%s]” { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX((.),.,.,.,.,.)]" }

but nothing shows up in the gui.

In EmonPi I have not touched anything
In OpenHab too (just installed the binding’s jar in addon)

In events.log i do not see any trace of mqtt message

should a mqtt broker be installed on openhab raspberry too?

No… only server side has a broker running.

You should first test if your EMONCMS is able to share data.
Maybe it has a firewall issue in your EMONCMS server.

mosquitto_sub -h BROKER_IP -t "#" -v

Maybe also… your “topic” in broker is not “emonhub”, than you will need to change it in the follow line…

It should be:
Number mqttMessage "MQTT [%d]" <house> { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX((.*),.*,.*,.*,.*,.*)]" }

You did:
String mqttMessage "MQTT [%s]" { mqtt="<[emonhub:emonhub/rx/5/values:state:REGEX((.),.,.,.,.,.)]" }

Take a look here… about firewall issue:

  1. Real-time data from emonHub using MQTT (see example below):

MQTT is a lightweight communication protocol for small web-connected devices. The latest version of emonHub as setup on the emonPi (and emonHub from July 15) uses MQTT as a link to Emoncms and also to provide data to the emonPi LCD script. Since MQTT is already running all we need to do is to point Node-RED MQTT input block to subscribe to the ‘emonhub/rx/#’ MQTT topic on port 1883. The ‘#’ topic includes data received from all nodes. To subscribe to just one node use e.g. emonPi use: ‘emonhub/5/values’ or ‘emonhub/10/values’ for emonTx.

To subscribe the the emonPi’s MQTT topics externally (if your running node-RED on another machine) you will need to open up the MQTT port on the emonPi:

$ sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

I have this as config in openhab.cfg:

check that `, it should be

Yep sure.was not the problem .But solved