My quest on flashing custom firmwares and controlling budget switches sold at Action discount store continues!
Recently, Action started selling a big amount of LSC Smart Connect devices that are compatible with Google Home and Alexa. These devices are so called 'Tuya' devices that work with a cloud service but can be easily flashed. I quickly got one and decided to give it a go.
Initially, I set out to flash it directly on the chip using an FTDI adapter but when opening it up, quickly realised that would be a big hassle.
These switches use the TYWE2S chip which is an ESP8285 based chip making it compatible with Tasmota and ESPHome.
In order to flash this chip you need to ground a pin to GPIO0 as outlined in this wiki page.
The technical sheet for this chip is available here.
Take note of the following GPIO pinout, which you need for a reference in ESPHome / Tasmota:
gpio 4 is LED (0 = on) gpio 12 is relay (1 = on) gpio 14 is switch (0 = pressed)
Some smart people figured out a loophole in the SSL handshake that made this devices able to flash using just a terminal and a mobile phone.
Unfortunately, Tuya issued a patch in January that stopped this software hack from working.
IN ANY CASE, DO NOT CONNECT THE SWITCH TO THE OFFICIAL TUYA OR LSC APP. THIS WILL DOWNLOAD THE LATEST STOCK FIRMWARE TO THE DEVICE AND POSSIBLY MAKE IT UNFLASHABLE AGAIN.
Luckily, some other smart people figured out another workaround with tuya-convert and as of September/October, tuya-convert can be used again to flash these switches!
Using tuya-convert to flash
The steps to flash firmware onto the switch are very simple, you only need a Linux machine with a wireless chip (like a Raspberry Pi Zero W), a mobile phone (I had better results with Android) and physical access to the switch's button.
Steps below all performed on a RPi Zero W, using a wired ethernet connection and SSH
$ sudo apt install git $ git clone https://github.com/ct-Open-Source/tuya-convert $ cd tuya-convert $ ./install_prereq.sh $ ./start_flash.sh
Follow the instructions displayed on screen. tuya-convert will automatically back up the stock firmware so you can flash it again if you'd want to. I copied it over using scp to my laptop, just in case.
A binary for Tasmota is included in the tuya-convert project, but ESPhome is not MQTT based, nicer looking, has a better API and integrates seamlessly with Home Assistant.
Figuring out how the config should look was rather difficult since I initially based myself on a blogpost from frenck.dev but found that the default Sonoff S20 config worked better. The config below is the one I used for flashing.
esphome: name: lsc_smart_connect_node_bedroom platform: ESP8266 board: esp01_1m wifi: ssid: !secret wifi_ssid password: !secret wifi_password api: logger: ota: binary_sensor: - platform: status name: "LSC Smart Connect Bedroom Status" output: - platform: esp8266_pwm id: led pin: number: GPIO4 inverted: true light: - platform: monochromatic id: status_led name: "LSC Smart Connect Bedroom Light" output: led switch: - platform: gpio id: relay pin: GPIO12 - platform: template name: "LSC Smart Connect Bedroom Relay" optimistic: true id: relay_and_light turn_on_action: - switch.turn_on: relay - light.turn_on: status_led turn_off_action: - switch.turn_off: relay - light.turn_off: status_led
You can not use ESPHome to flash using a UART connection or OTA, instead you need to create a binary and put it on the machine that flashed using tuya-convert and flash that binary to the LSC switch.
- /home/pi/tuya-convert is where you checked out the git repo for tuya-convert
- The binary has to be renamed to
thirdparty.binand has to be in the
# On my laptop which has ESPHome installed: $ esphome lsc_smart_connect_switch.yaml compile $ scp lsc_smart_connect_switch/.pioenvs/lsc_smart_connect_switch/firmware.bin firstname.lastname@example.org:/home/pi/tuya-convert # On the Raspberry Pi Zero that flashed using tuya-convert $ mv /home/pi/tuya-convert/firmware.bin /home/pi/tuya-convert/files/thirdparty.bin $ curl http://10.42.42.42/flash3 > Device should flash http://10.42.42.1/files/thirdparty.bin and restart
Now wait a few seconds until the device pops up as
lsc_smart_connect_switch.local on your network, which means it worked. Then quickly check Home Assistant and voila!:
You can now use the relay to toggle the switch on and off.
Some finishing notes:
I did not manage to make the LED respond to the relative switch state. It's possible, I just don't know how.Oli helped me and gave me a working config for the LED!
- Do NOT configure a button in ESPHome/Tasmota for the hardware button. Doing this will make the switch auto reset to the firmware stored on the chip every time.
- This was trial and error, I also completely bricked a switch when trying to flash, luckily they're only 8.95 EUR.
- Unfortunately, these do not offer power measurement like their counterpart GOSUND switches sold by Amazon. GOSUND can also be flashed by tuya-convert until Tuya issues another patch.
- I did not test reflashing a device again using the same tuya-convert method, nevertheless if you flashed it with ESPHome you should be able to just flash an updated firmware using ESPHome's OTA method.
More LSC stuff
These are the chip models for most of the LSC Smart Connect devices:
- Switch Plug ESP8285-TYWE2S
- Door Sensor ESP8266-TYWE3S
- PIR Sensor ESP8266-TYWE3S
- Hand Remote RTL8710BN-WR3
- Sirene RTL8710BN-WR3
- Led Strip ESP8266-TYWE3L
- If the flashing takes very long, try again
- Android phones yielded better results connecting to the AP and switch
- I had better chances when I put my switch in flashing mode, before running the
- If you are seeing an error regarding SSL when trying to install the prereqs or flashing make sure you have libssl-dev:
sudo apt install libssl-dev(not included by default on Raspberry Pi)
- The official ct-Open-Source tuya-convert repo should include the new workaround but if it doesn't work use this fork. I used this instead because it was the first one to include the patch bypass and I supose this is the one that got merged into upstream.