Lots of different cheap plugs can be modified like this.
The plugs we are using (ebay link – Lingan SWA1) were chosen because they are easy to disassemble and solder, and they’re cheap. Nearly all smartplugs use esp8266 and can be modified in similar way.  I’ve probably hacked up a dozen or so different models.

The ESP_Flasher utility used in this guide is here:  https://github.com/Jason2866/ESP_Flasher
Tasmota firmware used in this guide is here: http://ota.tasmota.com/tasmota/tasmota.bin

Why do this?
Local control — ALL! stock consumer IoT device firmware beacons to 3rd-party servers (many in China), and some beaconing leaks WiFi ssid and password in cleartext. In this project, we will replace the stock device firmware with Tasmota, which is open-source and auditable. Tasmota is very well documented (https://github.com/arendst/Sonoff-Tasmota).

A core value of home assistant (and me, personally) is to rely on cloud services as little as possible.  I want my stuff to work irrespective of internet status or cloud provider status.

We will be primarily focusing on the smartplug modification itself — not on installing home-assistant or the mosquitto MQTT broker software.  We have limited time in this workshop, and there are many other excellent tutorials for Home Assistant on the Home Assistant forums.

Let’s Go!
Disassemble – remove 4 screws holding the case together

Open and separate the power board by flipping it out of the way.

Insert the DuPont connector wires into the holes you see.  The color of the wire does not matter, what matters is that you connect holes to the programmer correctly referencing the labeled pictures below:

To write a firmware image to the internal memory of the smartplug, we must boot the ESP8266 on the mainboard into bootloader mode.  To do this, the GPIO0 pin must be connected to GND/ground.  Since the programmer has just one GND/ground pin, we will use a clip connector to split 1 ground wire to 2 ground wires.  You can see in the image below, a single wire connects the GND pin of the programmer to the clip connector.  From there, 2 wires exit the connector, both of them connected to the ground pin:

When connecting pins — the TX and RX pins must be crossed:
TX on programmer connects to RX on smartplug
RX on programmer connects to TX on smartplug

5V plug hole -> 5v programmer pin
GPIO 0 hole -> ground pin (via clip connector)
GND hole -> ground pin (via clip connector)

Use your finger to hold a small amount of sideways pressure against the connectors inserted into the holes of the smartplug. A small amount of pressure is needed to keep the pins in contact with the edges of the holes on the circuit board.   Continue to hold until programming is complete.  The guide will call out specifically when you can release the pressure on the connectors.

Plug the USB programmer into the laptop.

Launch the Esp_Fasher program.  It can be found in the Kernelcon folder on the desktop/home screen.

From the drop down menu, select the available COM port.  ESP_Flasher will automatically find and identify ports with chip programmers plugged in. The example below shows COM5 – yours may be a different COM port number (likely COM4).  Whatever COM port is shown, please take note as we will need this later.

Click the “browse” button and choose the tasmota-smartplug.bin file – this is the new firmware file we will load to the smartplug’s ESP8266 internal chip.

Click “Flash ESP” and the process will run.  See screenshots for guidance.  The flash process takes several seconds to erase.  If the flasher seems to be frozen, just wait a minute for it to progress.

Take note of the MAC address that is shown during flashing.  If it scrolls by too quickly for you to record, you can scroll up through the log file when the flashing process finishes.  It is critical to record this MAC address for later use:

When finished, you will see the following screen.  You can now release pressure on the pins.

This means we have successfully flashed this light bulb and we can now take full control over how it operates.

Plug the smartplug into an outlet.

During the flashing step above, you recorded the smartplug’s MAC address.  From your laptop, look for and connect to the tasmota-xxxx-xxxx network name where the -xxxx-xxxx contains the characters from your smart bulb’s MAC address.  In the screenshots provided, the flashing log showed MAC address of 5C:CF:7F:30:22:AD, and we see a wireless network containing the 6 characters at the end of the mac address (3022AD).  This is how you verify which SSID belongs to your smartplug.

Upon connecting, you should be redirected to a WiFi configuration screen:

Select the “kernelcon-iot” network
Type the password     hackspaceio
Click “Save”

If a save password prompt pops up, escape/cancel it quickly

The smartplug will start to connect to the network — once it connects, it will display the IP address of the smartplug.   Take note of the IP address.  It will be in the format of 192.168.128.xx

Re-connect your laptop to the “kernelcon-iot” network if it does not automatically reconnect itself.

In a Firefox/browser window – type the IP address that you noted just a moment ago when the smartplug connected to the wireless network.  It should be 192.168.128.xxx.  Web interface will look like this:

 

Click “Console”

In the box where it says “Enter command”, paste the following text:

backlog template {"NAME":"SWA1","GPIO":[0,0,0,0,288,224,0,0,0,32,0,0,0,0],"FLAG":0,"BASE":18}; module 0; wificonfig 2;

The plug will reboot and reconnect to WiFi.  The button on the smartplug will now work to toggle the internal relay, and the LED light will change color based on state (power on/power off).  The web interface toggle button will now work as well, and the webif/LED light will always be synchronized.

When finished with the lab activity – reset the wifi settings of the smartplug.  The plug is configured to look for the “kernelcon-iot” network, which will not exist at your home.  Upon failure to connect, the plug should revert to broadcasting an SSID and allowing you to configure just as we did in the lab, but it is best to make sure the smartplug will be in a good state by resetting the WiFIconfiguration before leaving the HHV at Kernelcon:

From the main web interface:
click “Console”
In the bottom command window area type:

reset 3

Press “Enter” key.   This will reset WiFI to default state, and smartplug will boot to access point mode.

Return the USB programmer and the wiring harness/clip connector to Matt/Jeff or an HHV staff.

Other Information:

You can add the smartplug via MQTT to your home automation system (Hubitat, Smart-Things, Home-Assistant, Node-Red, anything!) for 100% local control.   Alternatively, you can enable Belkin WeMo emulation and Google Home/Alexa can discover the smartplug and control it.

Enable WeMo emulation:

  • Configuration -> Configure Other
  • Change Device Name and Friendly Name to reflect what the device is (Example:  Livingroom Lamp)
  • In the Emulation section, click “Belkin WiMo”
  • Save
  • Perform device discovery on Google Home/Alexa/Smart Things.
  • There is more information on WiMo emulation here:  https://tasmota.github.io/docs/Alexa/

The smartplug can also participate in Tasmota Device Groups.  A smart wall switch running Tasmota firmware can be configured to toggle the power state of this smartplug.  Several smartplugs can be members of a single device group.

Device group information is here:https://tasmota.github.io/docs/Device-Groups/