Yet another MQTT question

Ok, I’m lost and I need directions. I have mosquitto installed on a pi at address 192.168.2.21, and it has been working fine for a year. I have installed openhabian on a different pi at 192.168.2.55, and it has a z-stick plugged in and talking to a whole house power monitor just fine. It even works when I’m remote via nginx. I’ve installed the openhab app on my android and I can see power consumption etc. Now I’ve decided to try to route the MQTT traffic through openhab, so that I can view and control my items with openhab. But I’m still missing some piece. Here’s what I have (where \OPENHABIANPI\ is the network location, as I’m working in windows and have the samba server running on the pi) :

I modified the file \OPENHABIANPI\openHAB-conf\services\mqtt.cfg to include the line
localMQTT.url=tcp://192.168.2.21:1883
every other line in the file is commented #

I created a file \OPENHABIANPI\openHAB-conf\sitemaps\main1.sitemap that file contains:
sitemap main1 label=“hvac”
{

Number item=temperature label=“0068ae2ae”

}

and I create a file \OPENHABIANPI\openHAB-conf\items\test1234.items that contains:
Number temperature “temp [%.1f]” {mqtt="<[localMQTT:hvac/0068ab630:state:default]"}

I modified the file \OPENHABIANPI\openHAB-conf\services\mqtt-eventbus.cfg so that the following two lines are not commented:
broker=localMQTT
stateSubscribeTopic=/hvac/0068ab630/${item}/state

I know MQTT broker is working and publishing to the topic hvac/0068ab630. In the android app, I can see the hvac sitemap (I also see the “Home” sitemap that has the Power monitor under it). But there are no “things” under hvac.

In \OPENHABIANPI\openHAB-log\openhab.log I see the lines:
2017-06-29 00:31:21.600 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-06-29 00:31:21.606 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘localmqtt’

What am I missing? Do I need something in \OPENHABIANPI\openHAB-conf\things\ ?

Thanks,
Dale

Mega Edit (after drinking my first cup of coffee): Use:

sitemap main1 label="hvac"
{
Text item=temperature label="0068ae2ae"
}

There is no Number element type in sitemaps: http://docs.openhab.org/configuration/sitemaps.html#element-types
no need to do the below steps :stuck_out_tongue:

----Pre-Coffee response—
Your configs (items, sitemap, mqtt.cfg) look good to me.
You don’t really need the mqtt-eventbus since you are subscribing to the topic using the item config.

The MQTT binding is a 1.x binding, so it doesn’t follow the Things concept from openHAB 2.x.

Try to debug the OH2 ↔ Broker connection: Enter in the openHAB console using the commands below
ssh into the openHABian system and then:

sudo su
ssh openhab@localhost -p 8101 // with password: habopen
log:set DEBUG org.openhab.binding.mqtt
log:set DEBUG org.openhab.io.transport.mqtt
logout // from the OH2 console
tail -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log

To start clean and to make troubleshooting easier, I would recommend:
Keep your /etc/openhab2/services/mqtt.cfg (aka openHAB-conf\services\mqtt.cfg) as is, comment out everything in mqtt-eventbus.cfg, delete /var/lib/openhab2/config/org/openhab/mqtt.config & mqtt-eventbus.config (if it exists), restart OH2 with DEBUG logging enabled on the binding.

You don’t see the temperature item being listed at all ? (even without any value?)
This means that you may have a problem with the main1.sitemap file.

Edit: (my bad) Of course you won’t see it… I modified the first line of my post :slight_smile:

1 Like

Thank you so much for the reply. I changed the sitemap to what you show. And now I see something under “hvac”, but its just the label: https://www.dropbox.com/s/anbk3vbrf5ssk9o/Screenshot_20170702-155241.png?dl=0

But there is no value displayed. Also, I see this in /var/log/openhab2/openhab.log:

2017-07-02 16:44:53.491 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test1234.items’
2017-07-02 16:45:01.944 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'main1.sitemap’
2017-07-02 16:45:03.653 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘temperature’ for widget org.eclipse.smarthome.model.sitemap.Text
2017-07-02 16:45:03.656 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘temperature’ for widget org.eclipse.smarthome.model.sitemap.Text
2017-07-02 16:45:03.658 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
2017-07-02 16:45:05.788 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at /start
2017-07-02 16:45:07.267 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-07-02 16:45:07.855 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-07-02 16:45:09.313 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2017-07-02 16:45:10.805 [DEBUG] [org.openhab.io.transport.mqtt ] - BundleEvent STARTING - org.openhab.io.transport.mqtt
2017-07-02 16:45:10.821 [DEBUG] [org.openhab.io.transport.mqtt ] - BundleEvent STARTED - org.openhab.io.transport.mqtt
2017-07-02 16:45:10.846 [DEBUG] [penhab.io.transport.mqtt.MqttService] - Starting MQTT Service…
2017-07-02 16:45:10.909 [DEBUG] [org.openhab.io.transport.mqtt ] - ServiceEvent REGISTERED - {org.openhab.io.transport.mqtt.MqttService, org.osgi.service.cm.ManagedService}={service.pid=org.openhab.mqtt, component.name=MQTT Connection Service, component.id=0, service.id=284, service.bundleid=187, service.scope=bundle} - org.openhab.io.transport.mqtt
2017-07-02 16:45:10.949 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-07-02 16:45:10.954 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'localmqtt’
2017-07-02 16:45:10.992 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTING - org.openhab.binding.mqtt
2017-07-02 16:45:11.000 [DEBUG] [.binding.mqtt.internal.MqttActivator] - MQTT binding has been started.
2017-07-02 16:45:11.037 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.mqtt.MqttBindingProvider}={component.name=org.openhab.binding.mqtt.genericbindingprovider, component.id=165, service.id=288, service.bundleid=191, service.scope=bundle} - org.openhab.binding.mqtt
2017-07-02 16:45:11.048 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Creating new client for ‘tcp://192.168.2.21:1883’ using id ‘openhab.1499028311028’ and file store '/var/lib/openhab2/tmp/localmqtt’
2017-07-02 16:45:11.091 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler, org.osgi.service.cm.ManagedService}={event.topics=openhab/, service.pid=org.openhab.mqtt-eventbus, component.name=org.openhab.binding.mqtt.eventbus, component.id=166, service.id=290, service.bundleid=191, service.scope=bundle} - org.openhab.binding.mqtt
2017-07-02 16:45:11.125 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.
2017-07-02 16:45:11.146 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/
, component.name=org.openhab.binding.mqtt.MqttItemBinding, component.id=167, service.id=291, service.bundleid=191, service.scope=bundle} - org.openhab.binding.mqtt
2017-07-02 16:45:11.165 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTED - org.openhab.binding.mqtt
2017-07-02 16:45:11.381 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - Initializing MQTT Event Bus Binding
2017-07-02 16:45:11.441 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - Setting up Event Bus State Subscriber for topic /hvac/0068ab630/+/state
2017-07-02 16:45:11.458 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Starting message consumer for broker ‘localmqtt’ on topic '/hvac/0068ab630/+/state’
2017-07-02 16:45:11.475 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT Event Bus Binding initialization completed.

So it looks like I’m still missing something. Any ideas?

Thanks,

Dale

This I also just noticed. in the console:
openhab> smarthome:items list
ZWaveNode2_SensorPower (Type=NumberItem, State=2357.28, Label=Energy Consumption, Category=Energy)
PowerMonitor_ElectricMeterWatts2 (Type=NumberItem, State=1450.92, Label=Electric Power Consumption, Category=Energy)
PowerMonitor_ElectricMeterWatts1 (Type=NumberItem, State=906.72, Label=Electric Power Consumption, Category=Energy)
PowerMonitor_SensorPower2 (Type=NumberItem, State=NULL, Label=Energy Consumption, Category=Energy)
PowerMonitor_SensorPower1 (Type=NumberItem, State=NULL, Label=Energy Consumption, Category=Energy)

So the item temperature is not even listed. Shouldn’t it be?

Thanks,

Dale

Well, I found it. Turns out that since I’m publishing the temperature as a string, it has to be defined as a string item. So now my items file looks like this:

String inTemp "Value: [%s F]"  {mqtt="<[localMQTT:hvac/0068ab630:state:default]"}
String outTemp "Value: [%s F]"  {mqtt="<[localMQTT:hvac/0068ae2ae:state:default]"}

and both items now show up as items and display in the android app!

Thank you very much for helping me.

1 Like

Hey

A bit of Help Please

2017-07-03 20:08:32.334 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'test'
2017-07-03 20:08:32.355 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'm2m-eclipse'
2017-07-03 20:08:32.355 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection
java.lang.IllegalArgumentException: tcp://10.0.0.26:8883/
at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateURI(MqttConnectOptions.java:433)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:260)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:222)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.openConnection(MqttBrokerConnection.java:291)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.start(MqttBrokerConnection.java:112)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.openhab.io.transport.mqtt.MqttService.updated(MqttService.java:109)[214:org.openhab.io.transport.mqtt:1.9.0]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)[3:org.apache.felix.configadmin:1.8.12]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)[3:org.apache.felix.configadmin:1.8.12]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)[3:org.apache.felix.configadmin:1.8.12]
at org.apache.felix.cm.impl.ConfigurationManager$UpdateConfiguration.run(ConfigurationManager.java:1772)[3:org.apache.felix.configadmin:1.8.12]
at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141)[3:org.apache.felix.configadmin:1.8.12]
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109)[3:org.apache.felix.configadmin:1.8.12]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]

I’m trying to access an MQTT Broker on raspberry Pi running Openhab2
You know the Story…

Heres my .cfg contents:

test.url=tcp://10.0.0.26:1883/

The rest is commented Out

I’ve spent hours Trying to Tackle this

I would appreciate Help

most likely, you are suffering from:

delete /var/lib/openhab2/config/org/openhab/mqtt.config and restart OH2

Root cause: Stale config entries kept in OH2 (port 8883 was most likely an older trial that you did to connect to the m2m-eclipse? Broker that was kept)

edit: also: Help with MQTT please - #16 by watou

Also, it’s poor form to post the same question in two different threads. In the future, I’d suggest starting a new thread with your issue if it’s not related to the initial question in the current thread.

1 Like

Alright Sorry

Will do…

Number 1!!:grin:

Thank You @Dim Works fine now …

1 Like