DETA Grid Connect Smart Switch and Home Assistant

I recently bought a DETA Grid Connect Smart Switch from Bunnings, with the plan being to integrate them with Home Assistant, using ESPHome, or other user-provided code. I actually didn’t use ESPHome, but rather pushed my own code/image to the device.

IMG_3645

The device uses an ESP8266 compatible chip, with a product code of TYWE3S. I’ve included a link to the manual for the TYWE3S package.

There are two different methods that I tried for replacing the image with a custom image (as I wanted to avoid the provided cloud service and integrate directly within my home network).

Method 1 – Tuya-Convert

This method uses the tuya-convert software which is a Linux based package that you use to simulate an OTA (over-the-air) update to the device. This will replace the firmware with a Tasmota or ESPHome image (or a custom image you create). This method needs a Linux computer (I used an Ubuntu USB stick), and a WiFi adaptor. Basically the software impersonates an access point to which the DETA smart switch connects, and then sends it a new image. You can only use this method once – i.e. when the original firmware is on the smart switch. Once you push a new image to the device, you’re then reliant on your own OTA for any further changes (or use method 2).

I’ve been using this method with an image generated by the Arduino IDE, but uploaded through tuya-convert.

Method 2 – Arduino IDE

This method used an AVR programmer and a couple of hookup wires to push an image to the device directly. In my case, I used an AVR programmer from DFRobot. The device basically acts as a USB to Serial converter.

Photo 8-12-19, 6 04 15 pm

Ensure the programmer is set to 3.3V and not 5V. Using the programmer, you need to connect the following pins:

  • VCC -> VCC
  • TX -> TX
  • RX -> RX
  • GND -> GND
  • GND -> GPIO0 (during programming)
  • GND -> RST (during programming)
Untitled

In order to push an image to the device, you need to first put the device into programming mode. This is done by pulling GPIO0 and RST to GND for 3 seconds. Release RST (the device boots), and once you see the code upload start, release GPIO0. If you are going to put your own firmware/image on the device, make sure to include OTA code so that you can do further updates over WiFi.

This sometimes takes a few attempts. Sometimes it works first time, sometimes I might have the timing slightly off, or I may not quite have the pins in contact. So be prepared to give it a couple of attempts.

For interest, the pinouts for manipulating the button and LEDs are as follows:

  • GPIO4 = Device status LED – pull to GND/LOW to illuminate the LED.
  • GPIO12 = Button 2 – GND/LOW represents a button press.
  • GPIO13 = Relay 1 – set to HIGH to turn on the AC relay for Light 1. This will automatically illuminate the LED on the button.
  • GPIO14 = Relay 2 – set to HIGH to turn on the AC relay for Light 2. This will automatically illuminate the LED on the button.
  • GPIO16 = Button 1 – GND/LOW represents a button press.

The pinouts are the same for the single and double gang switches. I’m pretty happy with these devices as they’re compliant with Australian regulations, and very versatile due to the ESP8266 micro-controller.

I’ve since tested this with the single and double light switches, the double power point, the extension cord, the power board and the plug top – although their GPIOs are different.

For updated information on the 3 and 4 gang switches, have a look at my latest post.

~ Mike

28 thoughts on “DETA Grid Connect Smart Switch and Home Assistant

  1. Nice article Mike.
    I just spent hours trying to find the device ID (using a Man in the middle proxy) with no success. I think I’ll go down the same path as you have and do away with the cloud service. I want to run them from a local Raspberry Pi server anyway, so no need for the Grid Connect capability. Thanks for posting the info.

  2. Thanks for posting this and laying out the pins so clearly!

    I’ve got a 2 gang switch working in ESPhome, only thing I can’t get to work is the touch LED’s being on whilst the lights are off (they only turn on when the lights are turned on)… I assume them being on when the lights are off is the intended behaviour so the switch can be located in the dark. Here is my ESPhome yaml for reference for others looking to get these into HA.

    Anyone got any ideas on powering the LEDs when switches are off?

    //

    esphome:
    name: switchname
    platform: ESP8266
    board: esp01_1m

    wifi:
    ssid: “”
    password: “”

    # Enable fallback hotspot (captive portal) in case wifi connection fails
    ap:
    ssid: “”
    password: “”

    captive_portal:

    # Enable logging
    logger:

    # Enable Home Assistant API
    api:

    ota:

    binary_sensor:
    – platform: gpio
    name: button1
    pin:
    number: GPIO16
    mode: INPUT_PULLUP
    inverted: True
    on_press:
    then:
    – light.toggle: light_1

    – platform: gpio
    name: button2
    pin:
    number: GPIO12
    mode: INPUT_PULLUP
    inverted: True
    on_press:
    then:
    – light.toggle: light_2

    – platform: status
    name: “Status”

    output:
    – platform: gpio
    pin: GPIO13
    id: relay_1

    – platform: gpio
    pin: GPIO14
    id: relay_2

    light:
    – platform: binary
    name: “”
    id: light_1
    output: relay_1

    – platform: binary
    name: “”
    id: light_2
    output: relay_2

    status_led:
    pin:
    number: GPIO4
    inverted: yes

    //

    1. Howdy – that’s the way the hardware is designed – when you activate the relay, it’s accompanying LED is lit up at the same time. They’re not independently controllable with the circuit board as designed.

      1. Yeah fair enough, I guess that design makes sense for a GPO so you have an indicator of when the switch is on or off, but definitely feel like it should have been inverted for light switches!

        Anyway, thanks for your help 🙂

  3. You press AND HOLD the switch button for around 5 seconds (until you hear the relay activate). Then the status LED should blink rapidly to indicate it is in pairing mode

  4. No luck with the triple gang switch:

    ID: 0242416f68626d643661473931494652319ac3d59b1aa47083d6bad90fc0f89b4edd42de897e10a5b48a2eba38d708a403
    PSK: 6e9b0fada77b1646ade482f17bc0c88397f1c9b682750a49dcb9fc5c138ba4ce
    could not establish sslpsk socket: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1056)

    any ideas?

    1. Yup, apparently the 3 and 4 gang have had a firmware upgrade which has changed the key. The tuya-convert should have a new version soon that sorts it out. Alternatively you could solder leads onto the chip to push the code to it manually and then use over-the-air updates.

  5. Can anyone who has a deta smart plug (the type you wire to an appliance) confirm if they blue LED on the power button should light up when it’s on? Mine only flashes on startup and I would have thought it stayed on when the device is on like the wall plugs.

    1. I have one of those Deta smart plugs. It is flashed with Tasmota so it’s behaviour may not be the same as under other firmwares.

      At power on, the LED in the on/off button flashes 4 times. From then on the LED lights when the switch is on (relay is closed). This is the same whether the switch is pushed manually or activated via http or mqtt.

      Hope that helps.

    2. The LED on those is controlled by the board – they are not hardwired to indicate the relay position. This means the LED can independently controlled, but it also means you have to find which output is the one you have to control.

  6. Hi, great post. I brought 2x these plugs on the weekend. There appears to have been a firmware update to the switch so now tuya-convert doesn’t work. I’ve plugged the board into a USB to Serial converter, and I’m still not having any luck.
    Confirming that the TX & RX not crossed?
    Also what software are you using to load the firmware .bin onto the board?
    Todd

    1. got it working.
      crossed TX & RX.
      used tasmotizer-1.1a for windows, on Win10. running As Administrator
      used bin tasmota-basic7.1.bin

      If the install fails, then disconnect the usb to serial dongle. refresh the com ports in tasmotizer. then while the device is connected and running, connect an ground lead to GPIO0, then to RST, hold for 3 sec. then release RST, wait 3 sec, then release GPIO0. Then click Tasmotize! button
      Todd

  7. Hi Mike,
    Thanks for your work on this. I’m trying to use the manual method on a few 1 gang and 2 gang switches but am having trouble getting it into programming mode. It reboots when I pull GPIO0 and rst to ground but no lights turn on again. Should they? Tasmotizer also times out while connecting.

  8. Mike; few bits of feedback, both on the 1/2 gang models and the 3/4 gang models.

    For everyone – I had to connect the Tx on the board to Rx on my usb adaptor. Rx->Tx. In order to get it to work, I took Reset to ground at the same time as I held GPI0 to ground. I then *kept* holding GPI0 at ground during the flashing process – worked every time if I did that – no timing issues.

  9. Mike, thanks for posting this information. It has been really useful. I have managed to convert one to Homekit from Raven Systems, for a friend. Personally I’m 100% in the Android camp.
    Has anybody successfully, backed up and restored the original firmware to these? if so could you please provide some guidance? I have tried OTA on Linux and made a backup, I was merely trying to just back it up, however, unfortunately, cancel at that point is the wrong choice as it erases the firmware (I guess I should have chosen restore the original firmware).
    I have another (still Working) one which I have tried backing up using esptool, however when I restore either the backup I made using esptool, or the OTA backup, the device doesn’t appear to boot. I have tried QIO, DIO and DOUT for the SPI mode to no avail. I have successfully flashed it with alternate firmware, but want the option to be able to roll back to factory firmware. Any assistance would be appreciated.

    1. I haven’t verified it to work, but you might try this as a starting point:
      https://www.instructables.com/id/How-to-Backup-Original-Flesh-File-From-Esp8266EX/

      I’m not really sure why you would want to, though. The biggest reason for replacing the original firmware on these is because the original firmware is allowing a Chinese company with dubious security protocols to have access to devices inside your network. Were it not for Tasmota, I would not be using any of these devices – not even the first one I was given as a gift.

      Best Regards,
      Richard.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s