I’ve been slowly amassing a collection of various smart plugs and switches around my house for the purpose of setting up a home automation system. I picked up a single Etekcity ESW01 plug to test out, and was pleasantly surprised to find that it was based on the ESP8266, a very popular and well supported microcontroller. I hadn’t played with home automation in a while, and was excited to see how far it had come. Where previously, I would have had to roll my own firmware, and then write my own integration for Home Assistant, I found that there is now a project called ESPHome which allows you to easily flash ESP8266 and ESP32 devices with a custom firmware, and then integrate them into Home Assistant.
Disassembly
I couldn’t locate any ways to flash the device without opening it up, so I had to take it apart. The two halfs of the device are held together with a few internal clips. I had tried to slide a spudger and an iFixit Jimmy around the crease, but was unable to get it to open. I ended up having to grip one half with a pair of pliers, and apply enough pressure to unclip a few of the clips to get started, and then was able to use the Jimmy to unclip the rest.
Once open, the device is very simple. There are a few PCBs, likely one for high-voltage, one for low-voltage, and one for the ESP8266 ESP-12F.
Flashing
It’s usually recommended to flash the device in a totally powered down state, but I was having issues with power sinking through the rest of the board, so I ended up flashing it in a powered on state. This is NOT recommended, and you should do so at your own risk. To conduct the flashing, I used my Tigard, an FTDI FT2232H-based multi-protocol tool for hardware hacking. I only conneected the TX, RX, and GND pins, as I didn’t need to power the device from the Tigard. For additional isolation, I ran my laptop off of battery power. I also soldered to the GPIO0 pin on the ESP-12F, and briefly connected it to GND to put the device into flash mode.
The wiring was as follows, which was conviently all on the same edge of the ESP-12F:
Tigard | ESP-12F |
---|---|
TX | RX |
RX | TX |
GND | GND |
GND (briefly) | GPIO0 |
Once connected, I used esptool to dump the firmware, and then flashed the ESPHome firmware using the ESPHome web-based flasher I had running in a local Docker container.
1 | # docker-compose.yml |
Once flashed, I was able to connect to the device over WiFi, and configure it using the ESPHome web interface.
Configuration
GPIO Pinout:
Pin | Function |
---|---|
GPIO4 | Relay |
GPIO5 | LED blue |
GPIO12 | HLWBL CF1 Pin |
GPIO13 | HLW8012 CF Pin |
GPIO14 | Button |
GPIO16 | LED yellow |
Initially, I set up a basic switch/relay/light YAML config, based on my own probing around, but after doing some research on this Etekcity plug, I had discovered it has power monitoring capabilities. Rather than reinvent the wheel, I found a blog post (which I can’t seem to locate now), which took GPIO12 and GPIO13, and used them to monitor the power usage of anything plugged in.
I applied the following yaml configuration to the device:
1 | esphome: |
Once the device was configured, I was able to integrate it into Home Assistant, and use it to monitor the power usage of my bedroom lamp as a test.