Installing Tasmota firmware for the cheap BSD34 smart socket
I have a lot of computers running at home, all connected to the same plug trough a distributor and I wanted to measure the amount of electricity they consume. I could use a $250 manageable PDU for this purpose, but I found it better to buy a $10 Tuya compatible 16A Smart Plug and flash it with the Tasmota Firmware. In this article I describe, how to do it.
Tasmota is an universal home automation firmware for the ESP8266 based devices, it is fully configurable and it has modules included for handling a lot of different sensors. The smart switch has 3 different type of sensors:
CW R 13 ADC RST
Some explanation:
Tasmota is an universal home automation firmware for the ESP8266 based devices, it is fully configurable and it has modules included for handling a lot of different sensors. The smart switch has 3 different type of sensors:
- two leds
- a button
- a HLW8012 compatible (BL0937) energy monitoring chip
Fortunately all of them are supported out of the box by Tasmota.
Firmware installation
The switch as it comes has the Tuya firmware version 1.1.4 and unfortunately so far it is not possible to install Tasmota over the air (see this thread), so we have to get our hands dirty and solder to the ESP module.
!!!Be very careful with the plug, do not plug it in 220V when it is dissembled, because it can KILL you. During flashing the ESP8285 module will get power from your PC-s USB port trough the FTDI module!!!
To open the case I used combination pliers, just grabbed the top part and pulled away, but some say, they could do it by inserting a screwdriver in the hole and leveraging the upper part.
Rsbob's picture from Github.
When you remove the top then there is a screw in the middle of the PCB you screw that off and then you can pull out the PCB.
Here you will see the AJW-02_8255 module which is an ESP8255 module and on this picture you can see, which connections you have to solder:
PupuJuku's picture from here.
I soldered wires to the 3.3V, GND, RX and TX connections and connected to my 3.3V FTDI module in the following order (from PupuJuku-s blog):
FTDI - ESP8285
GND - GND
3.3V - 3.3V
TX - RX
RX - TX
I did not solder the GPIO0 junction, as it is very small, instead I have soldered a wire to the GND of my FTDI module, and when connecting the module to the USB port, I connected that wire by hand with GPIO0 for about 2 seconds. It is enough to hold it during the startup (powering up the module form USB) as it will put the ESP8285 module into programming mode, you can release it later.
I used an Ubuntu 1804 server machine to upload the new firmware, for doing it I had to install the esptool.py. Earlier I have used the esptool from the normal Ubuntu repository but in this case it was not working so I had to install the "real" esptool.py using the instructions from its Github page.
I did pip install esptool and after that I could start the program with ~/esptool/esptool.py.
Probably because I did not solder the GPIO0 to the ground, after each esptool.py command I had to disconnect USB, ground GPIO0 and connect USB again, to put back the module in flashing mode.
I used the following commands to check the chip, backup the original firmware, erase the flash and install the new firmware.
esptool.py --port /dev/ttyUSB0 flash_id
esptool.py --port /dev/ttyUSB0 read_flash 0x00000 0x100000 image1M.bin
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 tasmota.bin
I used the latest (8.1.0) Tasmota image the, base version.
Configuring the unit
After flashing the Firmware and before desoldering the cables, I restarted the module, by plugging out and in the USB plug of the FTDI module, without grounding the GPIO0. If everything went Ok, you should see a new WiFi network called tasmota-XXXX, without a password and you can connect to it from your phone. After connecting with your web browser go to 192.168.4.1 where you should see a menu.
If you get here, then it is time to desolder the cables and assemble back your switch again.
After assembling it back again, plug it in to a socket, to start the firmware.
Connecting to your home WiFi
With your phone connect again to the tasmota WiFi network and go to 192.168.4.1. Go to Configuration/Configure WiFi add your SSID (or scan for it) and type in your WiFi password. After saving it, the module will restart and connect to your home network.
To continue the setup you need to figure out the DHCP address given to your smart plug, you can get it, by looking into the client list of your WiFi router. Connect to http:/the_address_of_your_plug.
Configuring the module
Now go the the Configure template menu and set it up based on this screenshoot:
You may leave out the GPIO16 LedLink setup, in the switch nothing is connected to GPIO16, but with this setting you can freely use Led2 for custom signals. If you set GPIO16 to None, then Led2 will be used for signalling if the connection to the WiFi network is set up.
GPIO14 is the red led and GPIO1 is the blue led. If you want the communication led to be red just change that to Led2 and GPIO1 to Led1
You can save this configuration, then the LEDs and the power switching will already work.
Calibrating power monitoring
You should do the calibration following this guide:
When you have done it your module is complete and set up 😀
Further possibilities with Tasmota
Beside the WEB interface we have just used, Tasmota can be accessed over MQTT a protocol very often used in home automation and can be accessed via a WEB API. You can integrate it to your own applications or you can integrate it with several Home Automation frameworks.
Personally I plan to integrate it with my Zabbix monitoring system, to have long term monitoring of the energy consumed.
I have already integrated a temperature sensor of our water heater, and it produces charts like this:
AJW-02_8255 PIN configuration
The pins of the AJW-02_8255 are labelled with the following:
Front left to right:
3.3V GND RX TX 12 14
Back in the same physical order
CW R 13 ADC RST
Some explanation:
12,13,14 - GPIO12,13,14 (Relay, Button, red LED)
RST - Reset
CW - GPIO5 (HLW CF1)
R - GPIO4 (HLW CF)
RX - UART RX for programming and GPIO3 (HLW Sel)
RX - UART RX for programming and GPIO3 (HLW Sel)
TX - UART TX for programming and GPIO1 (blue LED)
ADC - Analog input, not used
ADC - Analog input, not used
Comments