Generic Sonoff

In principle ESPHome supports all Sonoff devices, but as these devices are quite cheap and shipping from China takes a long time, I’ve only set up dedicated guides for the Sonoff S20 and Sonoff 4CH.

esphome:
  name: <NAME_OF_NODE>
  platform: ESP8266
  board: esp8285
  arduino_version: 2.4.2

The selected board and arduino_version are required in v1.14.3 (and probably later), see https://github.com/esphome/issues/issues/931 for details.

After that use the following list of pin to function mappings to set up your Sonoff device. This list has been compiled from the Sonoff Tasmota pin source file which can be found here: https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_template.h ❤️

Sonoff RF

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Green LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

GPIO4

Optional sensor

GPIO14

Optional sensor

Sonoff SV

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Green LED (inverted)

GPIO17

Analog Input

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

GPIO4

Optional sensor

GPIO5

Optional sensor

GPIO14

Optional sensor

Sonoff TH10/TH16

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Green LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

GPIO4

Optional sensor

GPIO14

Optional sensor

GPIO2

Optional Pin EXP-LOG (TH16 Ver 2.1 2019)

Sonoff Dual R1

Pin

Function

GPIO1

Relay #1

GPIO3

Relay #2

GPIO13

Blue LED (inverted)

GPIO4

Optional sensor

GPIO14

Optional sensor

Sonoff Dual R2

Pin

Function

GPIO12

Relay #1

GPIO5

Relay #2

GPIO10

Button

GPIO13

Blue LED (inverted)

GPIO4

Optional sensor

GPIO14

Optional sensor

Sonoff Dual R2 v1.4

Pin

Function

GPIO00

Button #0(inside header board v1.4)

GPIO09

Button #1(inside header board v1.4)

GPIO12

Relay #1

GPIO5

Relay #2

GPIO10

Button on the case

GPIO13

Blue LED (inverted)

Sonoff Pow R1

(equivalent to Huafan SS)

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO15

Blue LED

GPIO5

HLW8012 SEL Pin

GPIO13

HLW8012 CF1 Pin

GPIO14

HLW8012 CF Pin

See HLW8012 Power Sensor for measuring power.

Sonoff Pow R2

(equivalent to Huafan SS)

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Blue LED (inverted)

See CSE7766 Power Sensor for measuring power.

Sonoff S20, Sonoff S22, Sonoff S26

See Using With Sonoff S20.

Slampher

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Blue LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

Sonoff Touch

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Blue LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

Sonoff LED

Pin

Function

GPIO0

Button (inverted)

GPIO13

Blue LED (inverted)

GPIO5

Red Channel

GPIO4

Green Channel

GPIO15

Blue Channel

GPIO12

Cold White Channel

GPIO14

Warm White Channel

See RGBWW Light for controlling the lights together with ESP8266 Software PWM Output.

ElectroDragon

Pin

Function

GPIO2

Button 1 (inverted)

GPIO0

Button 2 (inverted)

GPIO13

Relay 1 and Red LED

GPIO12

Relay 2 and Red LED

GPIO16

Green/Blue LED

GPIO17

Analog Input

Sonoff SC

Pin

Function

GPIO12

Light

GPIO13

Red LED (inverted)

See Monochromatic Light and ESP8266 Software PWM Output for controlling the light pin.

Sonoff 4CH Pro

Same configuration as the Sonoff 4CH.

Sonoff B1, Ai-Thinker AiLight

See MY9231/MY9291 LED driver.

Sonoff T1, Sonoff T3 (1CH, 2CH, 3CH)

Pin

Function

GPIO0

Button 1 (inverted)

GPIO12

Relay 1 and Blue LED

GPIO9

Button 2 (inverted)

GPIO5

Relay 2 and Blue LED

GPIO10

Button 3 (inverted)

GPIO4

Relay 3 and Blue LED

GPIO13

Blue LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

Arilux LC10, Magic Home

Pin

Function

GPIO2

Blue LED

GPIO14

Red Channel

GPIO5

Green Channel

GPIO12

Blue Channel

GPIO13

White Channel

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

See RGBW Light for controlling the lights together with ESP8266 Software PWM Output.

Arilux LC01

Pin

Function

GPIO0

Button (inverted)

GPIO2

Blue LED

GPIO5

Red Channel

GPIO12

Green Channel

GPIO13

Blue Channel

GPIO14

White Channel

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

See RGBW Light for controlling the lights together with ESP8266 Software PWM Output.

Arilux LC02

Pin

Function

GPIO0

Button (inverted)

GPIO2

Blue LED

GPIO5

Red Channel

GPIO14

Green Channel

GPIO12

Blue Channel

GPIO13

White Channel

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

See RGBW Light for controlling the lights together with ESP8266 Software PWM Output.

Arilux LC11

Pin

Function

GPIO0

Button (inverted)

GPIO2

Blue LED

GPIO5

Red Channel

GPIO4

Green Channel

GPIO14

Blue Channel

GPIO13

Cold White Channel

GPIO12

Warm White Channel

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

See RGBWW Light for controlling the lights together with ESP8266 Software PWM Output.

Sonoff S31

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Green LED (inverted)

See CSE7766 Power Sensor for measuring power

Sonoff S55

Pin

Function

GPIO0

Button (inverted)

GPIO12

Relay and Red LED

GPIO13

Blue LED (inverted)

GPIO1

UART TX pin (for external sensors)

GPIO3

UART RX pin (for external sensors)

Sonoff Mini

Pin

Function

GPIO0

Button (inverted)

GPIO4

SW Input (inverted)

GPIO12

Relay and Red LED

GPIO13

Blue LED (inverted)

GPIO16

Optional sensor

Shelly 1

Pin

Function

GPIO4

Relay

GPIO5

SW Input

Shelly 2

Pin

Function

GPIO4

Relay #1

GPIO5

Relay #2

GPIO12

SW Input #1

GPIO14

SW Input #2

Teckin

Pin

Function

GPIO1

Button (inverted)

GPIO3

Blue LED (inverted)

GPIO13

Red LED (inverted)

GPIO14

Relay

GPIO12

HLW8012 SEL Pin (inverted)

GPIO4

HLW8012 CF Pin

GPIO5

HLW8012 CF1 Pin

See HLW8012 Power Sensor for measuring power. Example config: teckin.yaml

Teckin SP20 (US)

Pin

Function

GPIO13

Button

GPIO2

Blue LED (inverted)

GPIO0

Red LED (inverted)

GPIO4

Relay

GPIO12

HLW8012 SEL Pin (inverted)

GPIO5

HLW8012 CF Pin

GPIO14

HLW8012 CF1 Pin

See HLW8012 Power Sensor for measuring power. Example config: teckin_sp20_us.yaml

TorchStar LED Controller (Nov 2018)

Pin

Function

GPIO13

Button (inverted)

GPIO16

Blue LED (inverted)

GPIO4

Red LED (inverted)

GPIO14

Red Channel

GPIO12

Green Channel

GPIO5

Blue Channel

GPIO15

White Channel

See Also