MQTT: what am I missing?

Hi all,

I’m diving into MQTT, and thought I had it figured out pretty well after a lot reading, but I can’t figure out what I’m missing. My device is a Tasmota-flashed power strip with four controllable outlets and USB on/off. I can control it directly over WiFi from a browser, and MQTT is enabled.

I installed Mosquitto (no user/password), added the MQTT binding in PaperUI, and then set up my things and items. For the host, I’m pointing to my RPi’s IP address.

Bridge mqtt:broker:mosquitto "Mosquitto MQTT Broker" [ host="192.168.1.101", port=1883, secure=false, clientID="OpenHAB2" ]
{
    Thing topic tasmotapsb "Tasmota Power Strip (Black)" {
    Channels:
        Type switch : power1 "Outlet 1" [ stateTopic="stat/tasmotapsb/POWER1", commandTopic="cmnd/tasmotapsb/POWER1" ]
        Type switch : power2 "Outlet 2" [ stateTopic="stat/tasmotapsb/POWER2", commandTopic="cmnd/tasmotapsb/POWER2" ]
        Type switch : power3 "Outlet 3" [ stateTopic="stat/tasmotapsb/POWER3", commandTopic="cmnd/tasmotapsb/POWER3" ]
        Type switch : power4 "Outlet 4" [ stateTopic="stat/tasmotapsb/POWER4", commandTopic="cmnd/tasmotapsb/POWER4" ]
        Type switch : power5 "USB" [ stateTopic="stat/tasmotapsb/POWER5", commandTopic="cmnd/tasmotapsb/POWER5" ]
    }
}

This gives me the following log entries:

[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'
[INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '192.168.1.101' with clientid OpenHAB2
    ==> /var/log/openhab2/events.log <==
[hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from UNINITIALIZED to INITIALIZING
[hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from INITIALIZING to OFFLINE
[hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:tasmotapsb' changed from UNINITIALIZED to INITIALIZING
[hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:tasmotapsb' changed from INITIALIZING to ONLINE

Despite going to an OFFLINE status, the broker shows up in PaperUI as ONLINE. This makes me think that I’ve done something wrong in configuring the broker.

I can link items to my things and send commands, but I suspect that nothing is getting published to my Tasmota device.

I’m hoping it’s something really simple that I’m too tired to see.

Thanks in advance!

Most people find a tool like mqtt.fx useful, to allow you to talk directly to your broker. You can see which side of the fence problems fall on.

this is mine, i thing you’re missing on/off at the end

[stateTopic="stat/lilylamp/POWER", commandTopic="cmnd/lilylamp/POWER", on="ON", off="OFF"]

No, you should not need on=“ON”, off=“OFF” as this is default behavior.

@rpwong What are the Items like?

@rpwong here is what I have for Things and items that work.

Things:

Bridge mqtt:broker:pibroker "pibroker" [ host="10.0.1.10", port=1883, secure=false, username="xxxxxxxx", password="xxxxxxxx" ]
{
     Sonoffs
    Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

    Thing topic sonoff2 "Couch Light" @ "Couch Light" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
    }

    Thing topic sonoff55 "Office Light" @ "Office" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff55/POWER", commandTopic="cmnd/sonoff55/POWER" ]
   }
}

Items:

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

Switch CouchLight "Couch Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff2:power" }

Switch OfficeLight "Office Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff55:power", expire="180m,command=OFF" }

Hope this example helps.

Darn, I was hoping it would be something like, “you capitalized a T that should be lowercase”. :wink:

@H102, I referred to your posts a lot to get sorted out.

Here are my items, but I note that toggling the channels in PaperUI also does nothing, so I don’t think the problem is here.

Switch TasmotaPSB_1 "TPS Outlet 1" <switch> { channel="mqtt:topic:mosquitto:tasmotapsb:power1" }
Switch TasmotaPSB_2 "TPS Outlet 2" <switch> { channel="mqtt:topic:mosquitto:tasmotapsb:power2" }
Switch TasmotaPSB_3 "TPS Outlet 3" <switch> { channel="mqtt:topic:mosquitto:tasmotapsb:power3" }
Switch TasmotaPSB_4 "TPS Outlet 4" <switch> { channel="mqtt:topic:mosquitto:tasmotapsb:power4" }
Switch TasmotaPSB_USB "TPS USB" <switch> { channel="mqtt:topic:mosquitto:tasmotapsb:power5" }

I installed mqtt.fx and can publish/subscribe without issue, so my suspicion is that Tasmota isn’t communicating with the broker, even though it’s definitely connected to my WiFi. I added a user/password to Mosquitto and the Tasmota to make sure that wasn’t an issue, but it’s still not publishing or subscribing.

I’m starting to wonder if this is a firmware problem with the Tasmota. Maybe I should try downgrading or flashing Espurna? I could also try the embedded MQTT broker, but I can’t see Mosquitto being the problem since mqtt.fx can connect to it.

That broker is no longer supported and mosquitto is the recommended broker.

Can you control any device by sending a command with mqtt.fx to verify the device is working?

You need to dig into this further. Obviously it’s not going to work if openHAB can’t establish communication with the broker.

I tried removing the mqtt.things file and then adding it back, and got the same log result:

[hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from UNINITIALIZED to INITIALIZING
[hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from INITIALIZING to OFFLINE
[hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:tasmotapsb' changed from UNINITIALIZED to INITIALIZING
[hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:tasmotapsb' changed from INITIALIZING to ONLINE

That’s why I was thinking of trying out the embedded broker…just to see if it would behave differently from Mosquitto.

In mqtt.fx I published ON and OFF commands to cmnd/tasmotapsb/POWER1. I can see them come back to me in the subscription, but that doesn’t trigger the device and I don’t see any commands being received in the Tasmota console. I’m not sure if I’m doing that right.

I tried triggering the POWER1 item on my sitemap and the command showed up in mqtt.fx. So, it leads me back to thinking that everything is fine with Mosquitto and OH, but the Tasmota device is not publishing or subscribing to the Mosquitto broker.

1 Like

There’s probably another log later for ONLINE

Looking at post 1, you don’t seem to have set MQTT Host

1 Like

We have a winner! And as I predicted, it was something stupidly simple. I can’t believe how many times I looked at that without thinking, “you need to add the host IP”. And yet, I did think “how does the Tasmota know how to find the broker?”

Thanks @rossko57 and everyone else for your help. Now on to the the fun part of playing with the new toy…

1 Like

Thats why I love the community… Often you cant see your own mistakes/typos etc, (I have been there so many times) but showing others they see things differently, and often spot it really fast.

1 Like