[SOLVED] Mqtt Command

i have a Button with two States


Thing mqtt:topic:esp32Enten {
        Type string : torEnten "Taste Tor Enten" [stateTopic="Esp32/Aussen/Enten/ActData/StateTor", commandTopic="Esp32/Aussen/Enten/SetDatas/Tor", 0="1", 1="2"]


String ENTENBE                                                  {channel="mqtt:topic:esp32Enten:torEnten"}


Switch item=ENTENBE icon="" label="Tor" mappings=[0=Auf, 1=Zu]

now i want to write “0” when i pressed “Auf” and “1” when i pressed “Zu”
but when i pressed “Auf” writes “0” and “Zu” 1 (exactly the mapping)

can someone help me?


The question is confusing.

So it works?

Sorry, i mean:
i want to write 1 when i pressed “Auf” and 2 when i pressed “Zu”

i try it with this command commandTopic=“Esp32/Aussen/Enten/SetDatas/Tor”, 0=“1”, 1=“2”]
but this is not work


Reading this, I think outbound transformations are not yet working (@David_Graeff am I correct?)
So if that is the cause, you need to have a proxy item and a rule.

Because that’s a made up syntax ^^. If you have a switch channel instead of a string channel, you can use ON=“2” OFF=“1”. A string channel does not support that shortcut.

They do in OH 2.5M1+

And that is exactly the solution here. You need to apply the MAP transformation not on the sitemap level of abstraction but way earlier at the channels level. But to be honest I forgot the command although I have written this binding. I don’t use text files :smiley:

1 Like

Typ switch not work.
how can i make a rule by proxyitem?

this dosn`t work

rule "EntenStall öffnen schliessen"
     Item ENTENBE received command
        if (receivedCommand==1) { // Auf
            publish("myBroker", "Esp32/Aussen/Enten/SetDatas/Tor", "1") // sends MQTT command
        else {
            publish("myBroker", "Esp32/Aussen/Enten/SetDatas/Tor", "2") // sends MQTT command

It really helps if you say what that means, and maybe report relevant messages from openhab.log or events.log
What does it do that you didn’t expect?
What doesn’t it do that you did expect?

But you defined ENTENBE as a String type. Command “1” is not the same as number 1

what means?

Log File

The name 'publish' cannot be resolved to an item or type


You haven’t installed the MQTT Action. However, the MQTT Action only works with the MQTT 1 binding. You appear to be using the MQTT 2 binding. As documented here the MQTT 2 actions are accessed and used differently.

thats exactly what im looking for.