More from Sonoff

Sonoff Mains PlugToday I got a couple of new(ish) gadgets from Sonoff – one being a UK version of their WIFI mains adaptor. So the point of this if you don’t know Sonoff is that their stuff is solid and inexpensive – not two words you normally find in the same sentence. The mains adaptor is absolutely solid – and when it powers on it has a nice coloured ring light to let you know it is working.  Sonoff have their own software for this but as it is ESP8266-based I usually put my own in or use Arendst’s Sonoff-MQTT-OTA-Arduino software – which up to now is proving reliable and has one advantage over my own – it is smaller and fits into the Sonoff devices without replacing the FLASH (well, it has two advantages – it supports the Amazon Echo – but as I use HA-Bridge to do that, the subject is moot).

So – I opened the unit up and Sonoff have even now kindly put labelling on the 4-hole connector inside for programming – very nice of them.

What can I say, Sonoff SCit worked first time, I can fire off MQTT commands to turn the thing on and off and can override that with the button on the front. Most other similar products I’ve seen are either proprietary, expensive or generally naff – this is GOOD and no secrets – you can get diagrams, change software and it works well.  Like the other Sonoff mains control boxes, good product – good price ($12.86 plus whatever post to get to your location – but even then – compare that to B&Q rip-offs). Lovely.

And with that, I’ll move onto the Sonoff SC – the unit you see on the right. No it is not a loudspeaker. To quote the company – Sonoff SC is an ESP8266 based WiFi environmental monitor device. It detects current temperature, humidity, light intensity, air quality, and even sound levels, and directly send realtime data to iOS/Android APP EWeLink

Sonoff SCAnd yes, I believe there is some source out there but this one is likely to be a little more difficult to DIY as it contains both an ESP8266 and an Atmel 328 – no doubt for two things that need A/D where the ESP8266 has only one analog input. So this gadget contains a SHARP Dust sensor, a DHT11 (I know, the crappy one) temperature and humidity sensor, a light sensor (a simple ORP-12) and a microphone – so it is a test-everything unit.  It runs off 5v.

So we ran it up this afternoon – there’s a nice phone app and it only takes 5 minutes to setup – I’m trying to think where you would use this – maybe in an old-folks home you were running just to keep an eye on everything?

Sonoff SCFor me it fails in that there’s no MQTT connection so unless you use their App the use is limited but they DO claim it is “hacker friendly” so when someone goes to the bother of making a complete replacement software – with MQTT and the option to replace the hated DHT-11 with a marginally more expensive DHT-22 – I may just take more of an interest.

Sonoff SCThe thing is you have light sensing in the range of “dusky, normal and bright” – I’m not sure what use that is – had they made this more than $19 they could have used one of those little light sensors that gives exact LUX out for visible and also measures humidity and temperature accurately.

As it is they’ve used an ORP-12 device which is a bit basic.  Still – if I made a super-duper one and had a 3d printed case made, it would look like something out of Dr Who so hats off to them for making this at a price in a sensible case. It is almost worth getting one for the case to then gut it and do your own thing! Recently in the blog we’ve covered all of these sensor scenarios except for the dust sensing and there’s plenty of doc on that.  Worth a second glance.

Depending on the device you are using you can click on any of these images to get larger ones.

Update 12/JAN/2017:  Reader Jay pointed me to this link which gives the oppotunity to replace the lacklustre DHT11 with a DHT22 on the Sonoff SC and to upgrade the software – nicely written article.  And secondly – just to say I now have three of the mains UK sockets in full time use and not a hitch – they work perfectly using this software (latest version as of a couple of weeks ago – but note at the time of writing he’s just today updated the software again).


53 thoughts on “More from Sonoff

  1. Looking at the software for the SC that is on the wiki, the esp runs the standard AT firmware while the 328 does all of the lifting with the sensors.

    1. We kind of figured that would be the case.. I must admit – if no-one comes out with full pack of software I’m inclined to gut it, put a proper light sensor (UV/IR/Visible), a BME280 and a gas sensor on an ESP – and MQTT to it – thing is – it will look good in the living room! Wife-Friendly.

  2. Re sonoff U.K. Wifi socket .. I wondered why they put the push below the socket so it gets obscured by the flex from the plug, however I found it’s relatively simple to pull off the retaining collar and twist the socket round while you have the guts out soldering the connection pins to the board, so the push button is now at the top .. much better I think.

  3. A real shame most China manufacturers claim EU socket when they really are DE/NL, so these don’t even fit the sockets I have 🙁

    Would also be nice if they could include the RF receiver, so you can have a ‘traditional’ remote socket with wifi for automation

  4. Hi Pete,

    Can you program the sonoff devices without open them ?
    From factory the software act as AP. Is it possible to connect to that AP and upload your sketch ?
    Now I open the case, put GPIO- to GND, connect the FTDI and upload the sketch for the fist time.

      1. Just received the socket version. There are no fixing screws and I have tried to prise apart the 2 halves. It seems to be factory sealed…. do I need to be more brutal?

        1. Nooooooooooooooooooooo. Scratch off the little label on the back – red on – there’s a screw under there.

  5. When “dusky”, turn on Sonoff to light the LED : ) The Sonoff SC is designed for the IFTTT for the Sonoff , S20 socket, Sonoff Hum and other device. And you can do this in eWelink app , or you can hack it with you code, make it join your own smart home system as a sensor center.

    We will change the DHT11 to DHT22 in next version…

    1. Thanks for updating us Freezing. DHT22 much preferable. Have you published anywhere the protocol used between the asp ESP and uino?

    1. Not they are reduced if you go outside of the marketing crap to the normal portal. 25% off the bog-standard WIFI units.

  6. How can the dust sensor access the dusty air? According to the photo, there is this membrane on the top. Would it need a small fan to measure the room air?

    1. There is no membrane on the top – there is a metal grill that lets air through freely. There is only the smallest slot at the bottom – I think I’d like to see more slots at the bottom as a minimum.

  7. I have just ordered one of these.. Would be awesome if the DHT22 upgrade made it into my unit (but I doubt I will get that lucky!)

    I am looking forward to hacking it. A few things to note:

    The Sonoff has an SD card attached to the Atmega, but if you look in the arduino firmware for the sonoff, the SD card is not being used at all! It seems to be connected to the correct ports of the atMega, so it should be trivial to add logging functionality to the device.

    Not all the Atmega ports are used up in the schematic. D3, D4, D5, A0, A4 and A5 are unconnected. Should be easy enough to add data to these pins. With A4 and A5 being free it should be easy to add i2c devices to the unit. I am thinking about adding a piezo speaker for audio feedback. Its a shame that these were not broken out already (perhaps an idea for the updated version?)

    D7 is attached to a 2N7002 transistor (120mA) and the output of this is broken out to an unused header marked LED, Should be easy to add multiple LEDs to this (although I am considering an addressible light ring) to make a night light or visual notifier (assuming that the plastic is thin enough to transmit light).

    The 2N7002 transistor has enough power to drive a 0.12A 5v micro fan. I am thinking that I might be able to add one to generate some airflow through the device during/before readings. Other environmental sensors that I have seen have some sort of forced airflow. Indeed in the itead documentation, the base looks like it has some sort of fan in there….

    There is a single pin broken out on the ESP chip, though the RX and TX pins have headers that could be used. Currently AT commands are exchanged between the ESP and the Atmega… Using a serial/mqtt bridge and if you accepted one way communication from the arduino to the ESP, there is another port there for the controlling of.

    This could be a great little platform for HA purposes and at a pretty reasonable price.

    1. If there is software out there to do the job – i.e. upgrade, then I have no doubt it will support DHT22 – if not – maybe Sonoff will offer any upgrade to existing users – ASK THEM TO. For monitoring my own view would be to do storage on a central controller like a Pi rather than messing around with an SD – that way you could get web stats online.

      Serial LED is a good idea – but it depends what load is on each device- for example, I have found that on the ESP8266, I2c and Serial LED are great – but not at the same time. I can’t imagine why they are still using that old-fashioned AT command set – there are far better ways to have ESPs and Arduinos communicate these days.

      Regardless, yes, it’s a starting point for a really nice addition to the toolbox.

  8. Hi there. Peter. Love your blog.

    Was wondering if you could help me. I have a Sonoff POW that I soldered a header to the serial pins and connected my FTDI programmer as usual.

    Unfortunately, I had my FTDI adapter set to 5v incorrectly and, of course, nothing happened. When I set it back to 3.3v I find that the board is never detected and all of the uploads fail (with the usual espcomm_sync failed error).

    I have a few more sonoffs and I’m able to program them correctly. It’s just this one that I’m having problems.

    Did I brick it by attempting to flash in 5v mode?

    PS: one interesting fact is that the sonoff pow still works! I hooked it up and its working with the original firmware (need to use the ewelink app though)… I just can’t program it.

    1. It could be that it is damaged due to the 5v. All over the web you will see warnings about this – I have used 5v inputs (NOT recommended) on ESP8266 many times without damage – but I do remember putting 5v on one of them as power once – fried.

  9. Hi Peter, I ran across this recently and it would be a nice option for those wanting a simple ON/OFF capability with any ESP12 based module. It emulates the Wemo switch modules. I programmed this into one of my spare Sonoff S20 modules and it worked just by plugging it in. I do have a Wemo bridge for the LED lighting so that probably provided the WiFi credentials but it does have a webpage setup included for setup.

    1. Hi Dave

      So – a few comments:

      1. This code is probably useful because it is simple enough for us to understand how the Alexa interfacing works.
      2. If you want to have that feature in your software, a WAY better solution is this one – – because he’s written this for the Sonoffs – i.e. ESP8266 but with multiple access point fallover etc and multi-purpose input buttons. I’m using it for simple Sonoff-type projects instead of my own more comprehensive code (which doesnt’ support Sonoff directly but read on).
      3. There is no need to have Alexa capability in the boards if you’re using a central controller like a Pi or similar because HA-Bridge does exactly the same, simulating lots of WEMO devices.
      4. None of these solutions has any means to CONFIRM that the action has taken place – hence the skill we put together.

  10. Peter, thanks for this, and your blog in general.. I keep coming across your name associated with almost everything I want/try to do ref home auto, Node-red, esp8266, etc.
    As a result of the above plus the many other resources it links, I now have 2 sonoff devices controlled from both MQTT (node-red managing), plus from Alexa running a custom skill, plus from Alexa using wemo 🙂
    Happy 2017!

  11. Pete,

    Been reading for some weeks and learning much as a noob.

    Didn’t find mention of ESPurna on your site, a library based firmware for ESP8266, emulating WeMo and many Sonoff / other device support in latest v1.4.0:

    How would you compare it with your stuff or the Arendst MQTT- Arduino software you highlighted?

    Can ESPurna functionality be integrated in your Script somehow ?

    1. Given the effectiveness of the Arendst software which is mainly oriented toward Sonoff and similar, I don’t plan to integrate Alexa capability into my software which is way more general purpose. About to pen an article on some new work on sequencing RGB LEDs soon – integrated into my software, ideal for presentation displays.

  12. Hi Peter,

    Thanks for your blog.

    I’m trying to flash the Slampher with an arduino sketch which i’ve previously done with the original sonoff and i’m getting this error.

    i’m trying to hack the Slampher sonoff. I’ve already done the regular sonoff, and tried the same method with the Slampher but getting these errors:

    Global variables use 33,408 bytes (40%) of dynamic memory, leaving 48,512 bytes for local variables. Maximum is 81,920 bytes.
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed

    It worked fine with the original sonoff and assumed the pins are the same on the Slampher? Theres a little white arrow on one of the pin-out’s which i’m assuming is 3.3v then from there it would be RX, TX and GND?

    1. Ok, so I just found your post on the slampher – needed to change the R21 resistor to R20… doh!

      My eyes aren’t what they used to be so out with the helping hands and magnifying glass!!!

      Hopefully me trying to do this without the resistor change wouldn’t of damaged anything?

    2. Why not ask over a the relevant Arduino github. It LOOKS simply like you’ve not put the unit into programming mode. Communications failure. When you say “Assume” the power and ground leads – not a good idea – check with a meter – in the blog I show the 3v3 line and ground lines you can check. If that is correct you only have two options for RX/TX and up to now I’ve not damaged any units getting THOSE the wrong way around.

      1. Thanks Peter. It was the resistor. I’ve successfully flashed it with my code now and can now control it via mqtt. Now to get my accessory file code sorted so I can use it with HAP-NodeJS/homekit and siri.

        1. Magic. Could be a good day today – I also just got my NanoPi A64 working on WIFI after a struggle – just off to find some simple benchmarking software to see if it was all worthwhile.

  13. Hi there,

    at first I have to admit that I didn’t read the whole post and the comments …. so please forgive me if the answer is already within your comments!

    I’m looking for a brightness sensor (giving a numerical value for the brightness, maybe in lux or somthing else) to be used along with the Sonoff-devices (maybe the Sonoff TH) which is supported by the firmware written by Theo Arends on github.

    Would be glad if someone can help me out.


    1. Check out the blog – I found a device that does accurate LUX – Oh GY-30 board – Ebay. I2c. It is supported by my ESP8266 software.

  14. Hi
    I have been looking at the “Sonoff-TH-Temperature-Humidity-Monitoring” on ebay. I would like to remotely monitor the temperature of my fish tank from a web connection from my phone. I don’t like the fact that you have to connect to a web server in the cloud. ( Not secure ) Can I directly access the temperature unit ?

  15. Someone (Sam) in the orignal Sonoff blog was asking about integrating Sonoff with existing light switches. Well you could detect the switch somehow and tell Node-Red, but my son and I have independently developed solutions. My son, in Australia, has replaced the Clipsal light switch with a push button that connects to the Sonoff button. Easy to do due to the modular Clipsal system and the voids in the wall.
    I chose a different route in the UK. I modified the Sonoff by breaking the neutral link (top and bottom of the board) and using the old output neutral connector (suitably labelled) as input to a simple mains voltage detector connected GPIO14. The light switch(es) connect to the voltage detector and the lights are then controlled by the Sonoff. My modified Pete Scargill code can use this in either a) two way switch mode (wall switch change, on or off, will toggle the output) or b) obey the wall switch mode (wall switch setting will be honoured when it changes).

    Both of these solutions avoid any other infrastructure, such as WiFi and Node-Red, so reduce the points of failure, which I consider a good thing, but can still be controlled using MQTT.


  16. At time of arrival it seemed that the S20 mains switch was not always switching on when I put it in the wall outlet. At the time I didn’t have enough time to investigate and when I tried later it seemed to work again. Then again it stopped working when I removed and re-inserted it into another wall outlet.

    It seems that the device only boots after it has not been used for a while. If it works, then it works, but when I remove it from the power outlet it stops working when I re-insert it. Only after a few days of waiting I can use it again.

    First I thought it was the firmware, but after flashing Espruino on it and writing my own code, it turned out it must be something with the hardware. With my FTDI programmer connected my code runs always as expected when applying power, but not when it is powered from mains. The only way to get it working again is to wait a few days and then use it.

    Anyone has an idea what could be causing this?

    1. Good, but possibly this guy lives in one of the few places in the world where the mains is not THAT deadly. On European 240v I personally would like to see something more substancial than a random-width track cut to isolate the mains. Perhaps we could convince ITEAD to make a version of their low-end
      Sonoff boards with isolated contacts if they haven’t already.

      That led me off to watch the Superhouse video about replacing Flash on the Sonoffs, something we did here a couple of years ago you may recall.

      1. In the past, I’ve just put a 240v relay after the Sonoff to achieve isolation, and allow the switching of lower voltages.
        Alternatively Itead make the Sonoff SV (Safe Voltage) which can be powered from 5-24v. In the instance where you want to connect into existing electronics, such as seen in the YouTube video, then I’d just power the SV from the devices PSU, and avoid the need to modify the Sonoff.

    1. it seems way better at separating high and low voltages and there’s a fuse now, too, but gpio14 is gone, you have gpio2 on pad IO2 on back (no pins, beware to not overheat it when soldering a jumper)…

      1. Sadly still with 1MB Flash – and no more GPIOI4 – GPIO2 available – but not brought out so you have to solder. At first sight I don’t like it.

        1. well, as they’re very “basic” in any sense (you can’t do much more that enabling the relay via the button, or detach the 2 behaviours and do whatever you want), and tasmota just works well (once updated to support this model) and has whatever we need to use them fully, ota included, who cares… once they work, leave them there and forget about them, just use them…
          but many prefer the Shelly these days, as they’ve native mqtt support on stock firmware…

          1. The Shelly T&H might solve my only issue for home automation.

            While my “Tasmota-tized” Sonoff basics {16 of them} have worked flawlessly, I have a TH10 which refuses to flash Tasmota. It goes about 80% then fails.

            This is a spare TH10 so I can to get the last Sonoff TH10 off Ewelink and their mandated data share, without risking the one that is actually working.

            If the Shelly T&H can easily be incorporated into my Node Red without flashing it, I could just use it to report temp/humidity and let Node Red decide to tell a Sonoff Basic to turn on/off.

Comments are closed.