MQTT 2.4: Switch with different topics for command on/off

Hi Everyone!
I am moving my mqtt to 2.4 and i am struggling with an item that is controlling a tuya socket with the great tuya-mqtt script.
The old item is like this:

Switch	 LivingRoom_Tuya1 			"Tuya1" <poweroutlet_eu> (LivingRoom, gLight)  {mqtt="<[syn:tuya/socket/1582xxx/9179xxx/myip/state:state:default:.*],>[syn:tuya/socket/1582xxx/9179xxx/myip/command/on:command:ON:true], >[syn:tuya/socket/1582xxx/9179xxx/myip/command/off:command:OFF:false]"}

With the new binding i don’t have probelms to see the state with the thing/channel concept, but i can’t find in the binding documentation how to manage different topics ( command/on & command/off) and payloads (true/false) for the command to the ON/OFF status.

I am at this point and i don’t know how to continue. Of course commandTopic is wrong but i don’t know how to manage!

Thing mqtt:topic:tuyasocket1 (mqtt:broker:synBroker) {
    Channels:
        Type switch : tuya1 "Tuya Socket 1" [ stateTopic="tuya/socket/1582xxx/9179xxx/myip/state", commandTopic="tuya/socket/1582xxx/9179xxx/myip/command/", on="on", off="off" ]
    }```

Somebody already solved this? Could you help me to find the proper documentation?

Thank you!

I’m on the phone so can’t get you the right link. Have a look for the openhab2-addons GitHub repository and find the mqtt.generic binding. The readme file in there is the newest not yet published documentation. It contains an example matching your case.

Cheers

Hi David, thanks for your answer.
I think you refer to https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.mqtt.generic/README.md
But there it’s the opposite : 2 states and 1 command :frowning:
I hope that with upgrading we don’t lose functionalities! Would be very bad to write rules for such a simple need!

Oh right. This is indeed not covered by mqtt2. But for a reason. The Mqtt topic layout of that script is broken.

There are accepted conventions on how to use Mqtt and one is to have a single state expressed as one topic. The script should be adopted to how Mqtt is supposed to be used or indeed a rule is necessary in openhab.

Alternatively two channels with a different command topic each linked to the same item will do it maybe? (The second channels item link would be set with a follow profile).

Sorry that I can’t help more here.

Cheers

Maybe i found a solution. It actually involves the modification of tuya-mqtt to be able to use only one command topic.
More details here:
https://community.openhab.org/t/solved-oh-2-4-mqtt-binding-generic-thing-statetopic-working-commandtopic-not-working/63619/17
I will test it and let you know!

If I recall, the tuya mqtt bridge code was changed and you should be able to use one topic only.
taken from:

Change device state (by payload)
Use with OpenHAB 2.X MQTT bindings or others where only a single command topic is preferred
    tuya/<tuyaAPI-type>/<tuyaAPI-id>/<tuyaAPI-key>/<tuyaAPI-ip>/command // State as Payload (on,off)