# Flash Tasmota firmware to a Sonoff S31 Smart Monitoring Outlet using an Arduino Nano

![](https://lh3.googleusercontent.com/pw/AIL4fc-KsGCfOKScCQbihosNs9S0nZuXg5WSI19REFemq3eC2uRjERE6juEchFzD1GP7kEOT7WCPqn6goJzYFP3f6IWs-WTxq7Y_EMmgvKC0kmEsphoxqx1ywAsSlyNRs-QwTUdvYFuBU4LKrufVNB_kAFSHeaWgf0Ww0nqO7aitqUIE7T6Q3thOGc3hUuMuLypyCvIoHcVnd6uqzO-UoFl500fdIwd-u5bw5lGq6BXdxHvHTim4FDVE9zwM6JgWtj0h4j3EG-ckGNxeyh9Hd6mJx9HuiehWrFtwhjzgpxlciE7DlmfmDXdDs63m6MsPpB34TQCR6BAKjPOYVUYpczL3bpZfFm07qbMrfHVE8_5hlbfPGBqpC_Apcf1OcRtG9ABItY_X0zzHjG6G3r6pHZ2N8dsKtu4pZWZfFqseXtIC0C88s9LvYzDVdXaVFnRw2iYaNtxvwC3EYVNRI1gY7awTlqZOJ-dfbmcEx83XoZPKAkYvNOO7HcOrU3aF9DaayDnjN2OPJPpls3R8OBekkdeFRfCqb_Tl2TLghfJ9MqgX4DChbmg6TgoW76d4wK2DepASLGI_9N69S8fD9QfzhaunEh0KZQM7gYfwmkKhIE9clqXMZDr3MhtLSiV4AmFJOfiJAhaanCE2sdDwHBeZ5XDhncRYkyXvC1VIgIVuS8bUATwlxKmGHL_NCwbkFO3AsPytZzXh7yT75cK3AekfVh-nU-iSh29yPaHOpOyaC2RqBRcGS2MfZELX70Ip9gkH_dhonILgwShntbpmW5lM6-vra6jAlsPq0xDTvUnOofN00KfprlxF2pIKhuzzuPod4rsPUvUZw4qNUMmHBb55P3wwwV_-VOtDMewQrML10ZpuCtEk_JWiWt1ic-D298CqW7YGzhQ6zZliEe_5X8Goq0jMjrWZpnUftU0qzzSZ-CsyX6ItXfgs-gANn_XU3XtWWMHmjR2KVfWBCJWcjouHMuDXJxlLZFS7qQ=w1656-h1242-s-no?authuser=0 align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1242-s-no?authuser=0 align="left")

Bridge the Nano's GND and Reset pins.

> The TX/RX pins don't need to be swapped.

| Nano | S31 |
| --- | --- |
| 3.3V | VCC |
| RX | RX |
| TX | TX |
| GND | GND |

Hold the button on the side, plug it into the computer, release the button after 5 seconds

```bash
sudo dmesg -w
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694383560336/2d72eee9-7b4d-4db9-8a23-c20acfeaacd7.png align="center")

/dev/**ttyUSB0**

Install the pyserial python module. Pip for most people, an AUR for Arch.

```bash
sudo pacman -S python-pyserial
```

Download the esptool to do the flashing

```bash
cd ~/Downloads && git clone https://github.com/espressif/esptool.git esp && cd esp
```

Download the tasmota firmware

```bash
wget http://ota.tasmota.com/tasmota/release/tasmota.bin
```

Check if your computer can talk to the ESP

```bash
sudo python3 esptool.py --port /dev/ttyUSB0 -c esp8266 flash_id
```

Anything other than this output means your wiring is wrong, or you didn't put it into programming mode (the button holding part)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694383636637/517cfb69-87a9-4d4a-98c4-46358839cd5a.png align="center")

Actually write the firmware.

```bash
sudo python3 esptool.py --port /dev/ttyUSB0 -c esp8266 write_flash 0x0  ~/Downloads/esp/tasmota.bin
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694383721930/82db4a92-0c37-484a-9f54-115e4302692b.png align="center")

After it's done, connect to the new tasmota wifi network and go to this address.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694384049712/3895bd2a-38fc-4a76-b259-13827d9294f2.png align="center")

https://192.168.4.1/

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694384783830/9a3e2060-0928-4e18-8e3f-4c089f5afadd.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694384794548/306099b2-ed45-402a-a7c4-36c3e302d0f5.png align="center")

* Go to your router and set a DHCP reservation.
    
* Go to ***Configuration -&gt; Configure Module -&gt; Module type***
    
    * Change the module to "Sonoff S31 (41)"
        
* Go to ***Configuration -&gt; Configure Other***
    
    * Change the **Device Name** and **Friendly Name 1** to something else
        
    * "Sonoff-S31-A"
        
* Go to ***Configuration -&gt; Configure MQTT***
    
    * Input the settings that match your broker options in home assistant
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694385384619/90633c51-68d1-4189-86ce-ba288ee4c35f.png align="center")

Optional:

* Login to your Home Assistant server and go to **Settings** &gt; **Add-Ons** and click the **Add-on Store** button.
    
* Search for “TasmoAdmin” in the search and then click on the “TasmoAdmin” add-on in search results.
    
* In the add-on configuration disable SSL or it wont start.
