Tag Archives: esp8266

ESPHome TopGreener setup

The TGWF115PRM can be used with ESPHome – the process I used may be somewhat convoluted, but I can confirm it works well and accurately shows power consumption (Watts) through measurement of voltage and current.

Example display in HomeAssistant dashboard

[A note for future readers]

This was written in December 2021. I probably won’t update this in the future – so if you’re reading this sometime far in the future, you may want to look for a newer guide!

Step One

Plug in the device and use Tuya-Convert to load tasmota-lite.bin (see Tuya docs at that link)

Step Two

Make an ESPHome binary (or use mine)

I have the ESPHome integration installed on my Home Assistant server. Select the ESPHome button in the left-side panel in Home Assistant:

Then click on the “Add new device” button, the green circle:

You should name it something useful but short, and you can put in your WiFi info.


The TopGreener smart plug is an ESP8266 device.

Click “EDIT” to change the configuration for your new ESPHome device.

Copy and paste the following configuration into the text window. Makes sure you don’t have duplicate data which was automatically generated. For example you can’t have two esphome, logger, api, ota, or wifi sections. Should be pretty obvious.

  name: splug
  platform: ESP8266
  board: esp01_1m

# Enable logging

# Enable Home Assistant API

  password: "ota_pass"

  ssid: "netgear"
  password: "notmypassword"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Splug Fallback"
    password: "somepw"

  - platform: gpio
    name: "Smartplug Relay"
    pin: GPIO14
    id: relay
  - platform: gpio
    name: "Smartplug Button"
    pin: GPIO03
    - invert:
          min_length: 50ms
          max_length: 350ms
            - switch.toggle: relay
      number: GPIO01
      inverted: true
#      number: GPIO13
#      inverted: true

  - platform: hlw8012
    sel_pin: GPIO12
    cf_pin: GPIO04
    cf1_pin: GPIO05
      name: "Smartplug Current"
      name: "Smartplug Voltage"
      name: "Smartplug Power"
      name: "Smartplug Energy"
    update_interval: 15s
    voltage_divider: 14850
    current_resistor: .0127


Change the details highlighted with red text to the appropriate values.

Step Three

Select “INSTALL”

Then select “Manual Download”
Download the .bin file and save it somewhere safe.

Connect your Tasmota device to your WiFi

But first — You have to now connect to the Tasmota backup hotspot that shows up when you plug in the smart plug and tell it to connect to your wifi router. Open up your phone or laptop and connect to the WiFi AP which shows up as something like: “tasmota-xxxxx

Open up your web browser and you should find a page that has fields such as:

Input your home WiFi AP password and SSID under “AP1”. You can leave the other fields as they are. Click “Save”

Then I had to login to my LAN router to see what IP address was assigned to the new tasmota-0688 device. Unfortunately I wasn’t able to navigate to the device in Firefox. I suspect Tasmota isn’t using mDNS (though my build was a year old — apparently Tasmota has mDNS support now)

So if you have a newer build of Tasmota on your device you can try to navigate to the Tasmota device setup page by going to the url: http://tasmota-nnnn.local/ of course the “nnnn” refers to the ID which is automatically generated. My device in this example gave itself an ID of 0688, so I would attempt to go to http://tasmota-0688.local/ to get to the setup page.

This is from my router’s DHCP info. I had to go here because Tasmota didn’t support mDNS.

BUT anyway I had to login to my router to get the IP address, so I went to (for example): http://192.168.60/

If your browser forces you to go to https then you’ll have to figure out how to turn that off because it will fail.

Upload the bin file to the smart plug

Last step! When you get to the Tasmota setup page, select Firmware Upgrade

Find the .bin file you created earlier from HomeAssistant and upload it to your smart plug device.

You can close that tab, you won’t see that page again.

If this was successful, your ESPHome device should be detected in Home Assistant:

Click “Check it out”:


Select an area to add it to, then FINISH

Back in the Home Assistant Overview page, we see our new device:

A note on Calibration

The ESPHome configuration has two constants for voltage/current calibration. I chose these numbers based on my own measurements and devices. They may be accurate for you, but if not, do not despair. If you attach a known load, such as a 100W incandescent bulb, you can use change these values to fairly accurately reflect the load. If you have a decent way to measure the AC current and AC line voltage, you can do that too.

voltage_divider: 14850
current_resistor: .0127

The “Smartplug2 Voltage” value shows an odd value, 10.5 V, because the Relay is turned off. When we turn it on, with a load, it shows up with the correct value of 117 V

The first step to calibrate the device would be to measure the actual AC line voltage. If I measured 118.2 V I could change the voltage_divider value by multiplying it by the ratio of new/old:

voltage_divider = 14850 * 118.2 / 117.0 = 15002

The same procedure applies to the current_resistor value, except that increasing the current_resistor value will LOWER the measured current, and vice versa. Therefore you have to invert the ratio. If the measured current was 0.36 A then you would set:

current_resistor = 0.0127 * 0.35 / 0.36


I hope this was useful in all or part. I realize going from tuya-convert to Tasmota to ESPHome is not direct, but it happens to be the way I did it for this.


Tasmota TGWF115PRM configuration

Tasmota Documentation


ESP8266 WiFi module

Recently I received some really cheap WiFi modules.

The Wi07C isn’t much more than a little rectangular board with a WiFi chip, flash chip, and copper trace antenna.



The little board on the left is the ESP8266 board. It’s wired to a CP2102 UART to USB bridge and powered by a 5V – 3.3V buck converter I had laying around.

I bought the ESP8266 board from a store in Korea called Electrodragon

Pinout and AT command reference here

I made 5 connections for this demonstration:
VDD to +3.3v
RX to TX on CP2102
TX to RX on CP2102
RST to +3.3v

On my computer I ran a perl script that listens for connections on port 8001 and simply spits out data that it receives. If it receives the text “PING?” then it responds with “OK”

So I connected to the CP2102 UART bridge using Realterm. The baud rate is 57,600. The line endings are CR but CR+LF will work fine.

I sent the following commands to the module to

1. Connect to my WiFi AP
2. Establish a TCP/IP connection
3. Send data
4. Disconnect


Here’s a screen shot of what was echoed back to me on Realterm:


So I actually sent the PING twice. The last character after PING doesn’t matter in my perl script. You can see the second time I sent 7 characters. PING is 4. There’s a space you can’t see, and then CR+LF for a total of 7. The +IPD,3:OK indicates that the host (the perl script) returned 3 characters: “OK” and then a CR character.

I’m impressed that a $4.50 WiFi module does anything at all, but it actually worked without much trouble so I’m very impressed.

I then ran a command that the module didn’t like, and it’s only responding with “busy now …” to any command I send it. I’ll have to toggle the RST line or power in order to reset the device. An acceptable caveat or will this prove to be a persistent problem?

Here’s the perl script I used:



use IO::Socket::INET;

# auto-flush on socket
$| = 1;

# creating a listening socket
my $socket = new IO::Socket::INET (
LocalHost => '',
LocalPort => '8001',
Proto => 'tcp',
Listen => 5,
Reuse => 1
die "cannot create socket $!\n" unless $socket;
print "server waiting for client connection on port 8001\n";

# waiting for a new client connection
my $client_socket = $socket->accept();

# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
print "connection from $client_address:$client_port\n";

# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data\n";

print $data;
# write response data to the connected client

# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data\n";

if($data =~ m/PING.*/){
$data = "OK\n";
} else {
goto shdn;
# write response data to the connected client
print $data;

# close
shutdown($client_socket, 1);