Openhab authenticates w/MQTT broker, but does not PUBLISH

Hi all.

My problem is that Openhab seems to be initializing as an MQTT client and my items/rules are configured. Openhab connects to the local MQTT broker but never publishes to it even though I think Openhab reports that it is publishing - it even shows there are 2 publishers (I’m not sure where the second one comes from - a rogue socket perhaps?)

I am thinking… possibly Openhab thinks it is the broker and is sending messages to itself? It thinks it’s talking to the broker - my REAL broker even shows the successful connect. There are even PINGREQ packets from Openhab to my REAL broker, but something is wrong.

I have Mosquitto installed on a Raspberry Pi 2 and have been using it with ESP8266’s, Arduinos, etc. Everything seems to be working fine. I have used mosquitto_pub and mosquitto_sub to publish and subscribe topics. All devices that are subscribed to my test topics work as expected.

Yesterday I installed the Openhab runtime following the instructions on I also installed the demo site. Again, everything seems to be working fine and so I proceeded to install and configure Openhab MQTT binding. I think I understand the MQTT configurations in openhab.cfg, they are pretty straightforward. Btw, I am forcing authentication to Mosquitto.

After installing Openhab MQTT binding and configuring it in openhab.cfg I loaded up some terminal windows to do some testing.

I can see that the Openhab client successfully connects to the REAL MQTT broker (Mosquitto):

1458438690 New connection from on port 1883.
1458438694: New client connected from as Central (c1, k60, u’HomeGenie’).

(I previously tried HomeGenie and so I am using that same username. I’ll change it later)

On startup of openhab, the MQTT client seems to initialize correctly:

20:58:31.300 [INFO ] [.io.transport.mqtt.MqttService:108 ] - MQTT Service initialization completed.
20:58:31.305 [INFO ] [o.i.t.m.i.MqttBrokerConnection:114 ] - Starting MQTT broker connection 'mosquitto’
20:58:31.323 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294 ] - Creating new client for ‘tcp://’ using id ‘Central’ and file store ‘/tmp/mosquitto’

Later in the startup log I see:

21:04:07.051 [DEBUG] [i.internal.GenericItemProvider:341 ] - Start processing binding configuration of Item ‘DeckPostLightColor (Type=StringItem, State=Uninitialized)’ with ‘MqttGenericBindingProvider’ reader.
21:04:07.089 [DEBUG] [b.mqtt.internal.MqttItemConfig:72 ] - Loaded MQTT config for item ‘DeckPostLightColor’ : 0 subscribers, 1 publishers
21:04:07.102 [DEBUG] [i.internal.GenericItemProvider:341 ] - Start processing binding configuration of Item ‘DeckPostLightSwitch (Type=SwitchItem, State=Uninitialized)’ with ‘MqttGenericBindingProvider’ reader.
21:04:07.148 [DEBUG] [b.mqtt.internal.MqttItemConfig:72 ] - Loaded MQTT config for item ‘DeckPostLightSwitch’ : 0 subscribers, 2 publishers
21:04:07.152 [DEBUG] [i.internal.GenericItemProvider:341 ] - Start processing binding configuration of Item ‘DeckPostLightAnimation (Type=NumberItem, State=Uninitialized)’ with ‘MqttGenericBindingProvider’ reader.
21:04:07.155 [DEBUG] [b.mqtt.internal.MqttItemConfig:72 ] - Loaded MQTT config for item ‘DeckPostLightAnimation’ : 0 subscribers, 1 publishers
21:04:07.231 [DEBUG] [m.internal.MqttEventBusBinding:68 ] - MQTT: Activating event bus binding.

When I go to the web ui on port 8080, I can see the RGB LED I’ve configured for testing. The controls look correct, I get the colorselector and make changes. Viewing the openhab.log in debug mode I can see these log entries:

20:56:20.609 [INFO ] [runtime.busevents :22 ] - DeckPostLight received command 114,50.98039215686274,100
20:56:22.508 [INFO ] [runtime.busevents :22 ] - DeckPostLight received command 37.92452830188679,41.568627450980394,100
20:56:23.554 [INFO ] [runtime.busevents :22 ] - DeckPostLight received command 350.90909090909093,38.8235294117647,100
20:56:25.922 [INFO ] [runtime.busevents :22 ] - DeckPostLight received command 268.2089552238806,52.549019607843135,100

If it helps, here is my item and rule configuration:

Group gDeckPostLight “Deck Post Lights” (gGF)
Color DeckPostLight “Deck Post Light Color” (gDeckPostLight)
String DeckPostLightColor (gDeckPostLight) {mqtt=">[mosquitto:HomeGenie/deckpostlight/color:command::default]"}
Switch DeckPostLightSwitch “W1” (gDeckPostLight) {mqtt=">[mosquitto:HomeGenie/deckpostlight/SW1:command:ON:100],>[mosquitto:/HomeGenie/deckpostlight/SW1:comman$
Number DeckPostLightAnimation “Deck Post Light Animation” (gDeckPostLight) {mqtt=">[mosquitto:HomeGenie/deckpostlight/animation:command:

var HSBType hsbvalue

var int redValue
var int greenValue
var int blueValue
var String RGBvalues

rule "Set RGB 2 value"
Item DeckPostLight changed
hsbvalue = DeckPostLight.state as HSBType

redValue =
greenValue =
blueValue =

RGBValues = redValue.toString + “;” + greenValue.toString + “;” + blueValue.toString
sendCommand( DeckPostLightColor, RGBValues )

logInfo( “DeckPostLightColor”, RGBValues)

Also, Openhab and Mosquitto are on the same IP address of and the Mosquitto ACL gives read and write access to all topics (#) for the HomeGenie user.

Can anyone please tell me how I might troubleshoot this problem?

I think the problem is in the mqtt configuration of the items. In my items the final parameter is not ‘default’ but ${command}

Number Temperature_296_set    "Office Temperature Target [%d °C]" <temperature> (FF_Office, Temperature_Chart) {mqtt=">[raspberryPi:/energenie/eTRV/Command/Temperature/296:command:*:${command}]"}

I haven’t tried your suggestion yet. I wish I knew how I could see the impact of using ‘default’ over ‘${command}’. Of course I can subscribe to ‘#’ and see MQTT activity, but in this case there is none. Adding DEBUG logging for MQTT in OpenHab doesn’t help much either.

Although, I found other issues in my code above. Probably the biggest revelation was that ‘/’ could/should be specified for MQTT topics. In almost all of the Arduino/ESP8266 sketches I’ve seen, the leading ‘/’ is omitted - but somehow this is important for OpenHab. Once I began configuring properly formatted topics I was able to see SW1 (in my example) work.

I am thinking that I should close this topic and create a new one with updated symptoms/code.

Thank you!

This is specified in the Outbound Binding section of the MQTT wiki page. The final parameter is the transform, which if it is text just sends the text. By this reasoning, using default would just send ‘default’, but since this isn’t happening, there must be something else wrong as well.

I don’t think the / at the beginning of the topic is necessary for OpenHAB. I have it here just because it was my first attempt at defining some structure and seemed the thing to do. I have some other sensors that don’t use it.

default has special meaning, namely, just pass the string version of the command as the MQTT message to publish. See the code here.


could you explain how you fixed your issues?

I have very similar problems right now.

My problem was that I configured the Item Message wrong. It works really well now!