Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Sonoff S31 with energy monitoring #1626

Closed
zephyrr opened this issue Jan 18, 2018 · 45 comments
Closed

Support for Sonoff S31 with energy monitoring #1626

zephyrr opened this issue Jan 18, 2018 · 45 comments

Comments

@zephyrr
Copy link

zephyrr commented Jan 18, 2018

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
Copy link
Owner

arendst commented Jan 18, 2018

Will be implemented once I receive mine.

@phreakmonkey
Copy link
Contributor

phreakmonkey commented Jan 22, 2018

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
Copy link
Contributor

phreakmonkey commented Jan 22, 2018

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
Copy link

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
Copy link
Owner

arendst commented Jan 30, 2018

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

@arendst
Copy link
Owner

arendst commented Feb 1, 2018

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

Update:

  • Voltage, Current, Power, Power Factor - Done
  • User Voltage, Current, Power Calibration - Done
  • Energy - Tomorrow

image

@dkgrizzly
Copy link

Very nice!

@zephyrr
Copy link
Author

zephyrr commented Feb 3, 2018

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

arendst added a commit that referenced this issue Feb 3, 2018
5.11.1i
 * Update TasmotaSerial library to 1.1.0
 * Rename commands
HlwPCal, HlwUCal and HlwICal to PowerCal, VoltageCal and CurrentCal to
be used for both Pow and S31 calibration
 * Rename commands HlwPSet,
HlwUSet and HlwISet to PowerSet, VoltageSet and CurrentSet to be used
for both Pow and S31 calibration
 * Add support for Sonoff S31 Smart
Socket with Power Consumption Detection (#1626)
 * Fix IRReceive Data
value (#1663)
 * Fix compiler warnings (#1774)
@Sky1980chs
Copy link

Thank you Theo!

@Sky1980chs
Copy link

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
Copy link
Contributor

@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
Copy link

Sky1980chs commented Feb 6, 2018

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
Copy link
Owner

arendst commented Feb 6, 2018

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
Copy link

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
Copy link
Owner

arendst commented Feb 6, 2018

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
Copy link

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
Copy link
Author

zephyrr commented Feb 6, 2018

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
Copy link

Hint accepted and previous erroneous comments removed to avoid confusion.

arendst added a commit that referenced this issue Feb 9, 2018
5.12.0 20180209
* Change library PubSubClient.h define MQTT_MAX_PACKET_SIZE from 512 to
1000 for Home Assistant  support
* Change relation of define MESSZ being dependent on PubSubClient.h
define MQTT_MAX_PACKET_SIZE
* Change command color parameter input checks to less strict for Home
Assistant support
* Change command Ina219Mode into command Sensor13
* Change commands HlwPCal, HlwUCal and HlwICal to PowerCal, VoltageCal
and CurrentCal to be used for both Pow and S31 calibration
* Change commands HlwPSet, HlwUSet and HlwISet to PowerSet, VoltageSet
and CurrentSet to be used for both Pow and S31 calibration
* Change uptime from hour to second resulting in a display of
123T13:45:21 where 123 is days
* Change module name Wemos D1 mini into Generic (#1220)
* Change HTML from width=100% to style=width:100% supporting HTML5
(#1358)
* Change OSWATCH_RESET_TIME (Blocked loop) from 30 to 120 seconds to
allow slow networks (#1556)
* Change WIFI_MANAGER_SEC into WIFI_CONFIG_SEC (#1616)
* Change function pointers code to save code space and memory (#1683)
* Change webserver argument processing gaining 5k code space (#1705)
* Change weblog memory usage (#1730, #1793, #1819)
* Update TasmotaSerial library to 1.1.0
* Update language files Italian (#1594), Dutch (#1723) and Spanish
(#1722)
* Fix Non-English JSON temperature unit attachement
* Fix Arilux RF induced exception by moving interrupt handler to iram on
non ESP8266/Arduino lib v2.3.0
* Fix truncated command names and wrong response for DomoticzSwitchIdx
(#1571)
* Fix %-sign issue as printf escape character in Humidity and Sonoff SC
(#1579)
* Fix DS18B20 temperature JSON decimal dot (#1561)
* Fix Energy JSON message (#1621)
* Fix IRSend parameter translation (#1636)
* Fix TSL2561 device detection (#1644, #1825)
* Fix BME680 teleperiod resistance measuring (#1647)
* Fix Energy Monitoring Energy Today and Energy Total reading after
restart (#1648)
* Fix IRReceive Data value (#1663)
* Fix Energy Monitoring Energy Period roll-over (#1688)
* Fix compiler warnings (#1774)
* Fix command PWM response if no PWM channel is configured (#1783)
* Add locale Decimal Separator to Web sensor page
* Add ColorTemperature to light status message
* Add command PowerOnState option 5 which inverts PulseTime and allows
for delayed always on after power on
* Add OtaMagic two step Web server OTA upgrade using filename-minimal
image if OTA free space is too small
* Add support for PMS5003 and PMS7003 particle concentration sensor
* Add command SetOption21 1 to allow Energy Monitoring when power is off
on Sonoff Pow and Sonoff S31 (#1420)
* Add Chinese language file (#1551)
* Add French language file (#1561)
* Add Spanish language file (#1589)
* Add HTTP Allow Cross Origin removed from ESP8266/Arduino lib v2.4.0
(#1572)
* Add Home Assistant MQTT Discovery for switch and light to be enabled
by command SetOption19 1 (#1534) or define
HOME_ASSISTANT_DISCOVERY_ENABLE in user_config.h (#1685)
* Add command State to retrieve device state information (same data as
teleperiod state and status 11 in slightly different JSON format)
* Add optional login to Webserver AP mode (#1587, #1635)
* Add command Sensor15 2 to start MHZ19(B) Zero Point Calibration
(#1643)
* Add support for Sonoff S31 Smart Socket with Power Consumption
Detection (#1626)
* Add command SetOption20 to allow update of Dimmer/Color/Ct without
turning power on (#1719, #1741)
* Add NTP sync time slot based on chip id (#1773)
* Add cursor pointer to web button (#1836)
@j2mc
Copy link

j2mc commented Feb 9, 2018

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
Copy link
Owner

arendst commented Feb 9, 2018

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

@asmugala
Copy link

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
Copy link

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
Copy link

j2mc commented Feb 22, 2018

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
Copy link

@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
Copy link
Owner

arendst commented Feb 25, 2018

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
Copy link

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
Copy link

j2mc commented Feb 26, 2018

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
Copy link

gxgani commented Mar 5, 2018

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

@asmugala
Copy link

@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
Copy link

gxgani commented Mar 12, 2018

@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
Copy link

jekkos commented Apr 13, 2018

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

@jekkos
Copy link

jekkos commented Apr 13, 2018

Ok think I found my answer

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

So probably just need to use US - EU adapter then

@arendst
Copy link
Owner

arendst commented Apr 13, 2018

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
Copy link

nardev commented Apr 21, 2018

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

@jekkos
Copy link

jekkos commented Apr 24, 2018

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
Copy link

PiOver2 commented May 7, 2018

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
Copy link
Owner

arendst commented May 7, 2018

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
Copy link

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?

@BigBill2000
Copy link

Thanks! Got it working now.

@ascillato2
Copy link
Collaborator

Hi,

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

curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 6, 2018
5.11.1i
 * Update TasmotaSerial library to 1.1.0
 * Rename commands
HlwPCal, HlwUCal and HlwICal to PowerCal, VoltageCal and CurrentCal to
be used for both Pow and S31 calibration
 * Rename commands HlwPSet,
HlwUSet and HlwISet to PowerSet, VoltageSet and CurrentSet to be used
for both Pow and S31 calibration
 * Add support for Sonoff S31 Smart
Socket with Power Consumption Detection (arendst#1626)
 * Fix IRReceive Data
value (arendst#1663)
 * Fix compiler warnings (arendst#1774)
@rikray02
Copy link

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
Copy link

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
Copy link

xbliss commented Jun 29, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests