ESPHome and Hyleton 313 Smart Plug

I need some help on ESPHome configuration for the Hyleton 313 Smart Plug. @Beantree posted a nice teardown and Tasmota instructions here 313.

I’ve managed to flash ESPHome on the Hyleton 313, it’s online on WiFi and OTA firmware upload is working. @beantree identifies the pins as follows:

Module pin ESP8266 pin Pin name Pin name ESP8266 pin Module pin
1 7 Chip Enable Tout (ADC) 6 2
3 9 MTMS / GPIO14 MTDI / GPIO12 10 4
5 12 MTCK / GPIO13 MTDO / GPIO15 13 6
7 15 GPIO0 GPIO2 14 8
9 16 GPIO4 GPIO5 24 10
11 25 U0RXD U0TXD 26 12
13 Vdd - - GND 14

I’ve tried to adapt the Sonoff S20 example s20 on esphome.io by swapping at pin assignments to–I think–the appropriate pins on the H313. Everything shows in HA, but nothing actually works.

This is my first time trying to configure a switch in ESPHome and my first time using the ESPHome API instead of MQTT. I’m also unsure whether I’ve got the GPIO mapping right.

My ESPHome configuration file is below.

Any help much appreciated.

substitutions:
  devicename: socket_consumer_unit_cupboard
  staticip: 192.168.xxx.xxx
  switchgpio: GPIO0
  switchname: "Consumer Unit Cupboard Switch"
  binarysensorgpio: GPIO12
  binarysensorname: "Consumer Unit Cupboard Switch Sensor"
  binarysensorstatusname: "Consumer Unit Cupboard Switch Status"
  ledgpio: GPIO13
  ledid: consumer_unit_cupboard_switch_led
  lightname: "Consumer Unit Cupboard Switch Green LED"

esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  manual_ip:
    static_ip: $staticip
    gateway: 192.168.xxx.xxx
    subnet: 255.255.255.0

# Enable logging
logger:

# Enable ESPHome API
api:

# Enable OTA firmware update
ota:

binary_sensor:
  - platform: gpio
    pin:
      number: $binarysensorgpio
      mode: INPUT_PULLUP
      inverted: True
    name: $binarysensorname
    on_press:
      - switch.toggle: relay
  - platform: status
    name: $binarysensorstatusname

switch:
  - platform: gpio
    name: $switchname
    pin: $switchgpio
    id: relay

output:
  # Register the green LED as a dimmable output ....
  - platform: esp8266_pwm
    id: $ledid
    pin:
      number: $ledgpio
      inverted: True

light:
  # ... and then make a light out of it.
  - platform: monochromatic
    name: $lightname
    output: $ledid

In case anyone else is looking to set up a Hyleton 313 with ESPHome, here is a basic configuration that works. I haven’t bothered with the LED.

# Substitutions
substitutions:
  devicename: socket_consumer_unit_cupboard
  staticip: 192.168.xxx.xxx
  buttongpio: GPIO13
  buttonid: consumer_unit_cupboard_button
  binarysensorstatusname: "Consumer Unit Cupboard Status"
  binarysensorgpio: GPIO12
  binarysensorname: "Consumer Unit Cupboard Switch Sensor"
  switchgpio: GPIO15
  switchname: "Consumer Unit Cupboard"

esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m

# Enable WiFi
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  manual_ip:
    static_ip: $staticip
    gateway: 192.168.xxx.xxx
    subnet: 255.255.255.0

# Enable logging
logger:

# Enable ESPHome API
api:

# Enable OTA firmware update
ota:

binary_sensor:
  - platform: gpio
    pin:
      number: $buttongpio
      mode: INPUT_PULLUP
      inverted: True
    id: $buttonid
    on_press:
      - switch.toggle: relay
  - platform: status
    name: $binarysensorstatusname

switch:
  - platform: gpio
    name: $switchname
    pin: $switchgpio
    id: relay

First time esphome user here also, i managed to get the leds working with the following;

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      mode: INPUT_PULLUP
      inverted: True
    name: "${plug_name}_button"
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    name: "${plug_name}_relay"
    pin: GPIO15
    id: relay
    on_turn_on:
      - switch.toggle: ledblue
      - switch.toggle: ledred
    on_turn_off:
      - switch.toggle: ledblue
      - switch.toggle: ledred
  - platform: gpio
    name: "${plug_name}_led_red"
    pin: GPIO0
    inverted: True
    restore_mode: ALWAYS_ON
    id: ledred
  - platform: gpio
    name: "${plug_name}_led_blue"
    pin: GPIO2
    inverted: True
    restore_mode: ALWAYS_OFF
    id: ledblue
1 Like

I’m trying to flash a Hyleton 313 outlet using tuya-convert (on a rpi), but it doesn’t seem to be working. Can anyone share your experience with getting it to flash.

My steps:

  1. ~/tuya-convert#./start_flash.sh
  2. yes (Enter)
  3. connect to vtrust-flash with my phone
  4. turn on the H313, press the button for ~5 sec until I hear the click, release button
  5. hit Return at the prompt in tuya-flash at which point the dots start crossing the screen

My problem is that the dots keep going line after line and nothing happens. Are my steps correct in getting the H313 in flashing mode?

I did scan the network using phone and the H313 has an IP of 10.42.42.34 instead of 42?

Finally got around to trying this for the LED, and it works perfectly. Thanks.

Have you already registered the socket in the Tuya app. If not, try just plugging the socket in and following the tuya_convert procedure. That worked for me on two plugs so far.

I followed the tuya-convert procedure, but it never gets to the step where it backs up the firmware; I get to the step just before that (hit Enter and dots scroll across the screen, but it never does the firmware backup). How exactly did you get the plug into flash mode?

Also, I don’t have the tuya app, so I haven’t connected the device to the official app.

Try it without pressing the button at all. Just plug in the socket and start the tuya-convert sequence. Mine went into discovery mode automatically and were picked up after a short time.

Yes, I tried this (plugging it in without pressing the button) and let it set for 15 minutes, it never flashed. I just read the following on the tuya-convert GitHub page, this is probably what’s happening since I just ordered my plug about 2 weeks ago.

As of January 28th, 2019, Tuya has started distributing a patch that prevents tuya-convert from completing successfully. It is up to the individual brands to adopt the patch, so some devices may be affected sooner than others. To ensure the best chance of success, do not connect your device with the official app as it may automatically update the device, preventing you from flashing with tuya-convert. Some devices are already being shipped with the update, in which case there is unfortunately no work around available at this time.

Possibly you’re unlucky with the patch. 5 Hyleton 313 plugs that I bought from Amazon.co.uk in the past week all worked. However, I also ended up with some patched plugs from another brand.

I was unaware of tuya-convert when I bought the very first Hyleton a couple of months ago that prompted my first post in this chain. You could always open it up and solder leads on to flash as per the link in my first post. I’m certainly not the world’s best with a soldering iron. It was fiddly to do but worked.

After reading the logs (something I should have done earlier), I found that there was some tornado module missing - I think this is a python thing. Anyway, ran the following command, rebooted, followed the tuya-convert instructions, and it worked. Tuya-convert downloaded the firmware, then I was able to upload my binary file.

sudo python3 -m pip install paho-mqtt pyaes tornado

found here

1 Like