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.

Select

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.

esphome:
  name: splug
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "ota_pass"

wifi:
  ssid: "netgear"
  password: "notmypassword"

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

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

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

captive_portal:

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”:

Then “CONFIGURE”

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

Finally

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.

References

Tasmota TGWF115PRM configuration

Tasmota Documentation

Tuya-convert