MQTT openhab 2.4 No message send or received

I now tried for several days to get the new MQTT binding to work, with out any succes.
Can anyone tell me what I am doing wrong.
This is my bridge configuration:

Bridge mqtt:broker:mosquitto [ host="192.168.1.14", port=1883,secure=false]
{
    Thing topic LRshutters "rolluiken kamer" {
    Channels:
        Type Rollershutter : LRshutterCh1 "Woonkamer 1" [ stateTopic="stat/livingR/window/shutter/shutter1", commandTopic="cmnd/livingR/window/shutter/shutter1"]
    }
}

And this is my items file:

Group gShutters
  "Rolluiken"
  <blinds>
  (gShutters)
Rollershutter livingR_shutters1 "Woonkamer 1" <blinds> (gShutters) {channel="mqtt:topic:mosquitto:LRshutters:LRshutterCh1"}

If I click the up or down butten no massage is send, when I look in mqtt.fx with "# "
While in with rules the old mqtt 1 binding is still working, so I see the messages in mqtt.fx

rule "bathroom shutter "
when
	Item bathR_shutters received command
then 
logInfo("Rollershutter:",   " sends " + receivedCommand)
switch(receivedCommand){
case UP: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER1","ON")
	}
case DOWN: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","ON")
	}
case STOP: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","OFF") // will also swithc power1 to of in the physical switch
	}
default:  {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","OFF")
	}
}
end

Can anyone please help me.

Frank

How does the mqtt.cfg for the old mqtt binding look like?
Does the log give any clue? For instance, do you get an entry that the new binding connected to the broker? Are the mqtt bridge and the mqtt things online?

1 Like

This is how the mqttcfg file looks like:

mosquitto.url=tcp://localhost:1883


mosquitto.clientId=openHAB

<broker>.user=openhab

<broker>.pwd=xxxxx

I have this eeror warning in the log file:
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘MqttBridge.things’ has errors, therefore ignoring it: [5,14]: mismatched input ‘Rollershutter’ expecting RULE_ID

You might need to make a few changes. Compare what you have to the example below.


# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
pibroker.url=tcp://10.0.1.20:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. User id to authenticate with the broker.
pibroker.user=openhab

# Optional. Password to authenticate with the broker.
pibroker.pwd=xxxxxxxxxxxx

Remove the broker, with < and > around it and you should have something like this mosquitto.user=openhab and mosquitto.pwd=xxxxx

Thanks H102, that helpes now openhab is connected to the broker but I still have some problem:

2019-02-17 14:49:56.959 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2019-02-17 14:49:56.960 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2019-02-17 14:49:56.960 [ERROR] [org.apache.felix.configadmin        ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=362, bundle=205/mvn:org.openhab.action/org.openhab.action.mqtt/1.13.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.13.0
2019-02-17 14:49:59.440 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2019-02-17 14:49:59.441 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2019-02-17 14:49:59.442 [ERROR] [org.apache.felix.configadmin        ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=362, bundle=205/mvn:org.openhab.action/org.openhab.action.mqtt/1.13.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.13.0
2019-02-17 14:50:00.005 [INFO ] [lipse.smarthome.model.script.weather] - Temperature changed
2019-02-17 14:50:41.162 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'MqttBridge.things' has errors, therefore ignoring it: [5,14]: mismatched input 'Rollershutter' expecting RULE_ID

Wrong directory apparently. The error say that OH tried to interpret the file as a rule file.

What’s the output of ls /etc/openhab2/rules ?

kve.rules kve.rules.save LocalSun.rules readme.txt shutter.rules wheater.rules wheater.rules.save wheater.rules.save.1 wheater.rules.save.2

shutter.rules which is working is :

rule "bathroom shutter "
when
	Item bathR_shutters received command
then 
logInfo("Rollershutter:",   " sends " + receivedCommand)
switch(receivedCommand){
case UP: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER1","ON")
	}
case DOWN: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","ON")
	}
case STOP: {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","OFF") // will also swithc power1 to of in the physical switch
	}
default:  {
	publish("mosquitto","cmnd/bathR/window/shutter/POWER2","OFF")
	}
}
end

rule "Logeerkamer shutter "
when
	Item logeerR_shutters received command
then 
logInfo("Rollershutter:",   " logeer sends " + receivedCommand)
switch(receivedCommand){
case UP: {
	publish("mosquitto","cmnd/logeerR/window/shutter/POWER1","ON")
	}
case DOWN: {
	publish("mosquitto","cmnd/logeerR/window/shutter/POWER2","ON")
	}
case STOP: {
	publish("mosquitto","cmnd/logeerR/window/shutter/POWER2","OFF") // will also swith power1 to of in the physical switch
	}
default:  {
	publish("mosquitto","cmnd/logeerR/window/shutter/POWER2","OFF")
	}
}
end

rule "Parent room shutter "
when
	Item parentsR_shutters received command
then 
logInfo("Rollershutter:",   "parent room sends " + receivedCommand)
switch(receivedCommand){
case UP: {
	publish("mosquitto","cmnd/parentsR/window/shutter/POWER1","ON")
	}
case DOWN: {
	publish("mosquitto","cmnd/parentsR/window/shutter/POWER2","ON")
	}
case STOP: {
	publish("mosquitto","cmnd/parentsR/window/shutter/POWER2","OFF") // will also switch power1 to of in the physical switch
	}
default:  {
	publish("mosquitto","cmnd/parentsR/window/shutter/POWER2","OFF")
	}
}
end



/*rule "test "
when
	Item livingR_shutters1 received command
then 
logInfo("Rollershutter:",   "test " + receivedCommand)

	publish("mosquitto","cmnd/parentsR/window/shutter/POWER2","OFF")

end
*/
rule "All shutters"
when
	Item all_shutters received command
then
 		/* !!!do not use gShutters group because shutters will com into a swicht on off loop!!!
	   	   Item all_shutters also belongs to group gShutters, this will then trigger an endless loop*/	
	 gAll_shutters.members.forEach[shutter| shutter.sendCommand(receivedCommand)]
end

rule "All livingroom shutters"
when
	Item allLivingR_shutters received command
then
 			
	 gAllLivingR_shutters.members.forEach[shutterLR| shutterLR.sendCommand(receivedCommand)]
end

Use these commands to clean the cache and restart OH to see if you still have the errors.

sudo systemctl stop openhan2

sudo openhab-cli clean-cache

sudo systemctl start openhab2

When doing the above I get the following error when starting openhab

 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-ui-homebuilder, openhab-binding-mqtt, openhab-ui-basic, openhab-transformation-map, openhab-misc-restdocs, openhab-action-mqtt, openhab-ui-habpanel, openhab-ui-paper': Error restarting bundles:
        Exception in org.eclipse.smarthome.io.rest.sse.internal.SseActivator.start() of bundle org.eclipse.smarthome.io.rest.sse.

And it is still not working, the mqtt messages send via the rule are stil working.

THe MqttBridge.things is in the things diretory

/etc/openhab2/things$ ls
kve.things.off  MqttBridge.things  readme.txt

All of this is SO MUCH easier and almost error proof by sing the paperUI instead of things files…

btw, I have opened an Issue to get Paper UI replaced: https://github.com/openhab/openhab2-addons/issues/4918. Batch editing .thing files is probably most often the reason for not using Paper UI at the moment.

I tried it via paperUI. but for me it is very confusing.
I do not see how I can add a state or command topic, it is just possible to add a topic. And it does not work either.

I think I am going back to Mqtt1.9.

That’s always an option. But it would help OH2 development if you somehow try to summarize what could be improved.

Configuratuon via PaperUi or files?
Using PaperUI the config of the setup of each channel for a generic mqtt thing does show such.
Using an things file, the Example page of the documents would be helpfull.

Does some body know what this sentense mean:
"If you use the Mosquitto broker: Please be aware that there is a relatively low setting for retained messages. At some point messages will just not being delivered anymore: Change the setting " from the example page

Yes! I found the problem, of course as always very simple when you know:-)
in the bridge thing I had

Bridge mqtt:broker:mosquitto [ host="192.168.1.14", port=1883,secure=false,username="openhab", password="habopen4444"]
{
    Thing topic LRshutters "rolluiken kamer" {
    Channels:
        Type Rollershutter : LRshutterCh1 "Woonkamer 1" [ stateTopic="stat/livingR/window/shutter/shutter1", commandTopic="cmnd/livingR/window/shutter/shutter1"]
    }   
}  

Rollershutter with a capital R. it must be:

Type rollershutter : LRshutterCh1 "Woonkamer 1" [ stateTopic="stat/livingR/window/shutter/shutter1", commandTopic="cmnd/livingR/window/shutter/shutter1"]

Thanks for all the help!!!

That is strange, in the things file the type should start with small first charater for example rollershutters
And in the items files it should start with capital character like Rollershutter.
Or is there a reason for this?

The things and items file syntax is quite old (about 8 years?), and it is not necessarily logical or simple. For now that is all we have, if you don’t want to use the UI.

Cheers, David