Gosund SP111 / Tasmota / MQTT / things problem and question

Hello everbody,

maybe someone can help me with my issues:

I’ve flashed 2 Gosund SP111 Power Outlets with Tasmota 8.3

my setup:

Openhab 2.5.8
Mosquitto Broker
MQTT Binding 2.5.8
Generic MQTT Things via config file

mqtt.things

Thing topic power2ogoffice "WLAN/MQTT 2OG Steckdose Büro" @ "2OG" {

    Channels:

        Type switch : ch1                "Schaltkanal"     [ stateTopic="Messung/stat/power2ogoffice/POWER", commandTopic="Messung/cmnd/power2ogoffice/POWER", on="ON", off="OFF" ]

        Type number : ch1PowerTotal      "Energie Total"   [ stateTopic="Messung/tele/power2ogoffice/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Total" ]

        Type number : ch1Power           "Leistung"        [ stateTopic="Messung/tele/power2ogoffice/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power" ]

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

        Type number : ch1Current         "Strom"           [ stateTopic="Messung/tele/power2ogoffice/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current" ]

        Type string : ch1bootModule      "Modul"           [ stateTopic="Messung/tele/power2ogoffice/INFO1", transformationPattern="JSONPATH:$.Module" ]

        Type string : ch1bootVersion     "Version"         [ stateTopic="Messung/tele/power2ogoffice/INFO1", transformationPattern="JSONPATH:$.Version" ]

        Type string : ch1bootHostname    "Hostname"        [ stateTopic="Messung/tele/power2ogoffice/INFO2", transformationPattern="JSONPATH:$.Hostname" ]

        Type string : ch1bootIPAddress   "IP-Adresse"      [ stateTopic="Messung/tele/power2ogoffice/INFO2", transformationPattern="JSONPATH:$.IPAddress" ]

        Type string : ch1bootRestartReason "Restart Grund" [ stateTopic="Messung/tele/power2ogoffice/INFO3", transformationPattern="JSONPATH:$.RestartReason" ]

}

gosund.items

// Items for SP111 2OG Office:
Switch F2_WlanS1 "Steckdose 2.OG Office"                    <switch>     (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1" }
Number F2_Power_TotalS1 "Energie Total: [%.3f kWh]"         <energy>     (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1PowerTotal" }
Number F2_Power_TodayS1 "Energie Heute: [%.3f kWh]"         <energy>     (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1Power" }
Number F2_VoltageS1 "Spannung: [%.0f V]"                    <energy>     (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1Voltage" }
Number F2_CurrentS1 "Strom: [%.3f A]"                       <energy>     (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1Current" }
String F2_bootVersionS1 "Version: [%s]"                     <settings>   (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1bootVersion" } 
String F2_bootModuleS1 "Modul: [%s]"                        <settings>   (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1bootModule" }
String F2_bootHostnameS1 "Hostname: [%s]"                   <settings>  (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1bootHostname" }
String F2_bootIPAddressS1 "IP-Adresse: [%s]"                <network>    (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1bootIPAddress" } 
String F2_bootRestartReasonS1 "Restart Grund: [%s]"         <alarm>      (F2_LivingRoom_PowerOutletOffice) { channel="mqtt:topic:mosquitto:power2ogoffice:ch1bootRestartReason" }

values / strings from ch1bootModule down to othes are beeing published and displayed

but after some time (didn’t figure out exactly) some values are gone / set to NULL

obviously only the topics with INFO* are effected

interesting side effect:

if i restart the gosund device all values are published again and after a certain time the INFO* topics are gone

i’ve seen in tasmota / gosund console that topics1-3 are beeing published once after reboot

is there a way to get / reread the topics INFO1-3 in a periodic time-frame? without rebooting the device?

i’ve also seen in tasmota / gosund console that there are some STATUS cmds

eg. if i enter STATUS 2 i get following published message:

13:46:41 CMD: INFO3
13:46:41 MQT: Messung/stat/power2ogoffice/RESULT = {"Command":"Unknown"}
13:46:44 MQT: Messung/tele/power2ogoffice/STATE = {"Time":"2020-09-11T13:46:44","Uptime":"0T04:41:10","UptimeSec":16870,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":39,"MqttCount":2,"POWER":"ON","Wifi":{"AP":1,"SSId":"pretty fly for a wifi","BSSId":"00:21:29:99:0A:04","Channel":11,"RSSI":100,"Signal":-48,"LinkCount":1,"Downtime":"0T00:00:03"}}
13:46:44 MQT: Messung/tele/power2ogoffice/SENSOR = {"Time":"2020-09-11T13:46:44","ENERGY":{"TotalStartTime":"2020-08-25T18:35:37","Total":1.275,"Yesterday":0.159,"Today":0.025,"Period":0,"Power":2,"ApparentPower":9,"ReactivePower":9,"Factor":0.20,"Voltage":248,"Current":0.038}}
13:46:46 CMD: Messung/tele/power2ogoffice/INFO1
13:46:46 MQT: Messung/stat/power2ogoffice/RESULT = {"Command":"Unknown"}
13:46:54 CMD: Messung/stat/power2ogoffice/RESULT
13:46:54 MQT: Messung/stat/power2ogoffice/RESULT = {"Command":"Unknown"}
13:47:09 CMD: Messung/stat/power2ogoffice/INFO3
13:47:09 MQT: Messung/stat/power2ogoffice/RESULT = {"Command":"Unknown"}
13:47:14 MQT: Messung/tele/power2ogoffice/STATE = {"Time":"2020-09-11T13:47:14","Uptime":"0T04:41:40","UptimeSec":16900,"Heap":21,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":2,"POWER":"ON","Wifi":{"AP":1,"SSId":"pretty fly for a wifi","BSSId":"00:21:29:99:0A:04","Channel":11,"RSSI":100,"Signal":-48,"LinkCount":1,"Downtime":"0T00:00:03"}}
13:47:14 MQT: Messung/tele/power2ogoffice/SENSOR = {"Time":"2020-09-11T13:47:14","ENERGY":{"TotalStartTime":"2020-08-25T18:35:37","Total":1.275,"Yesterday":0.159,"Today":0.025,"Period":0,"Power":2,"ApparentPower":10,"ReactivePower":10,"Factor":0.19,"Voltage":248,"Current":0.041}}
13:47:24 CMD: STATUS 8
13:47:24 MQT: Messung/stat/power2ogoffice/STATUS8 = {"StatusSNS":{"Time":"2020-09-11T13:47:24","ENERGY":{"TotalStartTime":"2020-08-25T18:35:37","Total":1.275,"Yesterday":0.159,"Today":0.025,"Power":2,"ApparentPower":10,"ReactivePower":10,"Factor":0.16,"Voltage":248,"Current":0.041}}}
13:47:33 CMD: STATUS 2
13:47:33 MQT: Messung/stat/power2ogoffice/STATUS2 = {"StatusFWR":{"Version":"8.3.1.6(tasmota)","BuildDateTime":"2020.06.19 16:50:05","Boot":31,"Core":"2_7_1","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285","CR":"458/699"}}

how can i evaluate the RESULT topic?
and how can i publish the STATUS cmd in a periodic frame?

hm, maybe someone can help me,

regards, j

You are on a good track, the INFO messages are not sent regularly (as far as I know),using the STATUS messages would solve the update problem.
Use a rule with a cron trigger set to your desired update rate. In the rule use a MQTT action to send the same command which you used manually to get the STATUS messages.
In order to get the values change the used MQTT subscription in your channels to match the STATUS message instead of the INFO message and pay attention to the differnces in the way the values are presented ( the transformationPattern would be different).

As @opus says, you’re on the right track!

INFO topic

INFO1, INFO2 and INFO3 are only sent when the device starts up. Here is a Tasmota console log of a device starting up:

00:00:00 CFG: Loaded from flash at F7, Count 645
00:00:00 Project tasmota Bedroom Side Light Version 8.1.0(tasmota)-2_6_1
00:00:00 WIF: Connecting to AP1 ACPRO1 in mode 11N as swBedroomSideLight-5696...
00:00:06 WIF: Connected
00:00:06 HTP: Web server active on swBedroomSideLight-5696 with IP address 192.168.1.113
15:11:26 MQT: Attempting connection...
15:11:26 MQT: Connected
15:11:26 MQT: tele/swBedroomSideLight/LWT = Online (retained)
15:11:26 MQT: cmnd/swBedroomSideLight/POWER = 
15:11:26 MQT: tele/swBedroomSideLight/INFO1 = {"Module":"Sonoff Basic","Version":"8.1.0(tasmota)","FallbackTopic":"cmnd/DVES_BFB640_fb/","GroupTopic":"cmnd/tasmotas/"}
15:11:26 MQT: tele/swBedroomSideLight/INFO2 = {"WebServerMode":"Admin","Hostname":"swBedroomSideLight-5696","IPAddress":"192.168.1.113"}
15:11:26 MQT: tele/swBedroomSideLight/INFO3 = {"RestartReason":"Software/System restart"}

It is strange that after some time openHAB would set the linked Items to NULL. Either way, it doesn’t look like you can get Tasmota to re-print the INFOx topics again, unless you restart the device.

I would check your openHAB openhab and event logs at around the time that the linked Items are set to NULL to see what is happening.

STATUS topic

As you’ve identified, however, you can probably use the STATUS topics to grab the same information. It looks like you are after:

  • Module
  • Version
  • Hostname
  • IPAddress
  • RestartReason

Module

It does not seem possible to get this information from a STATUS topic.

Version

It is possible to extract the Version from the STATUS2 topic. Here is an example STATUS2 message:

15:20:46 MQT: stat/swBedroomSideLight/STATUS2 = {"StatusFWR":{"Version":"8.1.0(tasmota)","BuildDateTime":"2019-12-25T12:33:25","Boot":31,"Core":"2_6_1","SDK":"2.2.2-dev(38a443e)","Hardware":"ESP8285","CR":"376/699"}}

And this is a possible replacement channel configuration for you to extract the version:

Type string : ch1bootVersion [
	stateTopic="Messung/stat/power2ogoffice/STATUS2", 
	transformationPattern="JSONPATH:$.StatusFWR.Version"
]

Hostname

It is possible to extract the Hostname from the STATUS5 topic. Here is an example STATUS5 message:

15:23:32 MQT: stat/swBedroomSideLight/STATUS5 = {"StatusNET":{"Hostname":"swBedroomSideLight-5696","IPAddress":"192.168.1.113","Gateway":"192.168.1.254","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.254","Mac":"DC:4F:22:BF:B6:40","Webserver":2,"WifiConfig":4}}

And this is a possible replacement channel configuration for you to extract the hostname:

Type string : ch1bootHostname [
	stateTopic="Messung/stat/power2ogoffice/STATUS5", 
	transformationPattern="JSONPATH:$.StatusNET.Hostname"
]

IPAddress

It is possible to extract the IPAddress also from the STATUS5 topic. This is a possible replacement channel configuration for you to extract the IP address:

Type string : ch1bootIPAddress [
	stateTopic="Messung/stat/power2ogoffice/STATUS5", 
	transformationPattern="JSONPATH:$.StatusNET.IPAddress"
]

RestartReason

It is possible to extract the RestartReason from the STATUS1 topic. Here is an example STATUS1 message:

15:20:44 MQT: stat/swBedroomSideLight/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"tasmotas","OtaUrl":"http://thehackbox.org/tasmota/release/tasmota.bin","RestartReason":"Software/System restart","Uptime":"0T00:09:27","StartupUTC":"2020-09-12T14:11:17","Sleep":50,"CfgHolder":4617,"BootCount":14,"SaveCount":646,"SaveAddress":"F6000"}}

And this is a possible replacement channel configuration for you to extract the hostname:

Type string : ch1bootRestartReason [
	stateTopic="Messung/stat/power2ogoffice/STATUS1", 
	transformationPattern="JSONPATH:$.StatusPRM.RestartReason"
]

Force STATUS topic updates

Tasmota does not send any STATUS messages by itself - it must be prompted, as you’ve found out. To get Tasmota to send messages on the STATUS topics, as @opus mentions, you us an MQTT action at a timed interval using CRON. A possible example might be:

rule "Update STATUS topics"
when
	Time cron "0 0 0/1 ? * * *" or
    System started
then	
	val mqttActions = getActions("mqtt","mqtt:broker:mosquitto")
    mqttActions.publishMQTT("Messung/cmnd/power2ogoffice/status","1")
    mqttActions.publishMQTT("Messung/cmnd/power2ogoffice/status","2")
    mqttActions.publishMQTT("Messung/cmnd/power2ogoffice/status","5")
end

You’ll have to change the pointer to your MQTT bridge (you didn’t show that in your OP, so we can’t really guess), but otherwise the above should work. I haven’t tested it though!

However…

This only masks the issue. I don’t think there should be any reason for your linked Items to go NULL without something happening. You should try to find out what that something is, and maybe start with the openHAB logs.

2 Likes