EFUN SH331W Smart Plug ESPHome Configuration file

Hi,

I am new to Home assistant, wanted to convert my smart plug to ESPHome plug but I didn’t find any “premade” configuration for it.

Here the amazon link if you want to buy them :
https://www.amazon.com/EFUN-Motoring-Required-Appliance-Assistant/dp/B07DCJ7TDR?psc=1&SubscriptionId=AKIAILSHYYTFIVPWUY6Q&tag=duckduckgo-d-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B07DCJ7TDR

It’s based on a ESP8266-S3 ( which is the one made for slotted PCB I believe ).

After reading this page :

I have tweaked it to add the ESP blue led and the proper red led integration.

Enjoy


#Configuration for EFUN SH3331W Smart Plug

substitutions:
  plug_name: esun_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: esp01_1m


wifi:
  ssid: "SSID"
  password: "PASS"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esun Plug Fallback Hotspot"
    password: "1J01nevV4P5p"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "PASS"

ota:
  password: "PASS"

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}_ESP_LED"
    pin: GPIO4
    inverted: True
    restore_mode: ALWAYS_ON
  - platform: gpio
    name: "${plug_name}_LED_Red"
    pin: GPIO0
    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

Thanks for the config! Replying here in Dec 2020 to say Tuya convert still works on some recently bought SH331-s from Amazon.

Any suggestions how best to calibrate a device when given known current and power are measured at multiple points?

I only see the config for a gain (multiplier ) in the current setup.
I don’t know where this value comes from. Do you have data on the current curve ?
( At this moment the plug is used to monitor the christmas tree, so the current consumption isn’t that important :stuck_out_tongue: )

For reference if you need to hack the plug and remove the whole back :

I’m trying to calibrate with a 30W soldering iron that has a rock-solid 30W resistive load that produces a power factor of 1.00.

Yet the numbers coming out the SH331 don’t seem to make sense!

  • amperage: 0.145 A
  • voltage: 133 V
  • wattage: 33.9 W

But 133 V * 0.145 A = 19.3 VA, which is way off the wattage for a resistive load. Any idea what could be going on?

By adjusting current_resistor and voltage_divider I could calibrate two of the three quantities, but not all three. The power and voltage (or current) are computed separately: https://github.com/esphome/esphome/blob/ac15ce576b1c22e59a7186014de0202e79de959b/esphome/components/hlw8012/hlw8012.cpp#L55

Could there be anything else different in these chips that might need tweaking?

Note: The HLW8012 library that Esphome links to has apparently separate multipliers for the three quantities: https://github.com/xoseperez/hlw8012/blob/2dace562c339e77a2889446d461e8e56048fe634/src/HLW8012.cpp#L153

hello all, I have 8 of these I was able to tuya convert, trying to get this config on them but I am getting errors. i am wondering of something changed in esp syntax or maybe it’s just me , I could not YAML my way out of a paper sack

I am getting Dashes are not supported in IDs,

thanks for the help

full config

#Configuration for EFUN SH3331W Smart Plug

substitutions:
  plug_name: efun-01
  # 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: esp01_1m


wifi:
  ssid: "ClanOfRoss"
  password: "megahugeboners"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Efun-01 Fallback Hotspot"
    password: "3doors3whores"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "PASS"

ota:
  password: "PASS"

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}_ESP_LED"
    pin: GPIO4
    inverted: True
    restore_mode: ALWAYS_ON
  - platform: gpio
    name: "${plug_name}_LED_Red"
    pin: GPIO0
    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

Hi Clayton,

FWIW I haven’t changed the YAML config in ~ year, and still seems to be working. Just to confirm that things are still working, I include my yaml here for reference:

# EFUN SH331

substitutions:
  plug_name: efun_01
  # 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: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Efun Fallback Hotspot"
    password: !secret fallback_password

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

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}_ESP_LED"
    pin: GPIO4
    inverted: True
    restore_mode: ALWAYS_ON
  - platform: gpio
    name: "${plug_name}_LED_Red"
    pin: GPIO0
    inverted: True
    restore_mode: ALWAYS_OFF

web_server:

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