[SOLVED] Sonoff Tasmota firmware Version Check and Update

Looking at This subpage you will see all possible commands for Tasmota. Use the console on the webGUI of your sonoff and try the different STATE commands (like STATE2)and you can directly see what you can get.

Thanks for the link. Now i can see, when i write a command to get the state, then i get:

stat/xxx/xxx

When i wait some time, i get this all few minutes, without any command:

tele/xxx/xxx

So in my things-file, i have to use tele in all my channels? Is this right?

And strange thing is, i can read out wifi channel and SSId, but with the exact same syntax, i don´t get RSSI. But i can see RSSI value in my sonoff web console.

Next question:
Some status-info i can see all few minutes in the web console, without any command from me.

But “STATUS” i can only get with acommand to show the values.

So does mqtt2-binding send commands all few minutes to the sonoff or sends the sonoff this from itself?

Is this right:
–> tele/sonoff-name/STATE is sent automatically? I only have to wait and get the info?
–> stat/sonoff-name/STATUS is NOT sent automatically and i have to send a command first? So i have to extend my things file?

Now i´m one step further…

I got the firmware version value filled. I sent a command from the sonoff web console and i got the value into my item.

But how can i send those commands from openhab? I use mqtt2. Do i have to install some more bindings for publishing commands? When i want to send in a rule:

val sonoff_device_ids = newArrayList("sonoffs")

rule "MQTT System Test"
when
    Item System_Test changed
then
    logInfo("System Test", "System Test: Button is now " + System_Test.state)
	for (String device_id : sonoff_device_ids) {
			logInfo("sonoff.rules", "Sonoff Maintenance: " + device_id + " / " + sonoff_device_ids)
			publish("MosquittoBroker", "cmnd/" + device_id + "/status", "2")
	}
end

This is the error in MS Visual Code:

{
	"resource": "/w:/rules/mqtt.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.diagnostics.Diagnostic.Linking",
	"severity": 8,
	"message": "The method publish(String, String, String) is undefined",
	"startLineNumber": 10,
	"startColumn": 4,
	"endLineNumber": 10,
	"endColumn": 11
}

I think now i got it… publish is mqtt1…

So i hope this is right:
standard-state will be sent all few minutes without any command. So i get many infos. For special infos i have to “ask” the sonoff first. Then i get back an answer.

But:
If i listen to “tele/sonfoss/STATE” and i send a command to update this, i will get back the answer to the topic “stat/sonoff/RESULT” - so i have to use two channels with 2 items to store the values.

Or can i listen to both topics with only one item?

x
x
x

How fast is a sonoff? I want to use a sonoff POW - so how short can i set the interval to read out power consumption (watt)? Is it possible to get new values every second (only for testing)?

Or another example with sonoff S20: Can i set up a rule to ask the sonoff every second, to get back the time? Or is this to fast for the sonoff?

I’m pretty sure you only can issue commands to cmnd/sonoff/… You will get the answer as stat/sonoff/…
tele/sonoff/… is to get frequently information (defult is 6 Minutes?)

16:42:53 MQT: tele/sonoff_b1/STATE = {"Time":"2019-02-22T16:42:53","Uptime":"7T05:44:30","Vcc":3.471,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"mySSId","BSSId":"the MAC Address","Channel":11,"RSSI":88}}

or json formatted:

{
	"Time": "2019-02-22T16:42:53",
	"Uptime": "7T05:44:30",
	"Vcc": 3.471,
	"SleepMode": "Dynamic",
	"Sleep": 50,
	"LoadAvg": 19,
	"POWER": "ON",
	"Wifi": {
		"AP": 1,
		"SSId": "mySSId",
		"BSSId": "the MAC Address",
		"Channel": 11,
		"RSSI": 88
	}
}

You could get more information by issuing cmnd/sonoff/status 0 sonoff should answer with around 10 topics (stat/sonoff/STATUS, stat/sonoff/STATUS1, … stat/sonoff/STATUS11

Hi @halloween,
as @Udo_Hartmann posted, you will get the tele/… in a periodic cicle. To see what cicle is set, go in the Web UI of your Tasmota, and there into the Console. Then type in “TelePeriod” (that’s enough) and you will see the result:


To change the value just type in the Period (in Seconds) you want to have it changed. The several commands are detailed explained as remarked by Jürgen

BTW that’s what Theo says:

You are quite correct, the Rule you tried to use was Mqtt-Action 1.x. I don’t know how to handle this, with MQTT-2.

I also don’t know how fast a Sonoff can answer to your request, so you should test it. But if you want know how high the Energy Consumption of your POW is, just use the values you’ve got from the POW

Here’s a part of my item-set (POW), just for the JSON-Strings

//192.168.178.xx  Stehlampe stehlampe-1824
Switch    Sonoff_Pow_02                     "Stehlampe [MAP(de.map):%s]"                      <standard_lamp>         (EG_Wohnen,gSonoff)                             { mqtt=">[peter:cmnd/stehlampe/power:command:*:default],
                                                                                                                                                                              <[peter:stat/stehlampe/POWER:state:default]" }
Number    Sonoff_Pow_02_Verbrauch           "Stehlampe Verbrauch Total[%.2f kWh]"             <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/SENSOR:state:JSONPATH($.ENERGY.Total)]" }
//*       For Fun and Test
Number    Sonoff_Pow_02_Strom               "Stehlampe Stromaufnahme [%.2f A]"                <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/SENSOR:state:JSONPATH($.ENERGY.Current)]" }
Number    Sonoff_Pow_02_Spannung            "Stehlampe Spannung[%.2f Volt]"                   <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/SENSOR:state:JSONPATH($.ENERGY.Voltage)]" }
Number    Sonoff_Pow_02_Leisung             "Stehlampe Leistung[%.2f W]"                      <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/SENSOR:state:JSONPATH($.ENERGY.Power)]" }
Number    Sonoff_Pow_02_VCC                 "Stehlampe VCC[%.2f V]"                           <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/STATE:state:JSONPATH($.Vcc)]" }
String    Sonoff_Pow_02_State               "Stehlampe Status [%s]"                           <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:stat/stehlampe/POWER:state:default]" }
Number    Sonoff_Pow_02_RSSI                "Stehlampe RSSI [%s]"                             <qualityofservice>      (EG_Wohnen,gRSSI)                               { mqtt="<[peter:tele/stehlampe/STATE:state:JSONPATH($.Wifi.RSSI)]" }
String    Sonoff_Pow_02_Tele                "Stehlampe Wlan [%s]"                             <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/STATE:state:JSONPATH($.Wifi.SSId)]" }
DateTime  Sonoff_Pow_02_Date                "Stehlampe Refresh [ %1$tH:%1$tM]"                <standard_lamp>         (Chart_Sys_Temp)                                { mqtt="<[peter:tele/stehlampe/STATE:state:JSONPATH($.Time)]" }
String    Sonoff_Pow_02_Version             "Stehlampe Version [%s]"                          <sonoff_pow>            (Chart_Sys_Temp,gVer)                           { mqtt="<[peter:stat/stehlampe/STATUS2:state:JSONPATH($.StatusFWR.Version)]" }
Switch    Sonoff_Pow_02_Unreach             "Stehlampe Ereichbarkeit [%s]"                    <siren1>                (EG_Wohnen,gLWT)                                { mqtt="<[peter:tele/stehlampe/LWT:state:MAP(reachable.map)]"}

So I think there is no need to ask every second, as the POW will save all those Data for you.

Cheers,
Peter

How can i rename the name of the mqtt groups? Inside the tasmota i can see group topic “sonoffs”.

So when i send a command with mqtt like this:

val sonoff_device_ids = newArrayList("sonoffs")
val mqttActions = getActions("mqtt", "mqtt:broker:MosquittoBroker")


rule "MQTT Update Sonoff Status"
when
    Item SystemStarting changed from ON to OFF
then
	for (String device_id : sonoff_device_ids) {
			logInfo("sonoff.rules", "Sonoff Maintenance: " + device_id + " / " + sonoff_device_ids)
			mqttActions.publishMQTT("cmnd/" + device_id + "/status", "2")	
	}
end

How can i only send this command to a special group of my sonoffs? Do i have to rename the group of this sonoff devices to maybe “sonoff-group-1” and then i can change

val sonoff_device_ids = newArrayList("sonoffs")

to this

val sonoff_device_ids = newArrayList("sonoff-group-1")

and the rule will send only a command to the members of this group?

“sonoffs” is normally the group-topic of all your Tasmota-Switches, when you flash them for the first time via atom or vscode.

If you want to change just one or two of your Switches, you only have to change the ArrayList. Your Rule could look like

/*
val sonoff_device_ids = newArrayList(
    "pow_01",
    "stehlampe",
    "LampeYork",
    "basic_04",
    "schaltdose05",
    "schaltdose06",
    "schaltdose07",
    "schaltdose08",
    "schaltdose01",
    "schaltdose02",
    "schaltdose03",   // RasPi Office
    "schaltdose04"    // Wohnzimmerschranklicht
)
*/
val sonoff_device_ids = newArrayList("sonoffs")

rule "Sonoff Tasmota Version"
when
    Item Sonoff_Release_Refresh changed to ON or
    Channel 'astro:sun:local:noon#event' triggered START or
    Channel 'astro:sun:local:civilDusk#event' triggered START
//   Channel 'astro:sun:local:set#event' triggered START
then
var firmware = transform("REGEX", ".*([0-9].[0-9].[0-9])", Sonoff_Current_FW_Available.state.toString)
    logInfo("sonoff.rules", "Tasmota Release Refresh to Items: " + firmware + "(sonoff)")
    logInfo("sonoff.rules", "Tasmota Release triggeringItem: " + triggeringItem )
    logInfo("sonoff.rules", "Tasmota Release receivedEvent: " + receivedEvent)
    logInfo("sonoff.rules", "Tasmota Release previousState: " + previousState)
		
    for (String device_id : sonoff_device_ids) {
          publish("peter", "cmnd/" + device_id + "/status", "2")
          // logInfo("sonoff.rules", "Sonoff Maintenance: " + device_id)
    }

end

I use it sometimes with selected topics or with the group-topic, as they are defined in your tasmotas.

If you want to group your tasmotas you can change it via the web-console of your tasmota like this:

As you see i changed it to peter and then i will change it back to sonoffs. But do not scare when using the GroupTopic command as it will make a restart of your tasmota immediate after the change.

Cheers,
Peter

1 Like

I found a easy but a bit dump solution :smiley: Its possible to control the tasmota software with http. So you cand send http get requests to requests states or the software update just by sending commands. Moreover its better to set a static ip for this way.

After reboots i ask with this command for the actual state : sendHttpGetRequest(“http://X.X.X.X/cm?cmnd=Power”)

And with this Im doing the updates:
sendHttpGetRequest(“http://X.X.X.X/u1?o=http%3A%2F%2Fthehackbox.org%2Ftasmota%2Frelease%2Ftasmota-DE.bin”)

There are a lot of possibilities … dont forget to config all the json transformation for the items

Hi, Juschi,
let me welcome you in the community. :firecracker: :sparkler: :fireworks: :tada:

What you’re presenting is one kind of interacting with items/devices.

I’m useng it sometimes to enable or disable my MQTT-Parameter in my Sonoffs or changing a hostname or whatever.

val device_ids = newArrayList(
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab",
         "192.168.17y.ab"
)
rule "mqtt OnOff HostnameChange"
 when 
    Item Dummy4x changed to ON
  then
//    val vMQTT = 1
    val vMqttHost = "openHAB"
   for (String device : device_ids) {
//   var vString1 = sendHttpPutRequest("http://" + device + "/cm?cmnd=SetOption3%20"+vMQTT)    //vMQTT disable = 0 vMQTT enable =1
    var vString1 = sendHttpPutRequest("http://" + device + "/cm?cmnd=MqttHost%20"+vMqttHost)   //vMqttHost change Hostname of device
    logInfo("mqtt OFF"," vString1 {} enthält: {}", device, vString1)
   }
end

But be careful with the commands. Sometimes there are changes in the firmware, which means that an earlier command “Setoption3” is now maybe “Setoption99” or something else.

In other cases I use action-commands to direct communicate with the broker and it’s clients. i.g. for an update, a restart or just to force the current state, just for one device or for all via group-topic, which depends on what you address in your array-list

// Work with a list of selected Sonoff modules
//
val sonoff_device_ids = newArrayList(
//         "schaltdose03",
//         "pow_02",
         "schaltdose04"
)

// OR
// Work with the grouptopic, addressing ALL modules at once
// val sonoff_device_ids = newArrayList("sonoffs", "tasmotas")

// https://community.openhab.org/t/using-sonoff-power-switches-with-tasmota-firmware-and-openhab2-mqtt2-binding/59969/7  // thx to @opus
rule "Sonoff Maintenance"
  when
   Item Sonoff_Action received command
  then
//   logInfo("sonoff_maintenance", "Sonoff Maintenance on all devices: " + receivedCommand)
   val actionsBroker = getActions("mqtt","mqtt:broker:hans") // change to your broker name!
   for (String device_id : sonoff_device_ids) {
      switch (receivedCommand) {
         case "restart" : {
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/restart", "1")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
         case "queryFW" : {
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/status", "2")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
         case "upgrade" : {
             actionsBroker.publishMQTT( "cmnd/" + device_id +"/otaurl", "http://thehackbox.org/tasmota/release/tasmota-DE.bin")  // my modification, as for me this URL seems the better one -> tasmota 
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/upgrade", "1")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
        }
    }
//   Sonoff_Action.postUpdate(NULL)
   createTimer(now.plusSeconds(5), [ |
    Sonoff_Action.postUpdate("OFF")
   ])
   
 end

But for the normal communication with the devices I would prefer to use MQTT2 and Thing/Item, as there is no need writing rules for it.

One more time welcome that you joined the community. Stay tuned and share your problems and successes with us.

Cheers
Peter

1 Like

The rule is working great for me with the group topic :slight_smile:

One additional point could be nice … how do I transform the firmware output: “8.2.0(tasmota)” to just the version 8.2.0? I found out that regex is the way but i cant figure it how …

Can someone help me please?

Assuming that is the entirety of the message (nothing before it, nothing after) and it always has three digits.

(\d\.\d\.\d).*

If I put the regex in the item description like
“FW [REGEX((\d.\d.\d).*):%s]” { channel=“mqtt:topic:local:wohnzimmerlicht:firmware”} the log shows follow mistake:

mismatched character ‘d’ expecting set null
[9,62]: missing EOF at ‘’
[77,113]: mismatched character ‘’ expecting ‘"’

If I put it in the channel like this:
“Wohnzimmer FW [%s]” { channel=“mqtt:topic:local:wohnzimmerlicht:firmware:REGEX((\d.\d.\d).*)”} it shows me follow mistake:
mismatched character ‘d’ expecting set null
[9,133]: mismatched input ‘’ expecting RULE_STRING
[77,113]: mismatched character ‘’ expecting ‘"’

This is my simple solution, but not really elegant:
sendCommand(switch_oben_wz_tv_firmware, switch_oben_wz_tv_firmware.state.toString.replace("(tasmota)",""))

Look at your -> " <- signs, this are not the right ones. If you copy&paste it from the forum, you will get the wrong signs, which look to one side -> “ <- and -> ” <-. You need the right ones (shift+2) --> " <–.

…maybe you can use it in the way as it is described in the Regex-Docs, where the syntax shows this:

String  Temperature_str "Temperature [REGEX(.*=(\\d*.\\d*).*):%s °C]" {...}

In the brackets use the translation-code as Rich described. I didn’t test it yet. I will try it this evening too.

.just found one:

String Sonoff_Basic_03_Version  "Schreibtischlampe Version 31[REGEX(.*([0-9].[0-9].[0-9]).*):%s]"<sonoff_basic>  (gSonoffs,gVer)  { channel="mqtt:topic:broker:basic03:version" } 

But I think there other solutions too, e.g. in the Thing-Channel.

This works great!
But for better comparison of the strings e.g. updates or something i would prefer something behind the channel … like:

{ http="<[http://USER:PW!@192.X.X.X:80/web/powerstate:3000:REGEX(.*?<e2instandby>(.*?)</e2instandby>.*)]" }

But somehow it´s not working with the regex syntax.

Or is there a way to use it behind the transformpatter of jsonpath like this? (it´s not working)

[ stateTopic="stat/garten/STATUS2", transformationPattern="JSONPATH:$..Version", transformationPattern="REGEX:( . *([0-9].[0-9].[0-9]).*)"]

…I didn’t try the Thing-Version, even I think it should work too. (I have to test). But another solution on the items-side could be:

String Sonoff_Basic_03_Version  "Schreibtischlampe Version 31[%s]"  <sonoff_basic> (gMQTT,gSonoffs,gVer)  { channel="mqtt:topic:fritz:basic03:version" [profile="transform:REGEX", function=".*([0-9].[0-9].[0-9]).*"] } 

which is similar to the one that you prefer.

Hey Guys,

I fail to get the latest Tasmota version. I created the following thing. As a response, however, I get the complete json. Who can help me that I only get the 1st entry “name”?

Thing http:url:tasmota "Tasmota Version" [
	baseURL="https://api.github.com/repositories/80286288/tags",
	refresh=60] {
		Channels:
			Type string : TasmotaVersion "Tasmota Version" [  
				stateTransformation ="JSONPATH:.name"]
			
}```

Try $.name