prefixkit Ask an engineerAsk Support RU

ESPHome devices

Sonoff S31: ESPHome

Sonoff S31 (smart plugs, ESP8266): GPIO pinout and a starter ESPHome config with relays, buttons, LED. Local Home Assistant control with no cloud.

Type
Smart plugs
Chip
ESP8266
Region standard
US

Pinout

PinFunction
GPIO0Push Button (HIGH = off, LOW = on)
GPIO12Relay and its status LED
GPIO13Green LED (HIGH = off, LOW = on)
GPIO1RX pin (for external sensors)
GPIO3TX pin (for external sensors)

Find it in shops: AliExpress

Links open a search in the shop; some are affiliate links: buying through them costs you nothing extra and supports this site. We do not sell devices or get them from manufacturers.

Starter ESPHome config

Built from the pinout above. Keys and the Wi-Fi password come from secrets.yaml in ESPHome. Check the pins against your hardware revision before flashing: one model can ship with different boards.

substitutions:
  name: sonoff-s31

esphome:
  name: ${name}
  friendly_name: "Sonoff S31"

esp8266:
  board: esp01_1m  # most plugs and relays have 1 MB flash; check yours

logger:
api:
  encryption:
    key: !secret api_key
ota:
  - platform: esphome
    password: !secret ota_password
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap: {}
captive_portal:

switch:
  - platform: gpio
    pin: GPIO12
    id: relay1
    name: "Relay"  # Relay and its status LED
    restore_mode: RESTORE_DEFAULT_OFF

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: "Button"  # Push Button (HIGH = off, LOW = on)
    on_press:
      - switch.toggle: relay1

status_led:
  pin:
    number: GPIO13
    inverted: true  # Green LED (HIGH = off, LOW = on)

# Other pins from the pinout:
#   GPIO1: RX pin (for external sensors)
#   GPIO3: TX pin (for external sensors)

How to flash

  • Most devices are flashed over UART: a 3.3 V USB-TTL adapter to RX, TX, GND and 3V3, holding GPIO0 to ground at power-on (ESP8266/ESP32). Mains power disconnected.
  • Beken (BK72xx) and Realtek chips are flashed with ltchiptool, or with cloudcutter without opening the case if the firmware allows it.
  • Details and board photos: the device page in the ESPHome database.

A config from scratch: ESPHome generator. Which pins are safe: pinout.

Similar devices

Idea?