HELOB PLUGB

Overview

HELO PLUGB

A plug with a socket output switched by a relay and 2x USB outputs switchable with a separate relay.

Pinout

TYWE3S

The TYWE3S is a ESP8266-based module made by Tuya and very similar to the Espressif ESP-12 series modules. It has the same dimensions and nearly the same pinout.

Pin
GPIO0Button (strapping pin, boot mode)
GPIO2Unused
GPIO4BL0937 CF
GPIO5HLWBL CF1
GPIO12HLWBL SELi
GPIO13status_led (inverted)
GPIO14Relay for socket
GPIO15Relay for USB
GPIO16Unused

Flashing

Tools:

  • Triangular bit.
  • Soldering iron.
  • USB TTL/RS232/UART/Serial adapter (3,3V). I have a CP2102.

To flash the module we need to power it up with and connect to UART serial with TX and RX and boot into flashing mode by pulling GPIO0 to LOW1.

Both 3v3 and GND are available on the JST connector and trace back to the ESP8266 module headers, but it doesn’t seem to be possible to power up the module by connecting to them on the JST connector (voltage regulator?).

Connecting to 3V3 and GND on the module works and powers it up.

The button on these plugs is connected to GPIO04 and pulls LOW when pressed. So just hold down the onboard button while powering the USB-serial adapter on to boot into flashing mode.

Solder to the RX, TX, 3V3 and GND pins and then wire it up to a USB-serial module. Either hold the onboard button down or connect GPIO0 to GND and power on the USB-serial module.

When only the red LED lights up, the board is in bootloader mode and can be flashed4.

ESPHome config

This config is largely based on the config on the ESPHome Device registry page4 for the HELO-PLUGB-EU.

Configure the esp8266 platform for TYWE3S, using board id esp01_1m3:

esp8266:
  board: esp01_1m
  framework:
    version: recommended
  restore_from_flash: true
  board_flash_mode: dout

light:
  - platform: status_led
    name: "Status LED"
    id: esphome_status_led
    icon: "mdi:alarm-light"
    restore_mode: ALWAYS_OFF
    pin:
      number: GPIO13
      inverted: true

I found that the heloplugb_voltage_div, heloplugb_current_res and heloplugb_current_mul values were accurate, and did not need to adjust them. Compared the sensor readings for the same loads on the PLUBG plugs and Aeotec Z-Wave plugs.

substitutions:
  heloplugb_restore_mode_socket: "ALWAYS_OFF"
  heloplugb_restore_mode_usb: "RESTORE_DEFAULT_ON"
  # Lower value gives lower voltage readout. Calibrate for higher accuracy.
  heloplugb_voltage_div: "1655.66630552546"
  # Higher value gives lower watt readout. Calibrate for higher accuracy.
  heloplugb_current_res: "0.00092"
  # Muliplier for current sensor filter. Calibrate for higher accuracy.
  heloplugb_current_mul: "0.914285714285714"

Set up switch entities for the both the socket and the USB ports (on the sides of the plug):

switch:
  - platform: output
    name: Socket
    id: heloplugb_switch_socket
    icon: mdi:power-socket-de
    restore_mode: "${heloplugb_restore_mode_socket}"
    output: heloplugb_output_socket

  - platform: output
    name: USB
    id: heloplugb_switch_usb
    icon: mdi:usb-port
    restore_mode: "${heloplugb_restore_mode_usb}"
    output: heloplugb_output_usb

output:
  - platform: gpio
    pin: GPIO14
    id: heloplugb_output_socket
  - platform: gpio
    pin:  GPIO15
    id: heloplugb_output_usb

These should also work equally well by using the gpio platform for the switch component. I just re-used the example.

Set up a simple gpio platform binary_sensor component for the onboard button. The ESPHome device registry example contained an excellent on_multi_click to use long presses to toggle the USB ports with:

binary_sensor:
  - platform: gpio
    name: Button
    pin: GPIO0
    id: heloplugb_button
    filters:
      - invert:
      - delayed_off: 10ms
    on_multi_click:
      # Short press to toggle socket relay
      - timing:
          - ON for at most 1s
        then:
          - lambda: |-
              id(heloplugb_switch_socket).toggle();
      # Long press to toggle USB power output
      - timing:
          - ON for at least 1s
        then:
          - lambda: |-
              id(heloplugb_switch_usb).toggle();

The power monitoring sensor is a BL0937, which is supported by the hlw8012 sensor platform5 in ESPHome.

I've enabled all of the sensors in the platform (current, voltage, power and energy) and set up filters to keep the flow of measurements in check while still updating fast:

sensor:
  - platform: hlw8012
    model: BL0937
    sel_pin:
      number: GPIO12
      inverted: true
    cf_pin: GPIO4
    cf1_pin: GPIO5
    change_mode_every: 4
    update_interval: 10s
    initial_mode: VOLTAGE
    current:
      name: Current
      id: heloplugb_current
      device_class: current
      state_class: measurement
      unit_of_measurement: A
      accuracy_decimals: 2
      filters:
        - multiply: ${heloplugb_current_mul}
        - round: 2
        - or:
          - delta: 0.01
          - throttle_average: 30min
    voltage:
      id: heloplugb_voltage
      name: Voltage
      device_class: voltage
      state_class: measurement
      unit_of_measurement: V
      accuracy_decimals: 0
      filters:
        - round: 2
        - or:
          - delta: 1.5
          - throttle_average: 30min
        - round: 0
    power:
      id: heloplugb_power
      name: Power
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      accuracy_decimals: 1
      filters:
        - round: 1
        - or:
          - delta: 0.5
          - throttle_average: 30min
    energy:
      id: heloplugb_energy
      name: Energy
      device_class: energy
      state_class: measurement
      unit_of_measurement: kWh
      accuracy_decimals: 2
      filters:
        - lambda: |-
            return x/1000.0;
        - round: 2
        - or:
          - delta: 0.1
          - throttle: 60min
    current_resistor: ${heloplugb_current_res}
    voltage_divider: ${heloplugb_voltage_div}

I've configured some template platform binary_sensors to trigger if the load or current draw get too high, turning off the socket (and USB).

The plug is rated for and . I configured safety margins of and because that made sense to me, adjust as needed.

.heloplugb_safety: &heloplugb_safety
  device_class: safety
  on_press:
    - lambda: |-
        id(heloplugb_switch_socket).turn_off();
        id(heloplugb_switch_usb).turn_off();

binary_sensor:
  - platform: template
    name: Overcurrent
    id: heloplugb_overcurrent
    lambda: |-
      float rated_current = 16.0;
      float safety_margin = 1.0;
      float overcurrent = rated_current - safety_margin;
      if (id(heloplugb_current).has_state()) {
        return id(heloplugb_current).state >= overcurrent;
      }
      else {
        return {};
      }
    <<: *heloplugb_safety

  - platform: template
    name: Overload
    id: heloplugb_overload
    lambda: |-
      float rated_load = 3680.0;
      float safety_margin = 180.0;
      float overload = rated_load - safety_margin;
      if (id(heloplugb_power).has_state()) {
        return id(heloplugb_power).state >= overload;
      }
      else {
        return {};
      }
    <<: *heloplugb_safety

  - platform: template
    name: Undervoltage
    id: heloplugb_undervoltage
    lambda: |-
      float undervolt = 219.0;
      if (id(heloplugb_voltage).has_state()) {
        return id(heloplugb_voltage).state < undervolt;
      }
      else {
        return {};
      }
    <<: *heloplugb_safety

There is also a safety sensor for Undervoltage, since if the voltage at your house drops suddenly well below , something is probably wrong.

References