MQTT Item not working

Hello everyone!

I recently installed mosquitto, zigbee2mqtt und linked them via MQTT Binding in Openhab.

I paired a Xiaomi wall switch and tested all that with MQTT.fx
I get messages like {“battery”:100,“voltage”:3175,“linkquality”:57,“click”:“right”}
So I think this part works.

What I also managed to do is to publish MQTT Messages via rules:
val mqttActions = getActions(“mqtt”,“mqtt:broker:mqttbroker”)
mqttActions.publishMQTT(“mytopic”,“myvalue”, true)

This also arrives in MQTT.fx

Now here’s my problem:
I cannot get it to work that Openhab receives messages from the broker

Item is defined as
String Aqara1_CLICK “Aqara1 [%s]” {mqtt="<[mqtt:broker:mqttbroker:zigbee2mqtt/Aqara1:command:JS(getZigbeeClick.js)]"}

I must say that I’m totally new to Openhab, ZigBee and MQTT and everything I did so far was copy/paste from websites/youtube so please excuse stupid mistakes :wink:

Any help is appreciated

Greeting from germany,

1 Like

You are using the syntax for the mqtt binding version1!! This one doesn’t know anything about things and their channels!

In order to link a mqtt thing to an item the syntax like {channel="..."} has to be used. The needed syntax for the channel can be copied from PaperUI (it does NOT matter if the thing was created by file or by PaperUI, the correct syntax will be displayed!).


Thx for the hint!
But I’m totally lost with this. I haven’t defined these Things, Channels and Items yet. Could you help me, how to start?

What about the outdated habit of reading the docs?


Yet another way to say RTFM :rofl: :rofl: :rofl:

1 Like

I have to admit that the idea was not mine!

1 Like

I just googled the word “docs”. I also used a dictionary. Can’t find anything.
But I will keep searching…


You are viewing this with a web browser that uses links. Click the link in that post. :imp:

So, I added a thing:

Bridge mqtt:broker:myUnsecureBroker [ host=“”, secure=false ]
Thing mqtt:topic:mything {
Type string : Aqara “Aqara” [ stateTopic=“Aqara1/state”, commandTopic=“Aqara1/command” ]

and an item:

String Aqura “Aqara Switch” {channel=“mqtt:mybroker:topic:mything:Aqara” }

Still no transport to OpenHab. What am I doing wrong?

The Thing is myUnsecureBroker but the Item channel references mybroker, a different Thing.

You might want to study openHAB concepts.

Why? Somewhere, somehow, you had already created a broker Bridge thing, and it worked. Here it is in use by you -

So now you’ve got two Bridge Things squabbling over connection to the same broker. Get rid of one.
You’ll want to add a topic Thing to your existing, working, broker Bridge.

1 Like

Thx for that. Changed the channel to mqtt:topic:mything:Aqara
(That’s the channel I defined in my brindge (see above))

Also I noticed that the topics were wrong and changed them to zigbee2mqtt/Aqara1

Now there is a transport to OpenHab which I can see in the logs:
[vent.ItemStateChangedEvent] - mqtt_topic_mything_Aqara changed from {“battery”:100,“voltage”:3165,“linkquality”:65,“click”:“right”} to {“battery”:100,“voltage”:3165,“linkquality”:57,“click”:“left”}

[vent.ItemStateChangedEvent] - Aqura_Switch changed from {“battery”:100,“voltage”:3165,“linkquality”:65,“click”:“right”} to {“battery”:100,“voltage”:3165,“linkquality”:57,“click”:“left”}

Got rid of one :wink:

Isn’t that what I did (see above) with: Thing mqtt:topic:mything {

So now I have some follow up problems:

Problem 1: The output needs to be transformed. So I tried to insert the script via Paper UI into the fields “Incoming Value Transformations” (it has to be JS(getZigbeeClick.js)). But when I click save it say “Error 409 Conflict”

Problem 2: I inserted the follwing rule
rule “Aqara Reaction”
Item Aqara_Switch changed
logInfo(“Test”, “Aqara was pressed”)

But the rule does not trigger. But you can see that the item Aqara_Switch is changed in the logs (see above)

Problem 3: I googled the above Error (409 Conflict) and the solution seemed to be to clear the cache of Openhab. I did that with
openhab-cli stop
openhab-cli clean-cache
openhab-cli start

Since I did that Openhab does not start automatically when I reboot the system.

(I know these are all beginners problems eventually discussed before. I DO read the docs, but it’s really complicated when you start from scratch with OpenHab. I hope for you patience…)

If you created that thing in a file PaperUi can’t change it!

That’s a fact I did not know so far.
The next question is: What is the syntax for adding an incoming value transformation when I want to do this in the text files?

Is this really a switch?

The physical device is a Aquara Wall switch. Transferred is a String, so the item is defined as:
String Aqura_Switch “Aqara Switch” {channel=“mqtt:topic:mything:Aqara” }

I’d have to search the forum and docs as well…

I believe there’s a typo:
The rule checks for Aqara_Switch, but the item itself is:

[vent.ItemStateChangedEvent] - Aqura_Switch changed from ...

And for the transformation it seems to be JSON formatted, so you would not need a JS transformation
So the payload is:


If you want to access the battery value, just create an incoming transformation:

1 Like

Yes, was a typo :man_facepalming:

I changed the channel definition to
Type string : Aqara “Aqara” [ stateTopic=“zigbee2mqtt/Aqara1”, transformationPattern=“JSONPATH:$.click” ]

But the log still says:
[vent.ItemStateChangedEvent] - mqtt_topic_mything_Aqara changed from {“battery”:100,“voltage”:3165,“linkquality”:68,“click”:“left”} to {“battery”:100,“voltage”:3165,“linkquality”:73,“click”:“right”}
[vent.ItemStateChangedEvent] - Aqara_Switch changed from {“battery”:100,“voltage”:3165,“linkquality”:68,“click”:“left”} to {“battery”:100,“voltage”:3165,“linkquality”:73,“click”:“right”}

Still learning how to read the docs and use the concepts.
The parameter to be passed seems to be: transformationPattern