Making my light switches “smart” used to be such a cumbersome task which required me to flash a Sonoff Mini with ESPHome, connect it to a momentary switch and, stuff it in the electrical box. It worked, but as you could imagine, this didn’t bode well as far as troubleshooting was concerned.
I was tired of that implementation and decided to go a different route once I moved into my new apartment. I came across these Tuya-based smart light switches made by GoSund.
Gosund Smart Light Switch
These smart light switches give you the power to automatically or remotely access and control which devices are switched on/off. The smart switch supports wireless connection via a 2.4G Wi-Fi network and can be controlled via a free smartphone app. The biggest selling points were the following:
- Easy firmware flashing with no soldering
- Included screwless faceplates
- Works with 2+ gang Decora faceplates
- Screws instead of clips to secure it in the wall
- All in one cost-effective solution
Setup
Setting these up to run ESPHome isn’t as straightforward as it is to set them up with Tasmota. In fact, we’ll need to flash them with Tasmota first, and then flash them with ESPHome firmware.
Go ahead and open up the switch using a T6 Torx screwdriver. You will then find the circuit board, which is where the fun begins.
Because these switches had contact pads instead of via holes, I need to find a way to get an FTDI USB adapter wired to the board.
So I went ahead and designed a jig that would align some Pogo Pin Test Probes to the individual contact pads. You can find it on Thingiverse. It’s not the best, but it does its job.
You may need to hold the jig in place or perhaps use some tape to keep the contact still. Plug your Dupont connectors into your FTDI adapter of choice, then plug it into USB power of your computer. You should see the light on your switch turn on and flash several times. This is a good sign as your switch is now initiating pairing mode or “SmartConnect”.
Flashing Firmware
Flashing the firmware is a two-step process. You will first flash with Tasmota. Once flashed, you’ll use it’s UI to flash the ESPHome .bin file.
Flash the firmware
Before you begin you’ll need:
- One of the Linux machines listed below:
- A Raspberry Pi model B with the latest version of Raspbian Stretch Lite (Recommended Method).
- A raspberry pi model B+ with a USB wifi dongle and Kali Linux.
- A micro SD Card for your raspberry pi (at least 2gb, 8+ recommended).
- A wifi device that can connect to the SSID that will be generated by the raspberry pi and eventually the flashed tuya device. This cannot be an iOS device, android devices will work.
Installing the OS on Raspberry Pi:
- Download and install Etcher
- Plug your microSD card into your PC using a microSD adapter
- Start Etcher.
- Select the disk image you downloaded and your microSD card from the etcher interface.
- Press Flash and wait.
- Add a blank file called
ssh
to the root of the Raspberry Pi to enable the SSH service on Raspbian. - Plug the SD card into your raspberry pi, connect power and ethernet, and boot it up.
Connecting to your raspberry pi via SSH:
- Download and install Putty
- Start Putty.
- Enter the IP address of your Raspberry Pi in the box that says
Host Name
. I recommend using an app like Fing to find the IP address of your Raspberry Pi. - In the
Saved Sessions
input box, name your Raspberry Pi connection and then press “save”. - Select your new saved session.
- Press
Open
Setting up your Pi and updating the OS
- In the putty window log in with user
pi
and passwordraspberry
- Expand the file system by typing
sudo raspi-config
then selectingAdvanced Options
and thenExpand Filesystem
, select “Finish” and then selectYes
when it asks to reboot. - Reconnect via putty using your saved session and log in with username
pi
and passwordraspberry
again. - Type
sudo apt-get update
and wait for the updates to install - Type
sudo apt-get dist-upgrade
and wait for the upgrades to install- You may get a prompt for permission, just type
y
and press enter.
- You may get a prompt for permission, just type
- Type
sudo apt-get install network-manager
and wait for it to install. - Type
sudo apt install git
and wait for it to install.
Setup and Install Tuya-Convert
- In the putty window type
git clone https://github.com/ct-Open-Source/tuya-convert
press enter and wait. - Type
cd tuya-convert
and press enter. - Type
./install_prereq.sh
and wait.
Use Tuya-Convert to install Tasmota
- Type
cd tuya-convert
and press enter. - Type
./start_flash.sh
. - Types
yes
and press enter. - Connect your separate WiFi device to the
vtrust-flash
SSID that is being broadcast by your Raspberry Pi. There should be no password, but if there is somehow one, it should beflashmeifyoucan
. - Plug in your Tuya plug, switch, dimmer, or bulb and put it into pairing mode.
- Different models are put into pairing mode via different methods, check the curated product pages for information for putting your device in pairing mode. The LED should flash rapidly if done successfully.
- Press enter on your putty window to start the flash process and wait.
- Once the process completes you can type
curl http://10.42.42.42/flash3
to install Tasmota or look at the other options available.
Setup Tasmota
- On your secondary device, disconnect from
vtrust-flash
and connect to the new SSID calledtasmota-XXXX
- Open
192.168.4.1
in your browser and enter your WiFi’s SSID and password. - Use Fing or your router’s settings to find your new device on your WiFi network, it should be called
tasmota-XXXX
- Open the IP address of your new device in a browser.
- Navigate to console and enter
SetOption78 1
which allows you to flash non-Tasmota based firmware/binary files. - Head over to the Firmware Upgrade page and flash your ESPHome binary.
ESPHome Configuration
esphome: name: gosund_guest_bathroom_light platform: ESP8266 board: esp01_1m substitutions: entity_name: "Guest Bathroom Light" entity_id: "gosund_guest_bathroom_light" wifi: ssid: !secret WIFI_SSID password: !secret WIFI_PASS # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Gosund Guest Bathroom Light" password: !secret FALLBACK_AP_PASS captive_portal: # Enable logging logger: # Enable Home Assistant API api: password: !secret OTA_API_PASS reboot_timeout: 0s ota: password: !secret OTA_API_PASS # used just for testing, otherwise no need for it web_server: port: 80 ############################## # Config ############################## status_led: pin: number: GPIO01 inverted: true binary_sensor: - platform: gpio id: button pin: number: GPIO0 mode: INPUT_PULLUP inverted: true on_press: then: - light.toggle: $entity_id - platform: status name: "$entity_name status" output: - platform: gpio id: relay pin: GPIO14 light: - platform: binary id: $entity_id name: $entity_name output: relay sensor: - platform: wifi_signal name: "$entity_name WiFi signal" update_interval: 60s - platform: uptime name: "$entity_name uptime" text_sensor: - platform: version name: "$entity_name ESPHome version"