Setting up MQTT items

I’m a bit lost here. I try to connect items between two OH2 instances via MQTT. I don’t want to use the eventbus, as it’s only a bunch of items on one instance, which should be copied to the other one.

At first I installed a fresh new openHABian 1.3 on a raspberry pi 1 and then installed the mosquitto from sudo openhabian-config.

Then, I used this config for my
mqtt.cfg

mqttctg.url=tcp://192.168.x.x:1883
mqttctg.clientId=OH2MQTT
mqttctg.user=user
mqttctg.pwd=password
mqttctg.qos=1

sensors.items

Number	Pressure_Inside	"Luftdruck Innen [%.1f hP]" 		{mqtt="<[mqttctg:sensoren/Pressure_Inside:state:default]"} 
String	IPAddress	"Hütte IP-Adresse (verschlüsselt)" 	{mqtt=">[mqttctg:sensoren/IP:state:*:default]"} 

But it doesn’t seem, the items are subscribed to the MQTT Server. If the IPAdress is changed, it is not sent to the topic and if I try to update the Pressure_Inside in the MQTT, the item don’t gets updated.
I set log:set TRACE org.openhab.binding.mqtt1, but nothing comes up in the log at all.
openhab2.log

2017-11-08 22:55:48.460 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-11-08 22:55:48.759 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mqttctg'

From my perspective, the only thing, which is different from my other installations (with working MQTT) is the RPI 1? (mosquitto_pub and mosquitto_sub works fine!).
Do I miss something else?

I notice that one Item is using an incoming config and the other is using an outgoing config. Is that deliberate? It isn’t clear whether I’m looking at the Items that are to publish the sensor readings to your main OH or the Items on your main OH that are to subscribe to the sensor readings.

Do you see your OH successfully connecting to mqttctg in its logs?

I’m not good at debugging MQTT configs so hopefully someone else can review what you have specifically.

It occurs to me, how do you get the data from the sensors you want to publish? It might make sense to use sensorReporter or write something yourself in Python or the like rather than run a full up OH just to forward sensor readings over MQTT.

Thanks for your thoughts.
For Debugging, some more information:

  • First of all: The items are there for tests - to get info from MQTT-devices into that OH2 and to send info from that OH2.
  • I added a logfile-excerpt last night, and the MQTT Service was initialized and connected.
  • Using "mosquitto_pub" works fine from that OH2 using the same MQTT-Server and credentials.

I intend on using the second OH2 at our mountain cottage (perhaps you remember our exchange on that last week). Indeed I’m going to think a bit on your question to just publish the sensor data and not using OH2 for that. As I have limited Internet access up there, I was thinking on having a local OH2 for querying it while we are up there (displaying the local data). At present I don’t intend to use home automation (yet?). So just Publishing the sensor data directly without OH2 should work on my central OH2 (which in turn I could use for a limited sitemap for displaying). … But I’ll think through it. Thanks for the food for thought.

That was my guess.

That is a good reason to have an OH up there too. But you could configure the Items to publish to both MQTT Brokers, the local one at the cottage and the remote one at the home.

That is one of the beauties of MQTT. It is really easy to set up like this.

1 Like

as usual: you nailed it! :wink: perfect solution, thanks. (still, my Monk in me needs to figure out, why this won’t work… :roll_eyes:)

I missed, restarting OH2 and/or rebooting the whole server.
After some other changes being made, which required multiple restarts/reboots now everything works as expected.

So: boot often, if you’re experiencing some strange behaviour.