This article will explain the process of reflashing a Sonoff S31 with Tasmota firmware. A quick device tear-down of the smart plug along with some simple soldering allows you to replace the firmware on the device, thereby allowing it to easily join a management system for control, monitoring, and automation.

DISCLAIMER: Electricity is dangerous and can cause personal injury or death as well as other property loss or damage if not used or constructed properly. Do not attempt any wiring of any kind if you lack the relevant knowledge and understanding required; Instead hire a qualified specialist to perform the work for you.

What is a Sonoff S31?

The S31 is a 15amp Wi-Fi smart plug with onboard power monitoring and overload protection. It tracks the real-time use of power, current, and voltage, as well as measuring electrical consumption for a specified time period. For safety purposes, it also allows maximums to be specified (power, current, or voltage) and will automatically turn off connected devices when reaching any one of the set values.

Sonoff S31 Smart Plug
Sonoff S31 Smart Plug

Disassembly

Disassembling the S31 is a simple process. First pop-off the dark grey end cap which will then allow the two rounded edges to slide out.

S31 with Endcap Removed
S31 with Endcap Removed

Remove the three screws which are now exposed in order to extract the back panel.

S31 with PCB Removed
S31 with PCB Removed

On the bottom edge of the PCB you can see a row of six solder pads. For the purposes of this article, only four will be used: VCC, GND, TX, and RX. There are actually two pairs of RX/TX pins; You will use the pair closest to the VCC pin.

S31 Flashing Pins
S31 Flashing Pins

FTDI USB Adapter Connections

A FTDI adapter is a USB to Serial converter which allows for a simple way to connect TTL interface devices to USB. Adapters come in a few flavors (3.3V, 5.0V, or both), so make sure you get one that supports 3.3V. In our case, we used a Moyina and set the voltage selector to 3.3V.

WARNING: Using 5V on the S31 will brick the device, double-check you are operating at 3.3V.

We also used the jumper cables which shipped with the adapter, connecting only the four pins required for reprogramming.

Moyina FTDI USB Adapter
Moyina FTDI USB Adapter

Four short pieces of 20AWG wire were then used to solder to the S31 board pads. When connecting to the jumper wires, ensure to cross-wire the communication lines:

  • VCC -> VCC
  • RX -> TX
  • TX -> RX
  • GND -> GND
S31 Pinout
S31 Pinout

Once the device is wired, press the power button on middle of the PCB while simultaneously plugging the USB adapter into your computer. Leave the button depressed for approximately 5 seconds to ensure the device has been placed into “programming mode.”

S31 GPIO Soldering Pads
S31 GPIO Soldering Pads

Reflashing the Sonoff S31 with Tasmota

Now that the device is connected and in programming mode, we will use the open-source firmware Tasmota to flash the device firmware. Tasmota is written by Theo Arends and licensed under the GNU General Public License v3.0. It features local control over MQTT as well as options for automation using timers or rules.

The web installer can be located here:

Tasmota Web Installer
Tasmota Web Installer

Once connected, the web installer will upload the new firmware to the S31. After the programming process has completed, disconnect the FTDI adapter from your computer, de-solder the temporary connection wires, and reassemble the S31 plug.

Flashing the S31
Flashing the S31

Joining the Network and Configuration

At this point, the device has been flashed, but has not yet been joined to your Wi-Fi network. The following steps will vary somewhat based on your local network and devices, but the process steps will remain the same.

  • Power on the S31 (plug it in to the wall)
  • Open the Wi-Fi settings on your Mobile Device/Computer
  • Wait until you see a Wi-Fi network that starts with tasmota and join it. For example “tasmota-acebe4”
  • Connect via a flavor of “Sign in to this network” prompt
  • You’ll be presented with a list of Wi-Fi networks, select yours and type in the password.
  • Take note of the IP address that you are presented with.
S31 Wi-Fi Configuration
S31 Wi-Fi Configuration

After the module has joined the network, you can access it via its IP address through any browser. Click the “Configuration” button and set Module Type parameters to “Sonoff S31” to allow Tasmota to know exactly what type of device it is controlling. Also click “Configure Other” and update the Device Name and Friendly Name, then click “Save.”

S31 Module Type
S31 Module Type

MQTT Configuration

MQTT is commonly used to connect smart plugs to the Home Assistant platform. Setting up a Home Assistant Installation with MQTT is outside of the scope of this article. However, if you are supporting that type of installation, below are the final steps required for the device to fully join your automated environment.

  • Navigate to the S31 IP address
  • Click “Configure MQTT” and fill in the following details:
    • Host – The IP address of you MQTT instance. (starting on Tasmota 12.1.1, you can also use homeassistant.local).
    • Client – This must be unique for the user. The default value will work.
    • User – Use the MQTT user you previously configured
    • Password – Use MQTT password you previously configured
  • Click Save
Home Assistant MQTT Configuration
Home Assistant MQTT Configuration

Static IP Address

Usually, the device does not need a static IP address. Most local networks will be behind a router and you will access the S31 via a DHCP assigned address. However, if needed, use the following steps to set a static address.

  • Connect to the S31 console via a browser
    • http://s31-ip-address-goes-here/cs
    • NOTE: see here for a full list of commands available
  • ipaddress1: device ip
  • ipaddress2: gateway
  • ipaddress3: network mask
  • ipaddress4: dns
  • restart 1
S31 Static IP Address
S31 Static IP Address

Consider a Label

In order to track or inventory your devices, consider printing a label and affixing it to the bottom of the device.

S31 Label
S31 Label