The video and configuration below is for programming SP20 plugs to add to Home Assistant. You can buy these plugs for $10 a piece on Amazon here:
I’ve haven’t yet gotten tuya-convert to work and frankly I enjoy opening these plugs and soldering them. So I just posted a video on how to do it for anyone who’s still uneasy about this. I’m also posting my yaml configuration for programming them with esphome.
Video:
substitutions:
plug_name: energy_1
# Higher value gives lower watt readout
current_res: "0.00221"
# Lower value gives lower voltage readout
voltage_div: "955"
esphome:
name: ${plug_name}
platform: ESP8266
board: esp8285
wifi:
ssid: 'SSIDHERE'
password: 'PASSWORDHERE'
# Enable logging
logger:
# 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:
- platform: gpio
id: "${plug_name}_Relay"
name: "${plug_name}_Relay"
pin: GPIO4
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
then:
- switch.turn_on: "${plug_name}_LED_Red"
on_turn_off:
then:
- switch.turn_off: "${plug_name}_LED_Red"
- platform: gpio
name: "${plug_name}_LED_Blue"
pin: GPIO2
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
id: "${plug_name}_LED_Red"
name: "${plug_name}_LED_Red"
pin: GPIO0
inverted: True
restore_mode: RESTORE_DEFAULT_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