[SOLVED] MQTT 2.4 Channel Switch does not work

Hi! I am new to MQTT and I setup my stuff in Openhab 2.4 all by files, without PaperUI.
What I have done is:


Bridge mqtt:broker:myLocalBroker "MQTT Openhabbridge"

    Thing topic GenericMQTTtopic{
            Type switch : Test_Switch_MQTT  "Test Switch MQTT Channel" [ stateTopic="testswitch/state", commandTopic="testswitch/command", on="ON", off="OFF" ]


Switch TestSwitchMQTT "Test switch mqtt switch" {channel="mqtt:topic:myLocalBroker:GenericMQTTtopic:Test_Switch_MQTT"}

My understanding was hat I can publish a message for example from my Ubuntu now like:

mosquitto_pub -h -t testswitch/command -m “ON”

But the switch doesnt change the status. I am sure my Broker is running correctly, because I am publishing my temperatures in a rule wich works fine. Also my PaperUI shows that the Broker is online an the channel is linked.

I am running a Ubuntu 18 with Mosquitto, on this machine is also running my openHAB.


I am sure its a newbi failure, but I would apreciate if someone can help me :slight_smile:

When you action the switch, in an UI for example, the command topic will be used to send the payload.
To change the state of the swith with an mqtt message from outside openHAB, use the state topic

Thank you very much for your answer.

mosquitto_pub -h -t testswitch/state -m "ON"

doesnt work :frowning:

Set up a subscriber to check that the message is sent

I get a response:

The subscriber is my local running mosquitto

*the temp was published by a rule from openHAB

Can you post the item publishing the temperature, please


Number:Temperature WandthermostatWohnzimmer2ACTUALTEMPERATURE "Actual temperature" {channel="homematic:HM-TC-IT-WM-W-EU:OEQ1009821:OEQ1569091:2#ACTUAL_TEMPERATURE"}


rule "sendthermo"
    when Time cron "0 0/1 * * * ?" //cron every minute
        var Number tempTemperature = (WandthermostatWohnzimmer2ACTUALTEMPERATURE.state as QuantityType<Number>).doubleValue
        val actions = getActions("mqtt","mqtt:broker:myLocalBroker")
        actions.publishMQTT("temp/wt1", tempTemperature.toString)

What kind of switch is this? Can you manualy switch it and check what messages (state?) are send by subscribing to all messages ( with #)?

1 Like

when I subscribe # in my python script and manually switch in Paper UI I recieve this messages:
So it seems that the channel works, but I am doing just something wrong with publishing?

Try making another new String type channel without the on/off stuff, link it to a new test String type Item, to capture the raw payload.

1 Like

Hi rossko57,
I had no idea to try that, because it was a example but your suggestion solved my problem! Thank you very much.

It’s just a diagnostic move to see what OH is actually “seeing”. Did you get your Switch working?