Flashing Tasmota on Sonoff POW R2

It was a matter of moments before I decided to ditch the eWeLink app and flash Tasmota on Sonoff POW 2. If you are interested in off the box functionality, take a look at the hands-on post. I’m going to turn my soldering iron on and start hacking. We all knew this was coming.

Modifying PCB on Sonoff POW 2

I have to give it to the ITEAD guys, they made a splendid job in making this Sonoff board hackable. All you have to do is to add the female header or male pins to the dev pads and you are off to the races.

I had female headers available so I picked a 1×6 header and soldered it neatly to the board. It’s a 5 min job, even if you have to wait for your soldering iron to heat up. It used to be the case, but not any more thanks to YIHUA 992DA+.

I’m sure you have noticed neatly labled pins on the PCB. For a moment, I wondered where is GPIO00, which is needed for Tasmota, but a quick inspection of the ESP8266EX on the PCB reveals that the pin is mapped to the physical button! Awesome!

Flashing Tasmota on Sonoff POW 2

If this is your first time, then you will need to set up your environment. The process is exactly the same as in my Sonoff Basics tutorial. Take a look if you don’t have esptools installed.

To flash Tasmota on Sonoff POW 2 used my trusty serial port adapter FTD1232. Since the GPIO00 is already mapped to the button, all you need is the power and TX-RX connections.

DO NOT connect the Sonoff POW to mains during the operation. FTD1232 is more than capable to keep the ESP8266 alive for the flash.

Follow the wiring schema:

Sonoff POWFTD1232
VCC3.3V (or VCC)
GNDGND
RXTX
TXRX

I need the Tasmota image file for Sonoff POW R2 device. It’s easy, as there is one image file for all supported Sonoff devices. Pick Tasmota sonoff.bin from this page (pick your language version if you don’t want EN) the bins are at the very bottom. Then place that file in your esptool folder.

Open the esptool folder and start PowerShell or Cmd window (Shift + Right Click)

 python esptool.py

I strongly recommend to backup the firmware (just in case) then erase the flash. If you are not sure how to do this, read this post.

To flash Tasmota on Sonoff POW R2 check your COM port in device manager, then modify the command accordingly. Power the board up while holding down the button for 2-3 seconds then run:

python esptool.py --port COM11 write_flash -fs 1MB -fm dout 0x0 sonoff.bin

Once the firmware is flashed, disconnect the serial programmer and power the Sonoff POW using the power cable.

Using Tasmota on Sonoff POW 2

If the flash has been successful Tasmota on Sonoff POW R2 will advertise as new AP. Connect to it and load the configuration page. The device’s IP should be 192.168.4.1 but double check this in the WiFi manager. You are looking for the gateway IP address.

The first configuration mage will ask you for the WiFi credentials. Fill that in and wait for the Sonoff to reboot. Remember, at this point your Sonoff POW R2 will have a new IP assigned to it by the router. In the tasmota screen, go to Configuration/Configure Module and select the Sonoff POW R2 (or POW if you are using older board). This will map the buttons, lights and power consumption details.

MQTT

It’s the most convenient (but not only) connection protocol for your Sonoff, visit Configuration/Configure MQTT to connect to your broker. I recommend you the following changes:

  • client ID
  • topic
  • reverse %prefix%/ %topic%/ to %topic%/%prefix%/

I’m swapping the topic and prefix around as I find it more convenient to read. Don’t worry too much about this, as the correct topic format is visible in the Console option in the Tasmota firmware. All you need to do, is copy it from there to your MQTT setup.

The MQTT topics will depend on your configuration, so you have to adjust the topics in my examples. I have included some basic flows in my NodeRED, so you can see how you can trigger the relay and how you can intercept the state and power use data.

The MQTT rate of data is set by default to 300 sec. If you need the energy info posted more often, check out the Configuration/Configure Logging menu and adjust the Telemetry value.

HTTP

MQTT is not the only way to control the device. You can do so with HTTP endpoints. If you want to secure the HTTP endpoints with a password (which you should), visit the Configuration/Configure Other, menu. To create the HTTP POST Request use the format below.

https://xxx.xxx.xxx.xxx/cm?cmnd=Power%20TOGGLE 
xxx.xxx.xxx.xxx = Sonoff's IP
Power = command type
TOGGLE = value

https://xxx.xxx.xxx.xxx/cm?&user=USERNAME&password=PASSWORD&cmnd=Power%20On USERNAME,PASSWORD = use your web access credentials in sonoff settings
xxx.xxx.xxx.xxx = Sonoff's IP
Power = command type
On = value

//Get power info
https://xxx.xxx.xxx.xxx/cm?&user=USERNAME&password=PASSWORD&cmnd=Status%208
USERNAME,PASSWORD = use your web access credentials in sonoff settings
xxx.xxx.xxx.xxx = Sonoff's IP
Status = command type
8 = value

In this post, you will find the list of all commands that you can issue. The list is long and the commands listed can take more than one parameter. The response given will contain a JSON object with the current device state. If you want to learn more about JSON I have the basic tutorial for you.

Sonoff POW R2
Support NotEnoughTech
Buy Sonoff POW R2
Control a power outlet and monitor the power use at the same time

Conclusion

Tasmota on Sonoff POW R2 is the way to go! I’m going to use the new device for 2 projects. One Sonoff POW R2 will drive my 3D Printer and provide power use calculations for each print in my mobile notifications project. The other one will monitor my washing machine, as I’m constantly forgetting about it. What other uses could you think of? Let me know in the Reddit discussion thread.

Support NotEnoughTech
A lot of time and effort goes into keeping NotEnoughTech alive! If my work helped you out, consider buying me a coffee or check out exclusive rewards available to Patreon supporters.
SHARE