[SOLVED] MQTT - Testing new Binding - postCommand, config-trouble

i started testing the new mqtt binding in 2.4. And run into several ‘problems’ or things i don’t understand.

i have mosquitto with letsencrypt certificate running; and didn’t manage to connect succesfully to it. When i switched to non-encrypted communication messages started showing up.

Here’s my test-setting:
file: mqtt-broker.things (as i did read that there is an error when having all things in one file and you need to restart always OH - is this still correct?)

Bridge mqtt:broker:mySecureBroker [ host="...", secure=false, username="openhab2", password="....." ]

file: mqtt.things
Thing topic mything (mqtt:broker:mySecureBroker) {
Type switch : mq_lampe “Kitchen Lamp” [ stateTopic=“lamp/enabled”, commandTopic=“lamp/enabled/set”, postCommand=“lamp/enabled/command” ]

Which leeds to the first “error” in the logs:
[del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘mqtt.things’, using it anyway:
Provide a thing UID in this format:

i did bind this to a KNX-Item

Switch K_WANDLEUCHTEN "Wandleuchten Küche" <light>  [ "Switchable" ]

So when switching this with KNX the state was published to MQTT as
0 or 1
but PostCommand did not seems to do anything. So switching out of MQTT does not seem to work.

i also tried to raise Log-Level - but didn’t mange with this - but i needed to guess:
log:set DEBUG org.openhab.binding.mqtt

i also set this rule - like in the examples:
file mqtt.rules
rule “Publish all”
Member of Kueche changed
val actions = getActions(“mqtt”,“mqtt:broker:mySecureBroker”)

Which result always in actions been NULL
[ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Publish all': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.binding.mqtt.action.MQTTActions.publishMQTT(org.eclipse.smarthome.core.thing.binding.ThingActions,java.lang.String,java.lang.String) on instance: null

So - here are my questions: How do i raise Debug-Level?
Why a command from MQTT did not change anything on the Item - a lamp/enabled/command ON should work from my understanding of the Documentation? Do i need to restart OH everytime i change something from the config in regards to MQTT?

I may be wrong but I think a restart is needed only when you make a change to the Things file.

In the items file channel try adding the broker name like below (at least for the lamp, not sure about knx).

Switch K_WANDLEUCHTEN "Wandleuchten Küche" <light>  [ "Switchable" ]

No because a state change does not send a command to the binding.
There is no such thing as postCommand

As above

YEs is you are using 2.4. Upgrade to 2.5M1 or use the paperUI to configure things and channels. I recommend the second option. Why make your life complicated when you have a simple interface helping you set-up your things and channels without errors? (As you did)

Takes strings as arguments, therefore:

actions.publishMQTT(“allItems/”+triggeringItem.name, triggeringItem.state.toString)

The .toString was good; The Docu should add this - otherwise everyone else is running in the same trap.

ok, maybe i missread the documentation then:

* **postCommand** : If the received MQTT value should not only update the state of linked items, but command them, enable this option. You usually need this enabled if your item is also linked to another channel, say a KNX actor, and you want a received MQTT payload to command that KNX actor.

Hm. “postCommand” can be “true” or “false”. Might not be clear from the docu.

Ok, this postCommand
Use is tike this:


A state update from MQTT on the stateTopic will send a command to the KNX binding
BUT a state update from KNX will not send a command on the MQTT binding. I know of no ways to achieve this expect proxy items and rules.

I have fixed the documentation:

Btw: It’s super easy to do that. The edit link is at the bottom.

Cheers, David


ok - many thanks; Just to keep everyone in the loop here - now the working config:

Thing topic mything (mqtt:broker:mySecureBroker) {
     Type switch : mq_lampe "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set", postCommand="true" ]

a command on the broker on
lamp/enabled 1
switches the knx device as well.

the .toString did the trick in the rules

rule "Publish all"
      Member of Kueche changed
   val actions = getActions("mqtt","mqtt:broker:mySecureBroker")

I did use OH since 1.x times and some bad experiences with the early versions of migration of the userdata-dir; This and the problem of complex KNX config is the reason i still use .things-files. It tended to be more version-stable than adding things with the gui.

My question on howto raise Log-Level is still open btw.

That wasn’t it -
i guess it is than log:set DEBUG org.openhab.binding.mqtt.generic

But this doesn’t do anything to the logs as well … So?

I usually don’t add much to the log in my bindings. If I do log, it is usually warnings.

The reason is that if you use the REST interface for manipulating your things and items, your configuration will always be correct and you have a visual confirmation that an item is really linked etc. So I can avoid all the wrong configuration logging already.

And then there is not much to log, if you stick to the mantra of not logging in hot code paths (like the MQTT receive part).

But as soon as we have the “additional binding screens” feature that I started in the development section of this forum, I will add an MQTT binding page that outputs all subscribed topics and their mappings to channels for easier debugging.

Agreed. Good to know. Even so - sometimes when handling with the config - the way i do it - more info would me nice. (As i said - i did have mqtt running with a letsencrypt certificate and did not see anything other then “online”.)

Could you mark the thread as solved, thanks


Good morning Sir, I’ve been following your case understanding my personal usage application
Only, I don’t fully understand the Rule application
As I don’t see any group nor members known definitions, can you better explain why and how do you use it?