Hacked IoT Switch Gains I2C Super Powers

Economies of scale and mass production bring us tons of stuff for not much money. And sometimes, that stuff is hackable. Case in point: the $5 Sonoff WiFi Smart Switch has an ESP8266 inside but the firmware isn’t very flexible. The device is equipped with the bare minimum 1 MB of SPI flash memory. Even worse, it doesn’t have the I2C ports extra pins exposed so that you can’t just connect up your own sensors and make them much more than just a switch. But that’s why we have soldering irons, right?

[Jack] fixed his, and documented the procedure. He starts off by soldering a female header to the board so that he can upload his own firmware. (Do not do this when it’s plugged into the wall, you could get electrocuted. Supply your own 3.3 V.) Next, he desolders the flash memory and replaces it with a roomy 4 MB chip, because he might want to upgrade the firmware over the air, or just run some really, really big code. So far, so good. He’s got a better version of the same thing.

But breaking out the ESP8266’s I2C pins the pins that ESPEasy uses for software-emulated I2C turns this little “switch” into something much more useful — a wall-powered IoT sensor node in a sweet little package, with a switch attached. It’s just a matter of tacking two wires onto the incredibly tiny pins of the ESP8266 package. The good news is that the I2C pins are on the edge of the package, but you’re going to want your fine-tipped iron and some magnification regardless.

That’s it. Flash in a better firmware, connect up whatever I2C devices you’d like, and you’ve got a very capable addition to your home automation family for just a few bucks. Just for completeness, here’s the warning again: this device uses a non-isolated power supply, so if the neutral in your wall isn’t neutral, you can get shocked. And stay tuned for a full-length article on transformerless power supplies, coming up!

50 thoughts on “Hacked IoT Switch Gains I2C Super Powers

      1. In call faireness they are going for as much as £14.99 + £1.59 delivery on amazon in the uk. But theirs many cheeper ways to obtain esp magic in the uk, like ebay, banggood or even direct if your looking for 100 min order.

  1. The bad news is that it’s all unnecessary, because the ESP8266 doesn’t have any “i2c pins” — it only has software i2c, and you can use any two pins for it, in particular, the ones that are already exposed. You can even use one or both of the UART pins — for instance, use the RX pin if you are not going to be sending anything to it. The other i2c pin may be GPIO0, which is also broken out.

      1. I’m well aware of that the esp8266 doesn’t have hardware I2C (it’s mentioned in the article), but the only accessible extra GPIO pin is GPIO14. I needed that of a PIR sensor. Hence the adding of GPIO4 and 5.

      1. I doubt it has any approvals from UL and the like.
        It does appear to have a flyback SMPS with a transformer so it might be galvanically isolated if it has optocoupler feedback. But the transformer may not be insulated properly to pass a high-pot test.

        And it’s not clear what the true safe load for the relay and terminal blocks and PCB traces will be, especially with a reactive load.

        1. Purely out of curiosity, why does it matter if the power supply is isolated on a device where the only inputs and outputs are at mains power? It would seem to me that the isolation of the power supply would only matter if there was some way for the end user to come in contact with the low voltage. As it is, you would have to break a seal to touch any of the low voltage traces.

          1. That’s true – a lot of devices like plug-in power meters, 433MHz remote control switches, and line-powered PIR motion switches don’t have any galvanic isolation at all, they often use capacitive-reactance transformerless power supplies.

            That works well, and it is safe and cheap and easy. But if you take it apart and hack it you need to be careful! Connecting it to a PC or an oscilloscope while the AC line is connected could get you into trouble.

    1. He mentions this fact in his write-up:

      “The processor doesn’t have hardware I2C support, so you can use two free pins to connect, but usually (and in ESPEasy), GPIO4 and GPIO5 are used for I2C connections. Here I have soldered a thin wire to pin 24, which is GPIO5(SCL).”

  2. This is a great firmware to use this device with SmartThings (Home Automation kit for people who arent using HA/Domoticz). Shame it isnt open source, but still works very well in my experience and enables support for things like temperature sensors if you buy the right Sonoff.

      1. it’s not a SSR, it’s a regular relay.

        But you can get the ESP-8266 for <$2 each (including shipping), but then you need to add a power supply, relays, switches, enclosure, and terminals to connect the wires to

        the sonoff devices are nice and cheap and don't need all those other things.

        They're not for everyone, but there's no reason to attack someone who does want to use them.

  3. There’s tons of websites and videos on You tube regarding re-flashing the Sonoff and using such things as MQTT and Node-Red to create a nice dashboard but for me, I definitely prefer to use the boards by LinkNode or Link Sprite. The board I use is about the same price (sonoff is $12 Canadian on Banggood, LinkSprite is $12 on Amazon.ca).
    It has 4 relays connected to GPIO pins 12,13,14,16 and the others can be used by soldering wires to the ESP. It’s better in every way other than not having a plastic enclosure.
    The Linksprite has the full Esp8266-12 on board which is much easier to solder to. They also have a model that is just like an Uno if you want easier access to the pins.
    Like the Sonoff, the PCB has voids cut between the high power sections to help prevent arcing.
    Also, like the Sonoff the board doesn’t have onboard usb-serial but has the tx and rx pins and real easy to flash- just move 1 jumper. I can flash the awesome ESPEasy firmware just by running an exe and it takes less than 1 minute.
    It works very nicely with Node-Red and Mosquitto MQTT running on a Pi 3
    Here’s what it looks like:
    http://www.instructables.com/id/DIY-Home-Automation-With-ESP8266-Linknode-R4-and-A/

    1. No enclosure is a big drawback. But most important is that the stuff is usable WITHOUT any Cloud connection. That’s the main reason for me, why I look about hacking these.

  4. Nice hack, i don’t think i could every reliably solder to those tiny pins. On a side note, were you partial to espeasy? I’m fairly certain that Theo Arends TASMOTA firmware allows you to use gpio 14 as well as the rx/tx uart pins for i2c via software.

    1. you may want to double check the “supports all features” claim :-)

      With opensource software things can change rapidly, I’ve been watching both espurna and tasmota and I’ve seen a lot more activity on tasmota recently

  5. A question from ignorance here – but why not use the I2C pins that are used to talk to the EEPROM? Just make sure your I2C devices are on a different address to the EEPROM, and use the easily accessible pins on the EEPROM….

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.