MQTT Setup and Configuration

Hi,
your topics and payload are wrong.
Have a look into Tasmota documentation.
E.g. Command should be something like “FietBulb01/cmnd/POWER” and payload should be “ON/OFF”. No need to enter these, as these are the default.
Joerg

He has changed the full topic so it would be FietBulb01/POWER

First Make sure tasmota is working correctly and that you can control the bulb as you wish using only tasmota,

Next is the MQTT

Use something like http://mqtt-explorer.com/ to watch what happens when you control the device

Next is to start looking at openHAB

The state and command topic will both be FietBulb01/POWER

Remove the custom on off commands

If you just make up values it will never work

rpwong & James:
Everything went well with the Tasmota reflash and I can control the bulb in Tasmota.

As you can see from the screenshots, the broker and thing are online, but they don’t communicate with the bulb. I’m curious about the POWER parameter. I realize that rpwong is using an outlet as an example. Would POWER also be used for a light bulb? This is where all the documentation I have read and watched eludes me. there just doesn’t seem to be a solid step-by-step example of how some of these parameters inter-relate.

Just so you know, I’m not a technology neophite. I started out as a main frame programmer in 1984. I got my electronics training in the Navy. The last new language I learned was while programming a system in dBase III/IV. The last program I wrote was in BASIC over 20 years ago. I prefer being a Network Engineer.

I try your suggestions and let you know what happens.

Thank you all!

Thank you, Joerg. I figured my configurations were wrong, I just didn’t know where. Documentation on MQTT is confusing, to say the least.

In addition to the excellent suggestions by @denominator and @rpwong, just double check: do you have another device which is trying to connect to your MQTT broker with the same Client name? This won’t work, as Mosquitto (usually) kicks off the older connection in favour of the newer device.

@Joerg_Schreiner has a point here. You changed your Tasmota Topic to FietBulb01. But the default command topic to turn it on or off is normally:

cmnd/FietBulb01/POWER

However, that will only work for you if you put your FullTopic back to the default as shown above the field in the Tasmota MQTT Parameters page (%prefix%/%topic%). I would suggest you put that back to default so that most of the online guides you read make sense!

I tried to write a guide for setting up a simple Tasmota device. It’s based around a Sonoff Basic, but your bulb should work in exactly the same way. Like @rpwong I use configuration files instead of the UI:

But as @denominator says: forget about openHAB for now and use MQTT Explorer to make sure all the MQTT stuff is working. Once that’s done, come back to configure it in openHAB.

This page is your Bible: Commands - Tasmota

Use the Tasmota console to try out commands (just type POWER ON and POWER OFF into the Tasmota console and watch what happens), then use MQTT Explorer to do the same over MQTT, then move to openHAB.

2 Likes

hafniumzinc:

“do you have another device which is trying to connect to your MQTT broker with the same Client name?”

This is the first and only device that I’m using with MQTT. That’s why I’m having so much trouble with it.

“However, that will only work for you if you put your FullTopic back to the default as shown above the field in the Tasmota MQTT Parameters page (%prefix%/%topic%). I would suggest you put that back to default so that most of the online guides you read make sense!”

This is where my understanding falls apart. Would the (%prefix%/%topic%) be cmnd/FietBulb01/POWER? I know the topic is supposed to connect everything, but I’m not seeing the consistency.

“forget about openHAB for now and use MQTT Explorer to make sure all the MQTT stuff is working”

I run Fedora Linux as my desktop. I have MQTT-Explorer installed, but I haven’t figured out how to run it. this whole process has been rather frustrating. I’ll take a look at your web page.

“Use the Tasmota console to try out commands (just type POWER ON and POWER OFF into the Tasmota console and watch what happens)”

Works great.

No, you literally type in

%prefix%/%topic%

into the FullTopic field, and save.

Once that’s done, on the right hand side of MQTT Explorer, type

cmnd/FietBulb01/POWER

Into the topic field. Underneath, switch to RAW, and type in ON or OFF. Then click Publish and see what happens…

hafniumzinc / rpwong:

Like you, I prefer to use config files. Here’s my MQTT.things file:

Bridge mqtt:broker:mqtt [ host="10.5.0.10", secure=false ]
{
    Thing mqtt:FietBulb01:Light_US_Master_Stand {
    Channels:
        Type switch : masterstandswitch "Master Stand" (Master) ["Lighting"] [ "stateTopic="FiteBulb01/state, commandTopic="FietBulb01/command", on="i-am-on", off="i-am-off" ]
        Type color : masterstandcolor "Master Stand Color" (Master) ["Lighting"] [ stateTopic="FietBulb01/color", commandTopic="FietBulb01/color/set", hsb=true ]
    }
}

I look at MQTT like a memory register that transmits messages from one system to another that is very forgetful.

In the tasmota console you will see messages sent to the broker.

My Ifan

Toggle of the light shows

So we are looking for what happens when we do the toggle

11:19:56 MQT: IFANdining/stat/POWER1 = OFF
11:23:55 MQT: IFANdining/stat/POWER1 = ON

This is a state that the Light.

I think your issue is you have the same state and command topics

use %prefix%/%topic%

as @hafniumzinc suggested

image

OK, there’s a few syntax and spelling errors in there.

I’m going to assume you’ve changed your FullTopic back to %prefix%/%topic%. Then the following Thing definition should work (POWER switch only - I’m not sure how the color stuff should be formatted, but let’s get the switch working first. I’ve also re-named the bridge to MosquittoMQTTBroker for readability):

Bridge mqtt:broker:MosquittoMQTTBroker [ host="10.5.0.10", secure=false ]
{
    Thing topic FietBulb01 {
        Channels:
            Type switch : masterstandswitch "Master Stand" [
                stateTopic="stat/FietBulb01/RESULT",
                commandTopic="cmnd/FietBulb01/POWER",
                on="ON",
                off="OFF"
            ]
    }
}

You can then create a Switch Item

Switch Masterstandswitch "Master stand" {channel="mqtt:topic:MosquittoMQTTBroker:FietBulb01:masterstandswitch"}

And a sitemap Item

Switch item=Masterstandswitch label="Master stand"

Hi hafniumzinc:

You may hate me for this… trying to set things up like you suggested ion your web help page, I reconfigured my config files and swparated the bridge, thing and item files. I’ll make the corrections you suggested and re-post them for you as soon as I get home from work.

Silly idea, but I would assume I should delete what I did in PaperUI so as not to confuse the system? After all, it doesn’t work, anyway. I get a thing under “Control” that APPEARS to operate, but nothing happens when I move the controls. Currently, because of all the errors in my config files, I’m not showing anything in PaperUI.

Thanks again.

OK, no problem - just change your Thing to (assuming your MQTT bridge is called MosquittoMqttBroker:

Thing mqtt:topic:FietBulb01 (mqtt:broker:MosquittoMqttBroker){
    Channels:
        Type switch : masterstandswitch "Master Stand" [
            stateTopic="stat/FietBulb01/RESULT",
            commandTopic="cmnd/FietBulb01/POWER",
            on="ON",
            off="OFF"
        ]
}

And your Item:

Switch Masterstandswitch "Master stand" {channel="mqtt:topic:FietBulb01:masterstandswitch"}

Yes, definitely!

Hi James (denominator),

I ran a test in the console of Tasmota as previously suggested. I entered POWER ON and POWER OFF and it worked perfectly, same as if I clicked on the toggle button. I also updated the full topic as hafniumzinc suggested. I’m hoping as I clean up my spelling and syntax errors things will start working.

Thanks again.

Excellent you will have it going in no time. Systems integration is the most frustrating type of programming.

Next is to get it working in MQTT explorer (or another client) as a window to see what is going on.

Eg
When you first open MQTTE it starts gathering the info it doesn’t remember anything it is not told while connected.
image

After turning kettle on and off
image

I can command the kettle to turn on like this

I always advise and practice to get it working this way before moving onto openHAB as this is one side of the puzzle sorted.

You can also add the Last Will Testament to config to show online status of thing

Bridge mqtt:broker:MosquittoMQTTBroker [ host="10.5.0.10", secure=false ]
{
    Thing topic FietBulb01 [ availabilityTopic ="tele/FietBulb01/LWT", payloadAvailable ="Online", payloadNotAvailable ="Offline"]{
        Channels:
            Type switch : masterstandswitch "Master Stand" [
                stateTopic="stat/FietBulb01/RESULT",
                commandTopic="cmnd/FietBulb01/POWER",
                on="ON",
                off="OFF"
            ]
    }
}
1 Like

I’ve never felt the need to do this. Where do you see the online status?

Paper UI

My Tasmotas show up as online in PaperUI even without LWT. Or do you mean that they’ll always show as “ONLINE” unless you add it?

They’ve always worked, so I never questioned it.

My only problem with MQTTE is that I can’t get it to run. I installed it through Snap, but it doesn’t come up in my software list, and I can’t find the cli command to run it. Sometimes Linux can be a little frustrating that way…

I guess you could unplug one an see if it goes offline after 30 sec

1 Like