Teckin SP32 on ESPHome

Quindor has excellent guide for using $10 WiFi plugs for energy monitoring over on his blog intermit.tech . I ordered 6 of them from Amazon UK but what I received was a slightly different model, the Teckin SP23. These unit run Tuya and need to be converted, but he details the process very well.
However, after flashing them with ESPHome, they barely worked so obviously the internal configuration has changed. After a bit of researh, I got almost everything working except for the red LED, so perhaps someone would kow how to fix this? Also, I got the button on the device to toggle the relay and the blue LED. Here is my config, based on Quindor’s code. You just need to change the plug name at the top:

substitutions:
  plug_name: teckin_plug
  # Higher value gives lower watt readout
  current_res: "0.00221"
  # Lower value gives lower voltage readout
  voltage_div: "940"
esphome:
  name: ${plug_name}
  platform: ESP8266
  board: esp8285
wifi:
  ssid: 'SSID'
  password: 'PASSWORD'
# Enable logging
logger:
# Enable Web server
web_server:
  port: 80
# Enable Home Assistant API
api:
  password: 'PASSWORD'
ota:
  password: 'PASSWORD'
time:
  - platform: homeassistant
    id: homeassistant_time
    
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    name: "${plug_name}_button"
    on_press:
      then:
        - switch.toggle: "${plug_name}_Relay"
        - switch.toggle: "${plug_name}_LED_Blue"
switch:
- platform: gpio
  name: "${plug_name}_Relay"
  id: "${plug_name}_Relay"
  pin: GPIO15
  restore_mode: ALWAYS_ON
- platform: gpio
  name: "${plug_name}_LED_Blue"
  id: "${plug_name}_LED_Blue"
  pin: GPIO2
  inverted: True
  restore_mode: ALWAYS_ON
- platform: gpio
  name: "${plug_name}_LED_Red"
  pin: GPIO4
  inverted: True
  restore_mode: ALWAYS_OFF
sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO05
    cf1_pin: GPIO14
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: "${plug_name}_Amperage"
      unit_of_measurement: A
    voltage:
      name: "${plug_name}_Voltage"
      unit_of_measurement: V
    power:
      name: "${plug_name}_Wattage"
      unit_of_measurement: W
      id: "${plug_name}_Wattage"
    change_mode_every: 8
    update_interval: 10s
  - platform: total_daily_energy
    name: "${plug_name}_Total Daily Energy"
    power_id: "${plug_name}_Wattage"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh
      
# Extra sensor to keep track of plug uptime
  - platform: uptime
    name: ${plug_name}_Uptime Sensor
4 Likes

Have you seen this config?

I saw it linked from here:

Yes, I have thanks. I think I got some of the pin assignments from there. Despite there being an entry for the Red LED, I haven’t got it to work and I now suspect that the internal LED is blue only.

Thank you for posting the ESPHome yaml to work with the uk plug. Without it I would have been stuck with a broken plug. These plugs are great, and thanks to you they work in the uk. I’m already planning on buying another 4 pack of them.

No problem Michael, glad to be of assisance!

1 Like

Hi has anyone got the amps to work on the sp23, I have everything else working but no amp read out my code for power sensor is this

  • platform: hlw8012
    sel_pin:
    number: GPIO12
    inverted: True
    cf_pin: GPIO05
    cf1_pin: GPIO14
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
    name: “${plug_name}_Amperage”
    unit_of_measurement: A
    voltage:
    name: “${plug_name}_Voltage”
    unit_of_measurement: V
    power:
    name: “${plug_name}_Wattage”
    unit_of_measurement: W
    id: “${plug_name}_Wattage”
    change_mode_every: 8
    update_interval: 10s

It’s basically a direct copy from the link above

Any Ideas?

Looks OK to me, apart from the formatting. I presume it validates ok. If you look at the ESPHome logs, do you see current reported like this:

[14:19:16][D][sensor.hlw8012:076]: Got power=0.0W, current=0.0A
[14:19:16][D][sensor.sensor:100]: 'teckin_plug2_Total Daily Energy': Sending state 0.84014 kWh with 3 decimals of accuracy

And do you see Amperage reported on the devices web page?

Yes validates and works

[18:27:06][D][sensor.sensor:100]: ‘teckin_1_Total Daily Energy’: Sending state 1.88102 kWh with 3 decimals of accuracy
[18:27:16][D][sensor.hlw8012:076]: Got power=3.7W, current=0.0A

Amperage is reported but is always 0.0A

It looks fine apart from the amperage, so all I can suggest is to try flashing it again or do you have another one to compare it with.

I’ve got 2 both are the using a similar code and operate the same no amps I’ll try flashing again

Strange, if that doesn’t work can you try flashing with my config above - just change the wi-fi settings.

I compared your code with mine line by line and apart from my logger having level set to verbose the wifi settings including the AP and the relay switches blue led on and off instead of the button the code is the same
I’ve reflashed both plugs and still acting the same in logs both are reading 0.033A one has a 15w bulb on and the other is on washing machine drawing 3.9W in standby
I have had to cycle the wifi after reflashing to get them to connect again

just flashed 2 teckin sp23 plugs with tasmota then esphome. using altered code, relay works but no voltage or wattage reported. had same issue with the tasmota flash so not just with eaphome related.

Have a look at this


It will walk you through setting this plug up and calibrating it
1 Like

Teckin have released a new version of the SP23 UK plug on Amazon UK. It can be identified by the raised lip around the power pins which allows the plug to clear the switch on UK sockets. I got a 4 pack of them this week and sadly, I can confirm that tuya-convert does not work with these plugs. Also, I believe that the power monitoring circuity has been removed. However, the old model is still available but I can’t guarantee that the Tuya firmware hasn’t been updated.
I finally got around to updating my SP23s with the new calibration method, with help from @frenck - the link is in the config. You will need to substitute your own readings as I find they do vary from plug to plug, but I found I didn’t need the lambda function with these:

# Teckin SP23 UK Plug
# GPIO0 = RED LED??
# GPIO02 = Blue LED
# GPIO05 = Power CF Pin
# GPIO12 = Power Sel Pin
# GPIO13 = Button
# GPIO14 = Power CF1 Pin
# GPIO15 = Relay

substitutions:
  plug_name: teckin_plug1

esphome:
  name: ${plug_name}
  platform: ESP8266
  board: esp8285

# WiFi Connection
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable Logging
logger:

# Enable Web Server
web_server:
  port: 80

# Enable Home Assistant API
api:
#  password: 'PASSWORD'
ota:
#  password: 'PASSWORD'

# Sync time with Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time
    
binary_sensor:
  - platform: status
    name: "${plug_name} Status"
  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    name: "${plug_name} Button"
    on_press:
      then:
        - switch.toggle: "${plug_name}_Relay"

switch:
 # Switch to restart the plug
- platform: restart
  name: "${plug_name} Restart"
 # Switch to toggle the relay
- platform: gpio
  name: "${plug_name} Relay"
  id: "${plug_name}_Relay"
  pin: GPIO15
  on_turn_on:
    - switch.turn_on: "${plug_name}_LED_Blue"
  on_turn_off:
    - switch.turn_off: "${plug_name}_LED_Blue"
  restore_mode: ALWAYS_ON
- platform: gpio
  name: "${plug_name} LED Blue"
  id: "${plug_name}_LED_Blue"
  pin: GPIO02
  inverted: True
  restore_mode: ALWAYS_ON
- platform: gpio
  name: "${plug_name} LED Red"
  pin: GPIO0
  inverted: True
  restore_mode: ALWAYS_OFF

sensor:
  - platform: uptime
    name: ${plug_name} Uptime
  - platform: wifi_signal
    name: "${plug_name} WiFi Signal"
    update_interval: 60s
    
  # Power Sensor
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO05
    cf1_pin: GPIO14
    change_mode_every: 3
    update_interval: 3s
    
    # Current Sensor
    # Calibration instructions: https://frenck.dev/calibrating-an-esphome-flashed-power-plug/
    current:
      name: "${plug_name} Amperage"
      unit_of_measurement: A
      accuracy_decimals: 3
      filters:
        # Map from sensor -> measured value
        - calibrate_linear:
            - 0.0 -> 0.0
            - 0.314 -> 0.26
            - 0.623 -> 0.52
        # Make everything below 0.01A appear as just 0A.
        # Furthermore it corrects 0.013A for the power usage of the plug.
#        - lambda: if (x < (0.01 - 0.013)) return 0; else return (x - 0.013);

    # Voltage Sensor
    voltage:
      name: "${plug_name} Voltage"
      unit_of_measurement: V
      accuracy_decimals: 1
      filters:
        # Map from sensor -> measured value
        - calibrate_linear:
            - 0.0 -> 0.0
            - 596 -> 234
            
    # Power Sensor
    power:
      name: "${plug_name} Wattage"
      unit_of_measurement: W
      id: "${plug_name}_Wattage"
      accuracy_decimals: 0
      filters:
        # Map from sensor -> measured value
        - calibrate_linear:
            - 0.0 -> 0.0
            - 348 -> 60.0
            - 690 -> 120.0
        # Make everything below 2W appear as just 0W.
        # Furthermore it corrects 1.14W for the power usage of the plug.
#        - lambda: if (x < (2 + 1.14)) return 0; else return (x - 1.14);

  # Total Daily Energy Used
  - platform: total_daily_energy
    name: "${plug_name} Total Daily Energy"
    power_id: "${plug_name}_Wattage"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh

# Text sensors with general information
text_sensor:
  - platform: version
    name: "${plug_name} ESPHome Version"
  - platform: wifi_info
    ip_address:
      name: "${plug_name} IP Address"
    ssid:
      name: "${plug_name} SSID"
    bssid:
      name: "${plug_name} BSSID"

1 Like

I finally got around to tuya-convert to Tasmota, one of these that I got way back in July - and then upload via the Tasmota captive portal esphome.

I used basically the same config as quoted above - values as sent to home assistant look good, but in esphome logs they’re very strange looking.

I think what should happen is the voltage_divider and current_resistor should maybe be tuned … and then those filters should probably be unnecessary.