In the previous post, I talked about integrating Sonoff wi-fi switch into Home Assistant. Since the Sonoff GPIO pins can be used to control its switch status, I modified my porch light switch and connect it up to a Sonoff. Doing so allows me to turn on or off the porch light through Home Assistant dashboard.
First create a ESPHome Sonoff device “snf_porch_light” and add the following to the configuration (see the previous post for flashing ESPHome firmware).
# Configure Sonoff RX pin (GPIO3) as on/off switch
binary_sensor:
- platform: gpio
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: True
name: "Snf_porch_light Button"
on_state:
- switch.toggle: relayandled
# Setup Sonoff LED (GPIO13) as output
output:
- platform: esp8266_pwm
id: snf_porch_light_led
pin:
number: GPIO13
inverted: True
# Tie Sonoff LED to light component
light:
- platform: monochromatic
output: snf_porch_light_led
id: led
switch:
# Setup Sonoff relay (GPIO12) as a switch component
- platform: gpio
pin: GPIO12
id: relay
# Template to turn relay and LED on/off together
- platform: template
name: "Snf_porch_light Switch"
id: relayandled
optimistic: true
turn_on_action:
- switch.turn_on: relay
- light.turn_on: led
turn_off_action:
- switch.turn_off: relay
- light.turn_off: led
Next I soldered two wires to the Sonoff and connect them to the porch light switch. My Sonoff Basic is the R2 Power V1.0 version which no longer has GPIO14 broken out on the PCB, so I used the RX pin which is GPIO3 to avoid any boot conflict.
DrZzs has an excellent video ‘No $30 “Smart Switch” | $5 Sonoff + REGULAR Light Switch!‘ on how to wire up the Sonoff to a light switch. He describes the wiring between the Sonoff and the light switch beginning from 1:50. In the video, DrZzs uses the breakout connector GPIO14. As mentioned above, I’m using the RX instead of GPIO14. The RX connector is the one next to the square 3.3V connector, shown below connected to the yellow wire:
The wires that are connected to the porch light wall switch are removed, and the switch is now connected to the yellow and green wires. The Sonoff input pins are connected to power lines from the power panel, and the output pins are connected to the wires leading to the porch light.
With snf_porch_light entity added to Home Assistant, the porch light can also be turn on or off either from the wall switch or remotely from Home Assistant dashboard.

