Skip to content

Instantly share code, notes, and snippets.

@en4rab
Last active March 27, 2022 23:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save en4rab/6bc83b2c9f850ea29eeaa5f1833a21fd to your computer and use it in GitHub Desktop.
Save en4rab/6bc83b2c9f850ea29eeaa5f1833a21fd to your computer and use it in GitHub Desktop.
Flashing an ENER-J SHA5264 wifi smart plug to Tasmota

Flashing an ENER-J SHA5264 wifi smart plug to Tasmota

After having messed with an unbranded wifi lightbulb I thought I would have a look at a smart socket with energy monitoring. This particular model didn't have an entry on the Tasmota device templates repository nor was it listed as not compatible so I thought I would take a chance on it being ESP8266 based, the screws in the case also suggested it could be opened without damage incase it required serial flashing or a multimeter to work out how the energy monitoring chip was connected which is very helpful and saves destroying a plug for science.

TL;DR

The plug is Tuya based and can be flashed with Tuya-Convert for now, the pinout and device template for this power monitoring plug:

  • GPIO0 Button 1
  • GPIO4 BL0937 CF
  • GPIO5 HLWBL CF1
  • GPIO12 HLWBL SEL_i
  • GPIO13 LED 1
  • GPIO14 Relay 1

{"NAME":"ENER-J SHA5264","GPIO":[32,0,0,0,2720,2656,0,0,2624,288,224,0,0,0],"FLAG":0,"BASE":18}

A peek inside

cover-off

As soon as the Plugs arrived I opened one up to have a peek inside and see if the plug was a candidate to convert to Tasmota. Removing 3 screws and the cover revealed an ESP8285 chip, A Shanghai Belling BL0937 energy meter chip and a power supply consisting of a Silergy SY50282 Buck converter and an AMS1117 regulator

chips

Looking at the back of the PCB reveals test points for 5v, GND, Tx, Rx, RST and GPIO0 so it should be possible to flash this using a serial interface in the event of a problem or Tuya stopping Tuya-Convert from working.

pcb-back

Reflashing the firmware

There were already 2 ENER-J devices listed on the tasmota device templates repository and both of those were listed as Tuya based which suggested that all the ENER-J wifi devices would be based on that platform. So it should be possible to reflash it using a great bit of software called tuya-convert on a raspberry-pi 3 or other linux machine with wifi, this may not be true in the future however as Tuya have updated their firmware to stop you doing this I was lucky and the firmware was an older type that could be converted, the conversion process was:

  • install tuya-convert following the instructions on github
  • run ./start_flash.sh and wait when it says press ENTER
  • Connect your phone or secondary device to the the “vtrust-flash” access point. Make sure to accept any prompts that there is no internet access and you want to stay connected. (aparently this is required)
  • Put the plug in config mode by holding the button on the front for 10 seconds untill the green LED starts flashing
  • Now press Enter, follow the instructions and flash the tasmota firmware
  • The plug will now appear as an access point so connect to this network and open the webpage at 192.168.4.1 and configure the plugs Wi-Fi credentials.
  • Connect back to your network and open the devices webpage and use the firmware upgrade page to upgrade to the latest Tasmota firmware, I had to do this in 2 steps first uploading tasmota-minimal.bin then once it had rebooted repeating this but using tasmota.bin since the plug only has 1Mb flash and the upgrade requires enough free space in flash to store the new firmware before reflashing.
  • Open up the "Configuration" > "Configure Other" page and paste in the Template {"NAME":"ENER-J SHA5264","GPIO":[32,0,0,0,2720,2656,0,0,2624,288,224,0,0,0],"FLAG":0,"BASE":18}
  • Finally calibrate the power monitoring chip I used a toaster and a plug in power meter that showed voltage, current and watts and calibrated the plug to that power meter.
  • Your plug should now work

This isnt really meant to be a how to, more a description of what I did so its possible I missed a step or didnt describe it well so for more information see the tuya-convert and Tasmota documentation for authoritative information on flashing and using Tasmota.

generic-meter

The type of power meter I used to calibrate the plug. I plugged this into the wall, then the smart plug into that and finally the toaster into the smart plug so i could calibrate the smart plug to the energy meter, initally the smart plug was way off reporting a voltage of 294v and a current of 3.9A when the power meter was showing 241V and 3.5A, after calibrating it matched the power meter and showed a power factor of 1.0 which is what you would expect of a toaster which is a purely resistive load.

Woah there where did that template come from

pcb-front

Since this plug can be easily opened without damage I used a multimeter to trace out the connections, annoyingly all the gpio's seem to have 1K current limiting resistors in series so you cant just use continuity check from the power meter chip to the ESP8285, you have to meter from pin to resistor then from the other side of the resistor to the ESP, some time spent squinting at the board and testing continuity gave the connections as:

  • GPIO0 Button 1
  • GPIO4 BL0937 CF
  • GPIO5 HLWBL CF1
  • GPIO12 HLWBL SEL_i
  • GPIO13 LED 1
  • GPIO14 Relay 1

Initally I set GPIO12 as HLWBL SEL but that produced nonsense readings with a voltage of 0V when the plug was switched on as it was reading current as voltage, using the inverted output fixed this. This resulted in a device template of:

{"NAME":"ENER-J SHA5264","GPIO":[32,0,0,0,2720,2656,0,0,2624,288,224,0,0,0],"FLAG":0,"BASE":18}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment