Mosquitto broker / MQTT Gosund Smart Plug won't react to ON/OFF

You need

$.StatusSNS.ENERGY.Voltage

To expand on that, here’s your JSON string formatted a bit more nicely:

{
   "StatusSNS":{
      "Time":"2021-04-12T18:35:00",
      "ENERGY":{
         "TotalStartTime":"2021-04-10T20:30:28",
         "Total":0.060,
         "Yesterday":0.000,
         "Today":0.060,
         "Power":0,
         "ApparentPower":0,
         "ReactivePower":0,
         "Factor":0.00,
         "Voltage":0,
         "Current":0.000
      }
   }
}

You can see you have two levels before you get to Voltage:

  1. StatusSNS
  2. ENERGY

So Voltage is contained within ENERGY, and ENERGY is contained within StatusSNS.

2 Likes

Now it makes sense.
Thank you for that!

the item getting refreshed now.

One last question.
is there any advantage when its programmed like:

Number S1_Voltage "Spannung: [%.0f V]"                    { channel="mqtt:topic:Steckdose_01:ch1Voltage" }

I only see negatives, cause the channel is randomly getting updated.
Of course I am getting the values but only randomly :open_mouth:
Or am I wrong?

I would prefer to change my .things to something like this now:

Type number : Power2      						  [ stateTopic="stat/Steckdose_01/STATUS8", transformationPattern="JSONPATH:$.StatusSNS.ENERGY.Voltage"]

So I get the status “fast” matching to my defined rule of course.
Is there any disadvantage to this method?

Thank you for your time

You’ve invented “read polling”, which generates twice as much network traffic (request + response).
It’s better to set up the Tasmota to autonomously report periodically and/or when things change, when possible. Then openHAB only has to listen.

You can have multiple MQTT channels listening to different topics.
You can link more than one channel to the same Item, when you have the “same data” coming via different topics.

you’re right.
the idea is good, I will use it.
update when item changed and 5 min periodically

But did i need 2 items for voltage as example ?
cause when i change the state from the switch as example i can make a rule that triggers the publisher.

Type number : Power2      						  [ stateTopic="stat/Steckdose_01/STATUS8", transformationPattern="JSONPATH:$.StatusSNS.ENERGY.Voltage"]

but for the periodically i need this item as well correct ?

Type number : ch1Voltage        "Spannung"        [ stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage" ]

or did i have a logical problem ?

Ok cool you got MQTT connected. :+1:

I don’t think it is random.

Try this;

In tasmota console change the TelePeriod 10 in the console
10 sec is the minimum allowed

Add these channel to your thing

Type number : Total         [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Total"]
Type number : Yesterday     [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Yesterday"]
Type number : Today         [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
Type number : Period        [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Period"]
Type number : Current_Power [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
Type number : Voltage       [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
Type number : Current       [stateTopic="tele/Steckdose_01/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]

All these channels will update every 10 seconds

2 Likes

You can link two channels to one Item. An update message coming in on either channel will update the Item.

1 Like

Thanks for that response.

I tried the first version and it worked well with 30 seconds.

But I think I 5 minutes update interval is for the most usecases okay with a trigger to refresh if the state is changing.
When I can link 2 channels on one Item that will be the fix for me :slight_smile:
Thanks @rossko57

I run into a weird behavior.
Sometimes the Openhab Item switches to 0 Voltage.
I don’t know why, u can see at the log that the item is really switching from like ~230V to 0V

2021-04-13 16:42:26.615 [vent.ItemStateChangedEvent] - S4_Voltage changed from 229 to 0

2021-04-13 16:42:26.619 [vent.ItemStateChangedEvent] - S4_Power_Total changed from 0.589 to 0.03

2021-04-13 16:43:14.935 [vent.ItemStateChangedEvent] - S4_Current changed from 0.0 to 0.17

2021-04-13 16:43:14.940 [vent.ItemStateChangedEvent] - S4_Power_Total changed from 0.03 to 0.59

2021-04-13 16:43:14.943 [vent.ItemStateChangedEvent] - S4_Voltage changed from 0 to 228

Here u can see the log of the Tasmota device.
I know I got a timestamp problem (summer / winter in Germany)
But this is the log for the time.
In every log entry the voltage is at ~230Voltage.

So why does the Openhab Item changes to 0 Voltage !?
The smartplug is running all time so there is no voltage drop.

15:41:14.429 MQT: tele/Steckdose_04_Spuelmaschine/SENSOR = {"Time":"2021-04-13T15:41:14","ENERGY":{"TotalStartTime":"2021-04-10T23:42:25","Total":0.588,"Yesterday":0.000,"Today":0.588,"Period":1,"Power":76,"ApparentPower":80,"ReactivePower":26,"Factor":0.95,"Voltage":228,"Current":0.351}}
15:42:14.421 MQT: tele/Steckdose_04_Spuelmaschine/STATE = {"Time":"2021-04-13T15:42:14","Uptime":"0T07:14:44","UptimeSec":26084,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"Raspberry","BSSId":"DC:39:6F:14:1E:B0","Channel":7,"RSSI":58,"Signal":-71,"LinkCount":1,"Downtime":"0T00:00:03"}}
15:42:14.430 MQT: tele/Steckdose_04_Spuelmaschine/SENSOR = {"Time":"2021-04-13T15:42:14","ENERGY":{"TotalStartTime":"2021-04-10T23:42:25","Total":0.589,"Yesterday":0.000,"Today":0.589,"Period":1,"Power":76,"ApparentPower":80,"ReactivePower":26,"Factor":0.95,"Voltage":229,"Current":0.352}}
15:43:14.433 MQT: tele/Steckdose_04_Spuelmaschine/STATE = {"Time":"2021-04-13T15:43:14","Uptime":"0T07:15:44","UptimeSec":26144,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"Raspberry","BSSId":"DC:39:6F:14:1E:B0","Channel":7,"RSSI":56,"Signal":-72,"LinkCount":1,"Downtime":"0T00:00:03"}}
15:43:14.444 MQT: tele/Steckdose_04_Spuelmaschine/SENSOR = {"Time":"2021-04-13T15:43:14","ENERGY":{"TotalStartTime":"2021-04-10T23:42:25","Total":0.590,"Yesterday":0.000,"Today":0.590,"Period":1,"Power":21,"ApparentPower":39,"ReactivePower":33,"Factor":0.54,"Voltage":228,"Current":0.170}}
15:44:14.388 MQT: tele/Steckdose_04_Spuelmaschine/STATE = {"Time":"2021-04-13T15:44:14","Uptime":"0T07:16:44","UptimeSec":26204,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"Raspberry","BSSId":"DC:39:6F:14:1E:B0","Channel":7,"RSSI":58,"Signal":-71,"LinkCount":1,"Downtime":"0T00:00:03"}}
15:44:14.397 MQT: tele/Steckdose_04_Spuelmaschine/SENSOR = {"Time":"2021-04-13T15:44:14","ENERGY":{"TotalStartTime":"2021-04-10T23:42:25","Total":0.591,"Yesterday":0.000,"Today":0.591,"Period":0,"Power":10,"ApparentPower":12,"ReactivePower":7,"Factor":0.85,"Voltage":230,"Current":0.053}}

After some time, the voltage jumps from 0 Voltage to ~230 Voltage again…
I dont know why its fixing itself !?

The update interval is set to 300seconds.
without any rule by myself.

Did someone have an idea why this behaivor happen sometimes ?

What is your Item linked to? You’re probably listening to a topic that doesn’t always include a voltage value in the specified JSON path.

Here are my .things and .items.
It should be “SENSOR” which include the voltage in every log entry.

.things

Thing mqtt:topic:Steckdose_04_Spuelmaschine "Steckdose_04_Spülmaschine" (mqtt:broker:myMQTTBroker) 
{
	Channels:
		Type switch : ch4               "AN/AUS"          [ stateTopic="stat/Steckdose_04_Spuelmaschine/POWER", commandTopic="cmnd/Steckdose_04_Spuelmaschine/POWER", on="ON", off="OFF" ]
		Type number : ch4PowerTotal     "Energie Total"   [ stateTopic="tele/Steckdose_04_Spuelmaschine/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Total" ]
        Type number : ch4Power          "Leistung"        [ stateTopic="tele/Steckdose_04_Spuelmaschine/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power" ]
		Type number : ch4Voltage        "Spannung"        [ stateTopic="tele/Steckdose_04_Spuelmaschine/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage" ]
		Type number : ch4Current        "Strom"           [ stateTopic="tele/Steckdose_04_Spuelmaschine/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current" ]
        Type number : ch4Today          "Watt heute"      [ stateTopic="tele/Steckdose_04_Spuelmaschine/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
}

.items

//Steckdose_04_Spülmaschine
Switch S4_Switch "Steckdose Spülmaschine"                 { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4" }
Number S4_Power_Total "Energie Total: [%.3f kWh]"  (gSpuelmaschine)         { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4PowerTotal" }
Number S4_Power_Today "Energie Heute: [%.3f kWh]"         { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4Power" }
Number S4_Power "Watt: [%d]"                (gSpuelmaschine)              { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4Power" }
Number S4_Voltage "Spannung: [%.0f V]"                    { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4Voltage" }
Number S4_Current "Strom: [%.3f A]"                       { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4Current" }
Number S4_Power_Today2 "Watt heute: [%.3f kWh]"           { channel="mqtt:topic:Steckdose_04_Spuelmaschine:ch4Today" }
Number Washingmachine_OpState "Spülmaschine State [%d]"

I’ll bet you still have a ghostly link left over from previous experiments. None of the bindings are very good about managing file-based Things edits. Restart the binding, see what is left.

2 Likes

you’re right.

After a restart, everything works fine for 6 hours now.
weird :slight_smile:

At all, thanks to everybody who helped me.
I learned it the hard way… and falling over my own faults.

But at least it works and I can try different types with MQTT out.

Thank you all :slight_smile:

1 Like

You need to read the correct documents and make sure you are getting the right info for the version you are running.

You have to learn a lot to get started and asking the right question formatted so its easy to understand with enough information for us to answer will go a long way here in the openHAB community.

Now try getting the thing state working correctly for your thing add parameters to your thing.

Thing mqtt:topic:Steckdose_04_Spuelmaschine "Steckdose_04_Spülmaschine" (mqtt:broker:myMQTTBroker) [ availabilityTopic="tele/Steckdose_04_Spuelmaschine/LWT", payloadAvailable="Online", payloadNotAvailable="Offline"]
{
	Channels:
		Type switch : ch4               "AN/AUS"          [ stateTopic="stat/Steckdose_04_Spuelmaschine/POWER", commandTopic="cmnd/Steckdose_04_Spuelmaschine/POWER", on="ON", off="OFF" ]
		
}

Note that tasmota creates the LWT message as retained on broker. It will take a while for the broker to report it offline. I can’t remember the time but it may be 60 seconds.

This sounds like something is misconfigured - I’m fairly sure the way that LWT works is:

  1. When Tasmota connects to the MQTT broker, it sends a message Online to the device LWT topic.
  2. At the same time, Tasmota also tells the MQTT broker what message to use if it goes offline, namely Offline.
  3. The MQTT broker is now in charge, and when it no longer has a connection to the Tasmota device it will broadcast the Offline message on the device LWT topic.

So, as soon as the broker detects that it no longer has a connection to the device it should publish the offline LWT message, which should be almost instantly. Certainly for me, if I remove power to a Tasmota device the offline message is published by the broker within the same second (and I see it in openHAB at the same time too, though I use an LWT Channel rather than use the parameter of the Thing).

1 Like

Ah, there’s the rub. How would it detect that? It’s not busy polling the target client every millisecond to see if it’s there, or no-one else would get anything done.
So there’s a time delay about how often it gets checked.
So far as I know, the client itself tells the broker the maximum time allowed as part of its initial check-in of the LWT message.

For Tasmota, the subject of this thread, that is 15 seconds. So I was obviously chatting nonsense, as the broker could take up to 1.5 times the keep alive time to publish the offline message.

Anecdotes, anecdotes…!