Unlock the Full Power of Cheap Smart Plugs with Tasmota

Note: I now recommend using ESPHome for all your hacked-smart-device needs instead of Tasmota. The configuration is easier to understand and is significantly more flexible than Tasmota. Plus, it has direct Home Assistant integration rather than relying on MQTT, since it's made by the same people that make Home Assistant.

I may revisit this blog post at some point to adapt it to an ESPHome config, but all the information below will still work.

I think we can all agree on some level that home automation is pretty cool. Your smart plug automatically turns on the coffee maker before you wake up so you can start the day off with a fresh cup of joe at just the right temperature. When your alarm goes off, the blinds open and your lights turn on gradually as lo-fi starts playing. It's like that one DCOM except without the evil AI (at least, not yet).

But there are some issues with home automation in The Year Of Our Lord Twenty Twenty-One:

  • Privacy and Security: Many (if not most) smart devices are directly connected to The Cloud™️ with proprietary firmware, so there's no telling what that thing is doing on your network! Not to mention all the vulnerabilities that come with being connected directly to the internet. Yuck.
  • Compatibility: Shopping for smart devices can be daunting. You need to decide what to use as your "ecosystem" (Google Home? HomeKit? Alexa??) and then tediously make sure everything you want is compatible with that ecosystem. Then, oh lord, the manufacturer wants you to set up the thing through their own awful app. Not a great experience.
  • Price: The "good stuff" (Philips Hue, WeMo, etc.) is going to cost you a pretty penny. You could definitely settle on a cheaper option, but then compatibility with your ecosystem as well as UX, quality, etc. is thrown into question.

But what if I told you that you can avoid all three of these issues with just a bit of time and elbow grease? That's where Tasmota comes into play: it's open source firmware for ESP8266-based devices. The ESP8266 is a small microchip that enables electronics to connect to WiFi; it also has some GPIO pins that you can use to connect to whatever else you want.

Why is this notable? It's extremely popular. The ESP8266 has found its way into many a smart device from smart plugs to bulbs to robot vacuums to dehumidifiers. If you see a "smart" device on a shelf at Best Buy, there's a good chance that it's powered by an ESP8266.

The exciting thing about this is that since all these devices share the same core component, all we need to do is figure out how to get our own software onto it and suddenly we've fully unlocked the capabilities of the hardware. Good news: all ESP8266 modules support a common flashing mode.


Introduction

Before you read: Keep in mind that this is intended for those new to hardware hacking. If you are one of those people, and find some part confusing, or information missing, please do reach out to me. You can DM me on Twitter or email me: blog@tjhorner.dev

Have fun!

In this post we'll be taking a look at the Emporia Smart Plug with Energy Monitor, an affordable option ($30 for a pack of 4!) for anyone that wants to add simple smart controls to an existing appliance. We'll be flashing Tasmota on it so we can bypass the manufacturer's app entirely and integrate it with our platform of choice.

Prerequisites

Note: This project involves cutting holes in things and soldering stuff to other stuff. Even if you're not experienced with hardware (I'm not either!) I encourage you to read through the post to see if this seems doable for you. I promise it's not as hard as it sounds!
  • Emporia Smart Plug
  • Serial to USB interface
  • Solder and soldering iron
  • A Dremel with cutting and sanding accessories
  • Electrical tape
  • Safety glasses
  • Assorted lengths of wire
  • Recommended: Fire extinguisher. Just in case.

Accessing the Hardware

You don't need to follow the first half of this section. It's mostly storytelling.

Tasmota first caught my eye when a friend mentioned it in a group chat. I checked to see if my smart plugs were compatible, and thanks to Ken from Amazon it was confirmed:

Thanks, Ken!

Unfortunately I couldn't really find any resources on how to get started with reflashing these plugs specifically, so I went to Home Depot, bought a Dremel and started cutting away to search for the pads I needed to connect it to the serial interface. (To put an ESP8266 into flashing mode, you need to hold GPIO0 down while booting, so in total we need RX, TX, GPIO0 and power.)

Some beginning cuts.

Eventually I cut off the entire back of the device and was able to take the PCB out for a closer look.

The naked PCB out of its shell.

I could see the ESP8266 on a daughterboard soldered on to the main board.

There's the ESP8266, hidden behind the contacts for the power input.

On the other side I could see the RX and TX pads, so I soldered some wires to those. That's two down, but I still needed to find out where to wire power and GPIO0.

Please don't make fun of my soldering job.

I tried following the traces with no luck. But thankfully a friend noticed that our friend Ken from Amazon mentioned that the process was similar to another device, the Teckin SP20, and looked up resources for that. It turns out that this device is indeed nearly identical, and the power/GPIO0 pads are in the exact same spot. With that, we have everything we need to connect the plug to the serial interface. I soldered wires to the necessary pads.

You can see I also accidentally touched the iron to the wire casing. Oops.

Here's how my first attempt turned out when I was done:

Glorious, isn't it?

Knowing where the pads are will save a lot of time when flashing these in the future. If you're following along, I made this guide on where to cut to access the pads:

Try to cut as close to the neutral prong as you can. You'll need that space to reach the TX pad.

Once you've cut along the guide, it should look something like this:

Definitely an improvement over my first monstrosity.

Once you've soldered wires to the necessary pins, we can get to the fun part: flashing Tasmota!

All set up.

Flashing Tasmota

The flashing section of the official Tasmota docs has more information on how to flash on various platforms, but for simplicity I decided to use Tasmotizer on Windows. If you're using the serial interface I linked to earlier, you should wire up the pins like so (make sure you pay attention to the note about mis-labeled RX/TX pads):

https://community.home-assistant.io/t/programming-teckin-sp20-esphome-without-using-tuya-convert/155576/5

If you are on Windows you may need to download drivers for the serial interface, which you can find here. Also of note is the fact that the Sparkfun serial interface I linked is in 3.3V mode by default, so there is no need to attach a jumper.

DO NOT PLUG IT INTO THE WALL.

Once everything is wired up, go ahead and flash Tasmota using your preferred method (check the official docs for more info). If it worked, hooray! You can skip to Configuring Tasmota. If not, check out the common issues below.

Common Flashing Issues

  • Make sure TX is connected to TX, and RX is connected to RX. Remember, they are mis-labeled on the PCB.
  • Make sure GPIO0 is connected to both GND on the serial interface and the neutral prong of the device (this is our ground). This pulls the pin low, which indicates to the ESP8266 to enable flashing mode. To accomplish this I soldered a wire to an alligator clip, then the other end to 2 other wires; one leading to the serial interface, the other soldered to GPIO0. Here's a visual:
  • Make sure the right COM port/device is selected in your flashing software.
  • Make sure your serial interface is providing 3.3V, not 5V. Sending 5V will fry your ESP8266.
  • Make sure your serial interface actually works. A good way to test this is by creating a serial loopback — i.e., connect RX to TX on the interface itself. Connect to the device using a serial terminal (e.g., screen on macOS/Linux, or PuTTY on Windows). Type some characters, and if they appear back (and the activity LEDs on the interface start blinking), that means your serial interface is working fine.

Configuring Tasmota

Once Tasmota is flashed on the device, we need to configure it. Tasmota has a concept of "templates" which tell the firmware which components are plugged into which GPIO pins. Depending on which components you have, each will have a default behavior that makes sense. For example, if you define a button, relay, and LED, the button will control the relay and the LED will indicate connection status or relay status. This can be configured, though. Check out the docs for a comprehensive list of options. For our purpose, however, the defaults are just fine.

I prefer to do the configuration before the device is sealed up, since it's quicker than connecting through the hotspot. But if you want to do that instead, you can skip this section and refer to the official docs for how to set up via hotspot. I'm also going to assume you are using Tasmotizer here, so refer to the docs if you aren't.

Ok, since you're still reading I assume you want to configure the device with Tasmotizer before sealing it up. First, make sure your serial interface is unplugged from the computer. Then let's desolder our wire from GPIO0, but leave everything else intact. We want to get the ESP8266 out of flashing mode, but we also still want the power and serial connection. (Also make sure ground is still connected to the neutral prong on the device.)

Press "Send config" in Tasmotizer, fill in the WiFi network that you want it to connect to, then this template:

{"NAME":"Emporia EMS02","GPIO":[320,0,321,0,224,2720,0,0,2624,32,2656,0,0,0],"FLAG":0,"BASE":18}

Save the config. If all goes well, you should be able to power cycle the device, wait a bit, then see it connect to your network. You can press "Get IP" to get the IP once connected.

If you visit that IP in your browser, you should be able to see the web UI for Tasmota:

Eureka!

Try pressing the Toggle button a few times; listen for a click and make sure the LED turns on and off properly. You should also press the button a few times to see if it triggers the relay. If all goes well there, you're safe to seal the device back up.

Desolder the wires from the pads, and seal up the hole with some electrical tape:

Good as new. You can't even tell we modified them.

Testing It Out

Now for the moment of truth. Find a (preferably GFCI'd) outlet, grab your fire extinguisher (seriously), and plug the thing back into the wall. Hopefully there is no magic smoke! The LED should flash for a couple of seconds while it connects to your network, and then it should either remain solid or off depending on the relay's state. Go ahead and plug something into it (with your fire extinguisher still handy), and press the button a couple of times to trigger the relay.

You're done! Kind of. It's out of the scope of this post, but since you have the hard part done the rest should be easy peasy.

What Next?

You can leave it as it is (not very useful...) or you can choose one of Tasmota's many supported integrations (I recommend Home Assistant!). Also, if you intend on using the power monitoring capabilities of this plug, you will need to calibrate it. There are docs for this on the Tasmota website.

Now that you know how to flash an ESP8266, you also know how to flash any other device that uses one! Check out the list of devices that users have contributed Tasmota templates for; it's a great place to get started. If you have a device that's ESP8266-powered but it's not on there, it would also be a great time to learn to do it yourself and submit the template while you're at it.