[SOLVED] MQTT 2 Binding - Switch - Listen to two topics

  • Platform information:
    • Hardware: Raspberry Pi 3B+
    • openHAB version: 2.4

Hi! I am using OH 2.4 with the MQTT binding for 2.x and I am currently setting up a Snips voice assistant.
Now I want to create a Thing (“Snips”) with two Channels (“Snips intent” and “Snips listening”); the latter one should be a Switch that turns on when Snips is listening and turns off when it is done.

Snips is broadcasting its state via MQTT; when it begins to listen it broadcasts a message with a dynamic payload (a session ID) to the topic hermes/asr/startListening and when its done its broadcasting to hermes/asr/stopListening.

How can I configure the Channel so that it will listen to these two topics? I have set up other Channels for other things, but those always listened to one topic in which the state of the switch was broadcasted in the message; since it is not doing this here I dont know how to do it; I found information on this for the MQTT1.x binding, but none on the new one.

If anyone has a good idea I’d be really glad.

There is no way to define two topics to receive.

However, if there are not more topics on that level, you could use a wildcard, see https://www.openhab.org/addons/bindings/mqtt.generic/#common-channel-configuration-parameters for details.

Another option would be, to define an additional channel for the second topic, then link both channels to one item.

Thank you for your answer; I found a solution.

I am using two seperate channels now, one for turning the switch on and one for off.
The first channel is listening to the startListening topic and with a javascript-transformation I am changing the dynamic content of the message to a simple “1”, so the channel can change the state of the switch.

Maybe someone will find it useful.