ITEAD Sonoff switches and sockets - cheap ESP8266 Wifi+MQTT hardware

I am currently online anyway, so no problem. :slight_smile:

  1. Would be nice if you would use code fences to make the config more readable.
    image
    Those editor icons provide this funtionality.

  2. As i can see in the screenshot the github api part seems to work and you don’t get the device firmware.

So i have the same guess as @ThomDietrich had above:

https://docs.openhab.org/addons/actions/mqtt/readme.html

Tasmota can receive commands through http requests, but i don’t think that it can send commands/states with http.

This one right??

If thats what you mean, then yes thats installed… and I assume my normal on/off of the Sonoff basics from within the interface wouldnt work at all if the MQTT Action wasnt working?

(Ill try to edit/tidy my original post re code fences)

No, those are handled by the mqtt binding.
Mqtt action is only needed for usage in rules, which we need for the refreshing part.
And as it seems the action is installed properly and the binding also, since you can use the interfaces.

Second debugging step (as mostly) would be:
What are the logs telling you?
Both sample rules provide some logging functionality, so we should be able to read something out of the logs.

I see nothing logged in the openhab.log file at all (in respect to MQTT). I have restarted Openhab and looked through the logs since a restart too… I do see this:

2018-01-28 12:21:24.434 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘home.rules’ has errors, therefore ignoring it: [425,1]: missing EOF at ‘Val’

And the VAL would be the one Ive added in, as shown in my earlier message. so I guess its this??

val sonoff_device_ids = newArrayList("PowerExtension")

Is the arrayList val on top of the rules file?
I think i had problems too, when the val was “somewhere” in the file.

When the rules file is completely ignored it can’t update the items of course.

Ive moved the VAL to the top of the rules file and when I save it, there is no complaint now in the Openhab.log file… so I think that has resolved that specific issue. Though I do have another error now listed in the log file:

EDIT I see it… a missing quotation mark on line 440 after the word status"

2018-01-28 12:51:23.980 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules'
2018-01-28 12:51:23.990 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' is either empty or cannot be parsed correctly!
2018-01-28 12:51:24.354 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' has errors, therefore ignoring it: [440,70]: mismatched input '2' expecting ')'
[442,75]: mismatched input ':' expecting '}'
[444,13]: mismatched input '}' expecting 'end'

Which relates these lines:

rule "Sonoff Maintenance"
when
    Item Sonoff_Action received command
then 
    logInfo("sonoff.rules", "Sonoff Maintenance on all devices: " + receivedCommand)
    for (String device_id : sonoff_device_ids) {
        switch (receivedCommand) {
            case "restart" :
                publish("mybroker", "cmnd/" + device_id + "/restart", "1") 
            case "queryFW" :

Line 440 is below [440,70]: mismatched input ‘2’ expecting ‘)’

                publish("mybroker", "cmnd/" + device_id + "/status, "2")
            case "upgrade" : {

Line 442 is below [442,75]: mismatched input ‘:’ expecting ‘}’

                publish("mybroker", "cmnd/" + device_id + "/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin")
                publish("mybroker", "cmnd/" + device_id + "/upgrade", "1")

Line 444 is below [444,13]: mismatched input ‘}’ expecting ‘end’

            }
        }
    }
    Sonoff_Action.postUpdate(NULL)
end

Jerome

As per my EDIT on my last post, I found what the final error was, and Ive tested and its working. It does appear my main problem was not putting the VAL (or values) at the top of the rules file, and it would have worked straight away, had I done that (though I didnt realize that was a requirement).

Thank-you very much for giving time on your Sunday to look at this with me! Its very much appreciated.

Thanks!

1 Like

Your’re welcome.
As i already said i am her anyway.
I am doing some work for the vscode extension and so the keyboard is not far away. :smile:

Maybe we should file an issue for that val stuff.
cc: @ThomDietrich

Do you know anything about val instances have to be on top of a rule file Thomas?
I think this is not the expected behavior.

Hey @Confectrician,
yes has always been like this: https://docs.openhab.org/configuration/rules-dsl.html#the-syntax
I agree that this could probably be improved. There is no technical reason to have them on top, even though it doesn’t hurt. I’m not sure if a core developer wants to change something about this.
If you want to discuss, go ahead and raise an issue in the ESH repo :wink:

Guys, looks like I am simply too dumb to understand the syntax to collect the power consumption from the Sonoff POV; maybe somebody can point me into the right direction, as I am not a programmer…

Here the items

[CODE]
// Sonoffs
Switch Steckdose_Entfeuchter “Entfeuchter” (gUG,gSonoffs) { mqtt=">[mybroker:cmnd/sonoff1/POWER:command:*:default], <[mybroker:stat/sonoff1/POWER:state:default]" }

Number Steckdose_Entfeuchter_Strom “Entfeuchter Power [%.1f W]” (gUG,gStrom,gSonoffs) { mqtt="<[mybroker:tele/sonoff1/SENSOR:state:JSONPATH($.Power)]" }
[/CODE]

Switching ON/OFF works fine, but the power consumption is empty. There is a device connected, so power is consumed. Any idea what I am doing wrong ? The item definition I took from the tasmota wiki…

Thanks

Edit: Solved it finally (tried at least ideas from 15 posts or so…geeee)

Number Steckdose_Entfeuchter_Strom "Entfeuchter Power [%.1f W]" <energy> (gUG,gStrom,gSonoffs) { mqtt="<[mybroker:tele/sonoff1/SENSOR:state:JSONPATH($.ENERGY.Power)]" }]

Adding “ENERGY” did the job finally…

With the latest tasmota i use the following item and it works

Number BM_BR_CeilingLight_Power "UG Heizungskeller: Leistung [%d W]" <it_wifi> (BM_BR_CeilingLight) {mqtt="<[mqtt:tele/BM_BR_CeilingLight/SENSOR:state:JSONPATH($.ENERGY.Power)]"}

In the JSONPATH the “Energy” is missing.

Thomas

Yep, figured this out in the meantime as well, but thanks a lot. Finding the correct format is sometimes a pain in the b**…

TH16 - Reading the Temp and Humidity - I have the TH16 connected. I have the switch part of it working, ie i can turn it on and off. But I dont understand how to get the temp and humidity out of it. I have it connected to MQTT.FX and I can see it go on and off. I have checked the openhab log and i dont see any errors nor do I see any temp or humidity. it has a AM2301 sensor attached to gpio14.

I added this to the items:

Number Humidity “Humidity [%d %%]” { mqtt=“<[broker:cmnd/sonoff-00th161/AM2301/humidity:state:default]” }
Number Temperature “Temperature [%.1f °C]” { mqtt=“<[broker:cmnd/sonoff-00th161/AM2301/temperature:state:default]” }

Still dont see anything in the logs.

Thanks!

cmnd is for commands to the sonoff. The topics for info from the Sonoff are tele and stat/

Using MQTT.FX, subscribe to tele/# and stat/# and you should see lots of data coming from your sonoff.

My items files for a sonoff 16 state, temp and humidity are:

String sonoff2State "[%s]" (startpersist) {mqtt="<[mosquitto:stat/sonoff2/POWER:state:default]"} 
Number sonoff2Temperature "Temperature"  {mqtt="<[mosquitto:tele/sonoff2/DHT/TEMPERATURE:state:default]"}
Number sonoff2Humidity "Humidity"  {mqtt="<[mosquitto:tele/sonoff2/DHT/HUMIDITY:state:default]"} 

Does the TH16 know it is a TH16? :slight_smile:

When configured, the Tasmota main web page show live temp and humidity readings just above the ON / OFF switch status and blue buttons.

If the values are missing have a look at:

  • Configuration -> Configure Module
  • Module Type = 04 Sonoff TH
  • GPIO14 Sensor = 02 AM2301

Reboot, check the main page for readings again, and then look for tele/topic/STATE messages in MQTT.

Hey Tom, thanks. That would make sense. I have subscribed to the tele and stat and dont get the data. I do get the STATE that shows the uptime, wifi, ssid, etc. No sensor data. So something else is going. I am going to respond to James too, but I dont see any temp and humidity in the Tasmota app either…

Hey James, had to laugh at this one. Do any of us really know if we are a Sonoff. In any case, to your question, I do not see the temp and humidity in the Tasmota app so that might be a first clue. I have configured the module exactly like you stated. I just changed out the sensor too - hmm, could have been bad. But still no data. I tried what Tom suggested but it does not show the temp data. Thoughts on where to go from here?

Thanks!

I often feel like requesting a firmware upgrade, but am stuck with this version! :slight_smile:

My network has two TH16 flashed with Sonoff-Tasmota 5.11.1, and found the front-page stats only appeared when the sensor was connected - e.g. required config AND connection.

If the config is there, and you’ve swapped out the sensor, could the TH16 be bad? There’s not much in there - just the 2.5mm socket.

The only other thing that comes to mind is to look at the web interface console for any errors - mine shows regular sensor readings broadcast into MQTT - e.g. MQT: tele/th16-temp/STATE

Decided to update the firmware and voila! It worked! Well, that made my day!

Now to get it into my sitemap and then write some rules! Yikes!

Thanks all!