Son Of Sonoff

We’ve covered the Sonoff a few times–a very inexpensive box with an ESP8266, a power supply, and an AC relay along with a way to tap into a power cord. Very inexpensive means $5 or $6. The supplied software will work with several systems (including, recently, Alexa). But what self-respecting hacker wants to run the stock firmware on something with an ESP8266 inside?

[Tzapu] certainly didn’t. But he also knew he didn’t want to start from scratch every time he wanted to deploy a switch. So he built SonoffBoilerplate and put the code on GitHub. The code manages taking configuration (including network settings) using a web-portal, can update itself over the air, and integrates with Blynk and MQTT. If you don’t like that code base, there are other choices including one that has a failsafe reconfiguration mode.

You do have to solder a header to the board to reflash it. Since all of these provide for updating over the air, you could probably press fit the header just to get the initial flash, if you like.

Of course, if you want you can totally reprogram it, too. Or use the stock firmware and control it like all the normal people do.

If you plan to use Blynk, we’ve covered it before. For that matter, we’ve talked about MQTT, too. You can see more details about Sonoff, including a quick reveal of the insides, in the video below.

19 thoughts on “Son Of Sonoff

  1. I actually use pogo pins for programming so I don’t have to solder headers to every board. I’ve goat a couple of setups, one using a 1×4 header with the pins inserted and one with separate wires (not all devices have the nice 4-pin header arrangement that the plain sonoff has) it’s sometimes a bit tricky to hold them in place for the programming, but not harder than soldering a lot of wires to things.

  2. If you use the esp8266 to emulate a wemo device, you can control it with Alexa directly instead of asking her to ask “we link” to do it.

    “Alexa, turn on the light.” vs “Alexa, ask we link to turn on the light.”

  3. actually I have two remarks.

    1.) one should use the cable-anchor properly (why: live voltage, dangerous)
    the outside isolation should be clamped down not the isolation of the inner wires.

    2.) one should connect the ground in and out cables, through the box and not cut them
    (why: live voltage, all devices behind the SONOFF will not directly trigger RCDs over the nearest ground, in case of a lose cable for example. Your PC Case is most likely made up of sheet metal, that needs to be grounded because otherwise a lose wire can give you a nice “greating” when the case is grounded the RCD will trip)

    1. I mostly agree but the sonoff does not have a ground plane inside – I routed the ground around it for most of my lights – except for one where the lamp only had 2 wires to begin with.

      As for clamping the wires down – the problem is that you need to cut the teeth back a bit since the box is not made for 3-wire cables (they have a too large a diameter) .

      I recently started to swap them out for new sonoff plug-in switches. They are a bit more expensive at 12EUR but a bit safer.

      1. are you the creator of the sonoff? if so, i have a few suggestions:

        * use a double pole relay. sockets in germany, austria and other countries are unpolarized; you could end up with live current to the device in the off state.
        * put a physical button on the device to allow turning it on/off without a cell phone
        * better cable retention and more shielding around the connections: right now, if a cable comes loose, it could easily get exposed and touched.
        * add a earth pole/connection; people might not hook it up otherwise.

      2. How do you mean routed “around” it? When you say “ground” you mean “earth”, right? Connected to the actual planet, rather than “ground” just meaning “0v relative to some arbitrary point”?

        Actually that’s a problem with the American idiom, the meaning of “ground” is overloaded. Doesn’t do C++ any good and it won’t for you, either.

        Because in the video above, it’s just plain cut, “routed” nowhere. And yup many lamps just require 2 wires, and aren’t earthed by virtue of being made of clay or something insulating. But even so it doesn’t hurt to run earth as far down the wire as you can, if the wire’s going to go through switch boxes and things. One of an earth wire’s jobs is to provide an easy path to earth for any loose, wandering mains wires. So that even if there’s no RCD, they’ll blow a fuse.

        There should be perhaps a third terminal block within the case, for connecting an earth wire from incoming and outgoing cables. As is, it loses major safety points, and cannot be considered safe for any appliance that is normally earthed. It could turn a metal-bodied appliance, ketal, toaster, etc, into a deathtrap.

        And then just agreeing with the above guy, that’s a HORRIBLE bit of cable fitting, clamping on the inner insulation. Should never be done, but then it looks like the device couldn’t fit in 3-core cable properly, or even 2-core above maybe flat 5-amp lamp cable.

        Is this a commercially available product? Because it really needs banning. Lack of earth connection, and not even room inside the case to add your own terminal block. Opening apparently not thick enough to take 3-core cable. And switching only on one mains wire, which may be live or neutral in countries with unpolarised outlets (which are bad enough on their own…). If you were changing a lamp’s bulb, thinking it was “off” cos the app said so, you could get a deadly zap from the full mains. If this is commercially available, and popular, I expect people will die.

        I wouldn’t have one of these in the house. Too dangerous, makes me cringe. I suppose it might make a nice core you could gut out, replace the relay with a proper 2-pole one, provide for earthing, etc.

        Brrrr!

        1. > How do you mean routed “around” it?

          Almost certainly means the ground isn’t connected to the Sonoff (because you can’t), but it’s connected to the downstream devices.

          “Ground” is unambiguous in America, in the context of wiring, since the 3 wires are “ground”, “neutral”, “hot”, for 120VAC. Some people also refer to it as “earth”; the terms are synonymous.

  4. You could also look at ESPEasy. A complete framework to setup esp8266 with a pletora of homecontrollers, or stand alone if you wish. Supports additinal sensors as well. But do be carefull using the sonoff, ir runs on mains power so only program it without the sonoff being plugged in.

  5. I enjoyed the Easy ESP project very much. But if you want to use it for SONOFF, make sure you bought the one-relay-version. The two-relay-version works different. More complex at all.
    See http://www.instructables.com/id/SONOFF-Dual-Tutorial-Control-Your-Electrical-Appli/
    or
    http://support.iteadstudio.com/support/discussions/topics/11000006870/page/1?url_locale=

    I use one of the two-relay-version to power up my 3d-printer and his octopi separately via MQTT and openhab.
    The code of Markus Maeder works fine for me.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.