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:
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.
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.
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"