arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.09k stars 4.78k forks source link

Support for Sonoff S31 with energy monitoring #1626

Closed zephyrr closed 6 years ago

zephyrr commented 6 years ago

It would be great to support the new Sonoff S31 smart plug!

There are a number of cheap wifi controlled outlets for $20 or under, but the S31 is compact (two can fit on one US duplex outlet), supposedly capable of 15A, and most importantly does energy monitoring! And several sources are offering it for under $17, shipped.

See the last photo on this page: [(https://fccid.io/2AE2J-S31/Internal-Photos/Internal-Photos-3692513)]

I'm guessing that it continues to use the ESP8266 (or ESP8285).

It looks from the FCC registration photo as if there are pads (perhaps thru hole if not filled with solder) for VCC, GND, TX, RX and D_TX, D_RX (whatever the latter are).

arendst commented 6 years ago

Will be implemented once I receive mine.

phreakmonkey commented 6 years ago

It is ESP8266ex based. Sonoff-Tasmota runs fine on it. I haven't tried getting the "energy monitoring" working yet, so I don't know what sensor it uses.

Here's photos to show how to disassemble it; it's not readily apparent when you get it: http://www.phreakmonkey.com/2018/01/sonoff-s31-disassemble-and-flash.html

phreakmonkey commented 6 years ago

Looking at the board I see the ChipSea 7766 energy monitoring chip. Seems that it sends energy use via uart: http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf

It's connected to the ESP8266 UART0 RX pin via R2 on the board.

Sky1980chs commented 6 years ago

Theo do you have any estimate on when you will receive a S31 and start working on the power features? I can also confirm that your current firmware flashes no problem on S31 although no power measurements. Pics. for reference: https://community.blynk.cc/t/hacking-the-new-itead-studio-sonoff-s31/21532

arendst commented 6 years ago

The S31 is still in the mail. Once received I have to look at integrating the ChipSea 776 functionality...

Sky1980chs commented 6 years ago

CSE7766 reference: http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf http://www.chipsea.com/html/product/dnjs/201705/1878.html

arendst commented 6 years ago

Got it. Now find time to add it...

Update:

image

dkgrizzly commented 6 years ago

Very nice!

zephyrr commented 6 years ago

Cool! I had already ordered my own, glad to test when they arrive.

Sky1980chs commented 6 years ago

Thank you Theo!

Sky1980chs commented 6 years ago

Likely it is my error, but I can not get a successful build: \sonoff\xdrv_03_energy.ino:391:27: fatal error: TasmotaSerial.h: No such file or directory

I have verified that the files exist in a subfolder /lib/TasmotaSerial 1.1.0/src

What am I doing wrong?

phreakmonkey commented 6 years ago

@Sky1980chs - Repeat the steps for "setting up the Arduino IDE environment" from the Wiki. Recently a new library was introduced and you need to copy it from the source tree /lib folder into the libraries/ folder for your Arduino setup. You should probably copy the others while you're at it in case they've been updated since you first set up Sonoff-Tasmota

Sky1980chs commented 6 years ago

Unfortunately, I saw phreakmonkey comments too late, but had a successful build anyways. Will capture what worked for me in hopes it may help others:

  1. Copy TasmotaSerial-1.1.0 folder from the Tasmota github source /lib to the Arduino IDE install location /portable/libraries. Did same for PubSubClient although I think only think changed was MQTT_MAX_PACKET_SIZE to 1000. Note: Should have read Tasmota wiki sooner as this instruction is already detailed.
arendst commented 6 years ago

Hate to say but if I had the possibility to change all replies where people want to change Flash size from 1M (no SPIFFS) to any non supported value I would be very glad...

It's in the wiki, it's in the readme, it's in Theo's tips, it's everywhere but hey without a whip I can't force people to stay on the right path...

Sky1980chs commented 6 years ago

Humm.. I tried flashing using 1M (64K SPIFF) and was not having success. The unit returned unresponsive. I tried several times. I thought since the S31 has 4M flash I needed to increase. When I did the S31 worked. Coincidence?
Are you advising that we should flash the S31 @ 1M (no SPIFF)? I can try that...no problem.

arendst commented 6 years ago

As you noticed it worked (once). Chances are the next OTA won't work. So stick to 1M (no SPIFFS) and report any problems on that config only.

Sky1980chs commented 6 years ago

Hopefully this thread will help someone else and save you their questions. As always, I really appreciate your work you do for this community!!

zephyrr commented 6 years ago

Sky1980chs -

"Hate to say but if I had the possibility to change all replies where people want to change Flash size from 1M (no SPIFFS) to any non supported value I would be very glad..."

could be a hint to edit your post above to remove the wrong info about setting 4M/1M, since arendst is regretting that he cannot do it. (Thanks for the other tip and for trying to help others, tho).

Sky1980chs commented 6 years ago

Hint accepted and previous erroneous comments removed to avoid confusion.

j2mc commented 6 years ago

First, thank you! It works great! Second I have a quick question on the S31, will a short teleperiod cause any problems? I'm thinking in the range of 30 to 60 seconds.

arendst commented 6 years ago

No problem at all. You can go down to 10 seconds.

asmugala commented 6 years ago

What tool did you guys use to flash the S31? Can you use Arduino IDE and the same flash settings as the Sonoff Basic? Any instructions would be helpful.

asmugala commented 6 years ago

No matter what I do, I keep getting the attached error. I have Arduino IDE setup for flashing a Sonoff Basic and it works great on those. I got the following error on two different Sonoff S31's error

j2mc commented 6 years ago

Is anyone else getting random incorrect power readings from their S31? I have 3, and 2 of them are randomly showing power readings that are not happening, this one shows 22,689 W at one point: image

My other one is showing 150-170 W randomly with nothing plugged into it(unplugged dryer to test this problem): image

It is also counting it in total power calcs, here message from console showing both yesterday and today over 3kWh used even though the dryer is unplugged: 21:11:57 MQT: tele/dryer/SENSOR = {"Time":"2018-02-21T21:11:57","ENERGY":{"Total":19.69,"Yesterday":3.72,"Today":3.34,"Period":0,"Power":0,"Factor":0.00,"Voltage":124,"Current":0.000}} Graph of total power over last 24 hours: image

oglodyte commented 6 years ago

@arendst - Thank you Theo, this is great addition!

Is there a reason no user configurable GPIOs available for S31? Serials are easy to solder to, but are they used for energy monitoring?

Wanted to add temp/humidity sensor to this little nice device.

Anyone discovered other GPOIs available on-board w/out soldering directly to the chip?

arendst commented 6 years ago

First, serial is used to communicate with the energy chip. Second, Gnd is one of the AC wires again so stay away from the S31 inner parts when AC is conected.

oglodyte commented 6 years ago

Thank you Theo, good point re mains and gnd.
I assume that it is not the case with S20 is it? Or this hack might be dangerous too.

j2mc commented 6 years ago

Well, the S31 that was really acting up just stopped working completely. It powers up and connects to wifi when connected with the serial port, but no wifi or LEDs when under it's own power. Any ideas to try and get it working again?

gxgani commented 6 years ago

@asmugala did you happen to fix it yet? Having the same "warning: espcomm_sync failed" while uploading.

asmugala commented 6 years ago

@gxgani My problem was my pin headers weren't soldered correctly. I removed them and re soldered them and it worked. Make sure you're using pings 1,2 and 5 on the Sonoff. Pins 2 and 3 aren't used.

gxgani commented 6 years ago

@asmugala thanks for getting back. In my case it was the PL2303, was just not able to sync. Then I tried it with CH340G USB TTL, worked like a charm.

PS: PL2303 did flash S20 but was not able to flash S31.

jekkos commented 6 years ago

@arendst did you get an EU version of this adapter? Or does the US version work on 220V as well?

jekkos commented 6 years ago

Ok think I found my answer

Voltage Input: 90~264V AC, 50/60HZ

So probably just need to use US - EU adapter then

arendst commented 6 years ago

The US version indeed works just fine on 240V using holiday power plugs :-)

The new pow R2 uses the same energy monitoring chip as the S31 so I would go for that.

nardev commented 6 years ago

I still didn't get modules so i can't test it, is energy monitoring implemented? possible to get values through mqtt?

jekkos commented 6 years ago

Ok pow R2 arrived, any suggestions with regards to safety here? Is it ok to build my own socket and wire this thing in?

PiOver2 commented 6 years ago

I am having trouble flashing at least one Sonoff S31 with the Tasmota 5.13.1 from Arduino IDE.
It seemingly flashes correctly via USB, and the button works to force WIFI_MANAGER and I can connect to the Web interface, but cannot login, and there is garbage on the UI. Here is the HTML from the 192.168.4.1 interface

html removed because of the following update:

Now it works. It seems the Sonoff S31 does not like 1M (no SPIFFS) but does flash properly with 4M (1M SPIFFS). I hope this helps someone else.

arendst commented 6 years ago

S31 needs 1M(no spiffs) fot your next ota upgrade. It also works great on 1M(no spiffs).

All you had to do was resetting the settings with command reset 1 to fill a default friendlyname.

BigBill2000 commented 6 years ago

I am looking for information on how to add the power consumption values to Home Assistant. I am new to this, but have my S31 working in HA and I can turn it on and off. I am not sure what yaml commands to use to read the power. Any help?

blakeblackshear commented 6 years ago

Here is what I use with mqtt: https://github.com/blakeblackshear/blakeshome-config/blob/master/home-assistant/packages/sensors/sonoff_s31.yaml

BigBill2000 commented 6 years ago

Thanks! Got it working now.

ascillato2 commented 6 years ago

Hi,

Seems that your question has been addressed. Closing this issue. Please, reopen if needed. Thanks.

rikray02 commented 5 years ago

Hi,

I'm not an expert to compile with arduino, so, i can use esptool to upload bin file to Sonoff. So to night, i upload a sonoff.bin files (6.4.1). After that, all works fins but i can't see power information (voltage, current, etc.).

Any idea why? Richard

rikray02 commented 5 years ago

Forget my last comment. I'm very stupid. I forgot to change Module Type. Now, all works fine.

Thanks a lot for all sonoff développement.

Richard

xbliss commented 1 year ago

@asmugala thanks for getting back. In my case it was the PL2303, was just not able to sync. Then I tried it with CH340G USB TTL, worked like a charm.

PS: PL2303 did flash S20 but was not able to flash S31.

I am reading this thread but more confused. Does this S31 smart switch with energy monitoring have support across dual voltages?

The US version indeed works just fine on 240V using holiday power plugs :-)

The new pow R2 uses the same energy monitoring chip as the S31 so I would go for that.