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.

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.

~ Mike

10 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

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