Sunday, December 22, 2019

ZMAi-90 (or SMTONOFF WDS688) DIN rail meter/switch - more details on GPIOs and configuration

As an update to the previous post where I have shared the details on how to "Tasmotize" this device, I am adding more detail on what is the physical assignement of GPIO pins from the ESP8266, to other components in this device.

Given the pins from the ESP8266 microcontroller that are exposed in its breakout board (which in turn is SMD soldered to the main PCB):

We have the following identified connections:

TYWE3S module:

  • GPIO0 - not connected. Must be used to put the ESP in programming mode, by pulling it down to GND;
  • GPIO2 - in the original Tuya firmware is used as debug serial port (TX pin only) and is configured to 74880 8N1. It is one of the two available hardware serial ports in the ESP8266, but it only features a TX output;
  • GPIO4 - it is connected to the blue LED;
  • GPIO5 - apparently not connected to anything;
  • GPIO6 - N/A
  • GPIO7 - N/A
  • GPIO8 - N/A
  • GPIO9 - N/A
  • GPIO10 - N/A
  • GPIO11 - N/A
  • GPIO12 - Relay control - this connects to a GPIO pin on the V9821 chip. The later in turn provides the pulses to actually control the bistable relay;
  • GPIO13 - Push button - should be configured as Button1n in Tasmota, in order to be used to turn on and off the relay (this feature doesn't exist in the original Tuya firmware - hence another advantage of "Tasmotizing" this device);
  • GPIO14 - apparently not connected to anything;
  • GPIO15 - has a physical connection  on the PCB, but not yet clear what its role could have been on the original firmware. Is connected to R10, which is a 3.3 KOhm resistor that pulls to the V9821 analog ground (AVSS pin 4 on this device);
  • GPIO16 - apparently not connected to anything;
  • EN - to enable the ESP8266
  • ADC - provides an analog input to the ESP8266. Apparently not connected to anything;
  • RST - used to reset the ESP8266. Apparently not connected.

  • RSTn - if set to low, causes the V9821 chip to reset. If left as low (i.e. pulled down to GND) causes the chip to remain inactive. It is necessary to leave it in this state while programming the ESP8266, otherwise the serial connection between the two will prevent the external UART (your PC serial port for example) to communicate with the ESP8266.
  • Relay1, Relay2 - these signals originate from the V9821 chip, and are used to control the relay driver, in order to turn the relay on or off;
  • Metering analog inputs - these provide the input signals for metering, namely the small voltage differential from the current shunt, and voltage signal which is provided by a resistive divider, which drops the mains voltage to a value within the spec of the metering chip;

For Tasmota, the correct configuration including also the push button, should therefore be set as:

With the push button configured this way, each button press will toggle the state of the relay, hence causing the power to be turned on or off directly from the device, which is quite useful.


Stargazer said...

You have done an amazing job. As a complete noob I manage to setup my WDS688 within less than an afternoon. I truly hope you manage to find a way to reset the data on the V9821 via a serial command or othwewise, without having to pull the nRst to ground.
Thanks again for your valuable work!

Creation Factory said...

Hi @Stargazer, I am happy that you were able to successfully convert the WDS688 device. At the same time it is useful to have the confirmation of the suspicion that this device was the same hardware as the ZMAi-90.

Nice one!


Stargazer said...

Everything in your guide worked flawlessly
The only thing I can add is that if you set gpio to button it resets the esp and goes back to tasmota pairing mode. So to sum up an answer to your question yes I think they are identical. Is there any other way to reset the data of the V9821?

Creation Factory said...

Hi @Stargazer, regarding the GPIO please make sure you set it to Button1n and not Button1, bacause in the circuit, when pressing the button it pulls down the input and not the opposite.
Regarding the V9821, for programming the main chip, pulling down the RSTn pin was the simplest way I could find, to keep it from talking to the ESP8266. You will always need to disable the chip somehow, because otherwise its pin status will prevent the TX/RX pins of the ESP8266 to talk to another UART. In respect to resetting the data (the energy consumption counter I presume?), there may be a command to reset that register or something, but I haven't yet figured out which. Once the device is converted to Tasmota it is easier for someone to experiment with the commands, sending these through the console, e.g.:

SerialSend5 fe010f080000001c

You may risk messing up the calibration data if you discover such command first, though..

Mark said...


I had the same issue as stargazer, I pressed the button and it reset the wifi. I had mine set to button1n as well. Now I cannot do anything as no matter that tasmota button presses I do, I am getting nothing. Any way I can reset it please and start all over? I tried the press and hold for 40 seconds.. and nothing


Creation Factory said...

Hello Mark, after the reset happens the devices shows up as an Access Point (tasmota-xxx)? Do you get the wifi password captive portal once you select it?


Mark said...

Hello, it came up with the name I gave it and -xxx. So reentered the wifi details etc and it didn't connect. Eventually I did the 40 second press to reset and then, 4 short presses (a few times) and it came back after a while with tasmota-xxx and I configured it and it is all sorted. I just won't press the button again as I really don't need to :)

Unknown said...

THanks for this project its real helpful and got me well underway
the when i tasmotized it with lite and did an upgrade to 8.3.1 then setup the relay, wen i click the toggle button it says on and off bu only changes the www page not the relay im thinking the pins dont do what they did ? and the button just resets the wifi and does not toggle the relay either
welcome any comments

Creation Factory said...

Hi @Unknown, are you setting the GPIOs as described in the screenshot.? From your description it seems like both GPIO12 (wired to the relay) and GPIO13 (input from the push button) might not be correctly configured in the module configuration page. Can you verify?



Unknown said...

they are as per the screen shot, interesting if you press the button it resets the wifi config and possible other config the toggle does nothing

Terence's @rchive said...


Thanks for your great guide

Do you have to calibrate the device after you tasmotize it?


Creation Factory said...

Hi Terence's @rchive,

No, the device calibration data is not affected by this process. In fact it lies in a separate microcontroller which is not touched by this conversion (the Vangotech V9821 metering chip). Only the ESP8266 chip is reflashed with the Tasmota firmware, and no calibration data exists there (it receives the data already calculated and converted to the appropriate units - a task which is performed by the metering chip itself).


fernando said...

Hi, I have tasmotazed a eMylo (clone) with the config of GPIOs in your screenshoot.

But I am receving this in console: {"Reset":"Reset and Restarting"}

I have read this:

Hi, Thanks for completing the template. 👍

In the gpio where you have set the button1, you have connected a pushbutton or a switch?

Tasmota has a feature that if you keep pushed the button1 for more than 40 seconds, tasmota will reset all configs. If you have connected a switch, you should be using a switch as a gpio config and also you should select the switchmode that suits better your use case.

Also, you can disable the reset feature when pushing the button for more than 40 seconds using the following commands in the Tasmota console:

setoption1 1


setoption13 1

Please, tell us if this solves your issue. Thanks


Probaly new version or clone versions have different GPIOs for button?

Creation Factory said...

Hi @fernando,

The mapping between GPIOs and their functions (button, switch, relay, etc) is totally configurable by the user, except for some GPIOs that may have some restrictions (

In the Tasmota web UI, if you go to Configuration > Configure Module, you will be able to select what you want to do with each GPIO.

If in the top you have selected "Generic Module", all the GPIO mappings will be free. The other module types in the dropdown will have predefined mappings that won't appear. This is suitable to use in the case of an ESP8266 module that is part of some off-the-shelf product such as a Sonoff switch, Xiaomi lamp, etc. These are assignments that usually are not interesting to modify, as the GPIOs are already connected permanently (on the PCB) to certain peripherals.

If you are able, please share some photos of the interior of the device. It may be the case that you have a different hardware revision and some pin assignments may be different.

Maybe with some closeup shots of both sides of the main PCB, it can help understand if there are differences.

Thank you.


fernando said...

Hi @Creation Factory,

After sending this post I have found that eMylo is the new version, so I have configured it as TUYAMCU (54)

I have sent another post about other things that are missing (physical button and more data), so my advice to other people is that if you don't work as this web page gpio's config screenshot, try with TUYAMCU module configuration.

Thanks for your quick answer. Let's see if all of us get more things from these new versions. Thans,

Unknown said...

I have the eMylo that I flashed as you described (thx a lot).
I cannot make it work with the button. I have set up the template Tuya MCU (54) and I can turn on/off the relay but when I set the button (GPIO 13) to button n, it resets the device.
With Tasmota 9.1, it seems that web UI changed. Now it is "button_n"!
And by the way, with Tuya MCU device selection, there is no need to run all the console commands you have in your previous post, just run "Backlog TuyaMCU 33,20; TuyaMCU 32,18; TuyaMCU 31,19;"

tesna said...

I want to disable the switch/relay off function so I wont be accidentally shutting down electricity for the entire house. Which line to cut? relay 1 or relay 2?

Creation Factory said...

Hello @tesna,

The relay in this device is a bistable relay. This means that it is either on or off, being energized only for changing its state. The relay1 and relay2 pins provide pulses for controlling the relay (it goes through a driver chip which is in a second board). Pulses applied to one of the pins will turn on the relay, while pulses sent to the other pin will turn off the relay. The metering chip is responsible for converting the on/off states that are sent by the ESP8266 chip GPIO12 pin into pulses for each of these pins (relay1 and relay2), depending on the desired state.

I don't recall which is which (would need to check on the physical device which I don't have at hand).

If you want to be on the safe side, you can disconnect these two pins but first make sure you leave the relay latched in the ON state.

If you simply don't want the software running on ESP8266 from changing the state of the relay, without making hardware changes, you can for example keep GPIO12 deconfigured.

I personally have my ZMAi90 running permanently for over 1 year and simply don't have anything in home assistant configured to send commands to the switch topic, but keep the relay configured in Tasmota. If I ever need to cut the power for some emergency reason, I can go to the Tasmota web UI or manually send a message to the relay topic, and it turns off.

I never had any unintentional shutdown ever since I removed it from Home Assistant configuration.


tesna said...

thank you for taking your time to reply my question :) greatly appreciate it. The real reason need to disable the relay is I dont have the tools and skills (yet) to flash the zmai-90 to tasmota. The stock app has huge button and I already accidentally pressed it once lol.

I ordered another zmai 90 and a raspberry pi and hopefully I will be able to flash tasmota and setup home asssitant on the pi.