MQTT V1 migration issue(s) :)

I’ve done a fresh install of OH3.2 and now trying to replicate some basic functionality I have working in a OH2.5 setup using MQTTV1.
I’m using Control Tasmota flashed devices via MQTT as a guide.

This is my 2.5 mqtt.items file entry which both controls the light on/off and can get its state both from the ‘stat’ and ‘tele’

Switch StudyLight "Study Light" <light> (LR,AllLights) ["Lighting"] 
	{mqtt=">[mosquitto:cmnd/STUDY_T1SON_85/POWER:command:*:default],
		<[mosquitto:stat/STUDY_T1SON_85/POWER:state:default],
		<[mosquitto:tele/STUDY_T1SON_85/STATE:state:JSONPATH($.POWER)]"}

and these are the OH3.2 files mqtt.things:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
        host="192.168.1.39",
        secure=false,
        port=1883,
        clientID="OpenHAB2",
        username="",
        password=""
]

Thing mqtt:topic:swStudyLight "Switch Study Light" (mqtt:broker:MosquittoMqttBroker) {
        Channels:
                Type switch : power "Power Switch" [
                        commandTopic="cmnd/STUDY_T1SON_85/POWER",
                        stateTopic="stat/STUDY_T1SON_85/POWER",
                        on="ON",
                        off="OFF"
                ]
}

and items file

Switch StudyLight "Study Light Item" { channel="mqtt:topic:swStudyLight:power" }

I’m able to turn the light on and off (via a simple sitemap) but I’m not picking up changes in state. I confirmed this by looking at events.log.

Questions

  1. What stupid thing am I missing to cause the stateTopic bit not to work?
  2. Do I just include stateTopic="tele/STUDY_T1SON_85/STATE:state:JSONPATH($.POWER)", to capture state via the ‘tele’ mqtt messages?

No. Have you looked at binding docs? The channel has a transformationPattern= parameter for incoming messages.

Don’t forget JSONPATH is an optional add-on that needs to be installed as well.

Thanks for the prompt response. I’ll go through both those articles.
Any idea on Q1? or suggestions on diagnosing

Well if the JSONPATH is not active, and I presume the incoming MQTT message payload here is JSON, then a complete message text in JSON format is not going to fit the ON or OFF states required by a Switch type Item.

You can always make another temporary channel of type string with similar parameters, and link it to a String type Item to see what is received.

Hey @Ianc99 Welcome to the joys of out of date information.

It can be super frustrating because many people can change a little thing and can be difficult to diagnose. I have trust issues with data and want to see exactly what is going on and roughly follow a tutorial.

Is the version of tasmota you installed the same as the one for the tutorial?

Educated Guess change state to

stateTopic="stat/STUDY_T1SON_85/POWER1",

download http://mqtt-explorer.com/ it will greatly help you to see the messages being sent from client

You don’t need JSON transformation for power1 on off

James,
I’m with you on the trust issues which is why I was already snooping on the actual MQTT messages. It’s deffo just POWER and also the OH2.5 server with the mqtt.items file is still working (I’m using it to toggle the light on and off to test the new server)

This “old” Server is running a mqtt broker as well?

Regarding the need for a JSONPATH transformation, take a look onto theconsole of your tasmota device. You will when a message containing the state I sent ( tele or stat) and which of both does need a transformation.

How very dare you!! :slight_smile:

@Ianc99 have you restarted openHAB 3 at any point? Sometimes changes to Things files don’t take effect properly. Or I do this.

Also, probably change this if it’s the same as in OH2.5 - you’ll confuse Mosquitto with the same client IDs…

1 Like

I have OH3.1 working with MQTT/Tasmota. Maybe this will help.

In my .things file

Bridge mqtt:broker:MqttBroker [ 
       host="192.168.0.5", 
       port="1883", 
       secure=false,
       username="MqttUserid", password="********",
       clientID="OpenHab"]

Thing topic ChristmasTreeThingId "ChristmasTree" {
    Channels:
        Type switch : power        "Power"         [stateTopic="ChristmasTree/stat/POWER", commandTopic="ChristmasTree/cmnd/POWER"]
        Type string : sleepmode    "Sleep Mode"    [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.SleepMode"]
        Type number : sleep        "sleep"         [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Sleep"]
        Type number : loadavg      "Load Average"  [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.LoadAvg"]
        Type number : wifiap       "WiFi"          [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.AP"]
        Type string : wifissid     "SSID"          [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.SSId"]
        Type string : wifibssid    "BSSID"         [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.BSSId"]
        Type number : wifichannel  "Channel"       [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.Channel"]
        Type number : wifirssi     "RSSI"          [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

.items file:

Switch ChristmasTree            "ChristmasTree [%s]"               {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:power"}
String ChristmasTreeSleepMode   "ChristmasTree Sleep Mode [%s]"    {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:sleepmode"}
Number ChristmasTreeSleep       "ChristmasTree Sleep [%d]"         {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:sleep"}
Number ChristmasTreeLoadAvg     "ChristmasTree Load Average [%d]"  {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:loadavg"}
Number ChristmasTreeWifiAP      "ChristmasTree AP [%d]"            {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifiap"}
String ChristmasTreeWifiSSID    "ChristmasTree SSID [%s]"          {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifissid"}
String ChristmasTreeWifiBSSID   "ChristmasTree BSSID [%s]"         {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifibssid"}
Number ChristmasTreeWifiChannel "ChristmasTree Channel [%d]"       {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifichannel"}
Number ChristmasTreeWifiRssi    "ChristmasTree RSSI [%d]"          {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifirssi"}

.sitemap

Switch item=ChristmasTree      label="Christmas Tree [%s]"

HTH

Jim

What MQTT broker are you using and is it all on the same broker?

Some Example thing’s I use with TASMOTA

Bridge mqtt:broker:myMQTTBroker [ host ="192.168.1.148", secure =false, username ="user", password ="pass" , clientID ="openHAB3" ]
{
 
    Thing topic fan1 "Dining FAN" [ availabilityTopic="IFANdining/tele/LWT", payloadAvailable="Online", payloadNotAvailable="Offline"] {
    Channels:
        Type switch : Power1   "Dining Light "  [ stateTopic = "IFANdining/stat/POWER1", commandTopic = "IFANdining/cmnd/POWER", on="ON", off="OFF" ]
        Type dimmer : fanspeed "Fan Speed"      [ stateTopic = "IFANdining/stat/FANSPEED", transformationPattern = "JSONPATH:$.FanSpeed", commandTopic ="IFANdining/cmnd/FANSPEED", 0="OFF", 1="LOW", 2="MED", 3="HIGH", 2=100  ]
      }

    Thing topic Kitchen_Bench_Light "Bench Light" @ "Kitchen" {
    Channels:
        Type dimmer : dimmer  [ stateTopic ="Kitchen_Bench_Light/stat/DIMMER", transformationPattern ="JSONPATH:$.Dimmer", commandTopic ="Kitchen_Bench_Light/cmnd/Dimmer" ]
      }
}

A combination of reboot of OH3 plus changing clientID=“OpenHAB3” has gotten the stateTopic="stat/STUDY_T1SON_85/POWER" reading the state changes

Thanks All.

Also a lesson for me - Ask one question per post :slight_smile:

1 Like

Now a revised Question 2 :slight_smile:

I now have the commandTopic working and also the first stateTopic (reading “stat/STUDY…”) below. I still need to capture the “tele/STUDY…” stateTopic.

Switch StudyLight "Study Light" <light> (LR,AllLights) ["Lighting"] 
	{mqtt=">[mosquitto:cmnd/STUDY_T1SON_85/POWER:command:*:default],
		<[mosquitto:stat/STUDY_T1SON_85/POWER:state:default],
		<[mosquitto:tele/STUDY_T1SON_85/STATE:state:JSONPATH($.POWER)]"}

I understand I need to use transformationPattern for this but can I do it byadding a second stateTopic line to the channel or do I create another channel for the Thing?

If I need a second channel, do I just put the two channels in the item something like this?

Switch StudyLight "Study Light Item" { channel="mqtt:topic:swStudyLight:power", 
                                       channel="mqtt:topic:swStudyLight:tele_power" }

Yes

Yes!

See last section in this post for example:

Yea! I’m on a Roll.

Thanks

1 Like

You really only need one state you can use the tele one in you thing and it will be commanded with every tele update if thats what you want.

                Type switch : power "Power Switch" [
                        commandTopic="cmnd/STUDY_T1SON_85/POWER",
                        stateTopic="tele/STUDY_T1SON_85/POWER",
                        transformationPattern ="JSONPATH:$.POWER",
                        on="ON",
                        off="OFF"

What topics you’ll choose to listen to might depend on when they are sent. Usually for Tasmota, one is a response to commands and the other a periodic report. There’s no cost in having a receive channel for both, each linked to one Item.

@rossko57 Monitoring the “tele” and “stat” does have overlap but they address different scenarios for my setup. “stat” give immediate feedback when a device turns on or off. “tele” deals with those times when OB may have missed a stat msg (usually because its temorarily offline).
I have the telemetry interval set to 30 seconds on all my Tasmota devices so my OH states always reflect reality within about a minute of reboots etc.

Does that sound like a reasonable approach or am I missing a more straightforward approach?

The only issue may be when you are using rules attached to an item that it commanded trough the tele thing if that makes sense.

That way your item may receive a command every 30 seconds.

I guess it depends on your use case and how you use each item. As my openHAB is rarely down I just use the stat topic.

You could use a rule to send an empty message to TASMOTA to ask it for the state of the device.

If I understand correctly, I think I’ve addressed that issue by not having a commandTopic in the tele channel of the Thing

Thing mqtt:topic:swStudyLight "Switch Study Light" (mqtt:broker:MosquittoMqttBroker) {
	Channels:
		Type switch : power "Power Switch" [ 
			commandTopic="cmnd/STUDY_T1SON_85/POWER", 
			stateTopic="stat/STUDY_T1SON_85/POWER",
			on="ON",
			off="OFF"
		]
		Type switch : state_power "State Power" [
			stateTopic="tele/STUDY_T1SON_85/STATE",
			transformationPattern="JSONPATH:$.POWER"
		]
}
1 Like