logo elektroda
logo elektroda
X
logo elektroda

Gosund/Ghome SW2 [BK7231T] wifi dimmer switch - subsystem identification

bkespoke 3534 26
Best answers

How can I identify and interface with the subsystems in a Gosund/Ghome SW2 BK7231T dimmer switch so it can work with OpenBeken?

The BK7231T in the SW2 does not talk TuyaMCU or I2C; it talks over a custom 115200-bps serial link to the power/dimmer controller, while the separate APTchip touch MCU handles the touch strip and 7-LED bargraph over I2C [#20815398][#21601119] The decoded BK protocol is simple: LED updates are 0x40|(1..7), dimmer-on is 0x80|dimmer(0–100%), dimmer-off is 0x00|last brightness(1..7), usually sent as LED then dimmer about 14 ms apart and sometimes repeated later [#20825305] Touch input comes back as a 5-byte frame 0x24 0xTT 0x01 0x69 0x23, where TT is roughly 0x01 to 0x96, and the power board also prints startup text like “touch addr not ack when tx write cmd!” and “mcu ver: v2.1.2” until the touch MCU ACKs I2C [#20825305] For OpenBeken, the practical path is a custom serial driver or porting a small UART driver in C; the thread suggests this is easier than trying to fit it into the usual TuyaMCU model [#20825398][#20825371][#21593661] If you only want basic control, you can likely ignore the touch MCU and just emulate the BK-side serial commands for relay, dimming, and bargraph state [#20825305][#21594323]
Generated by the language model.
ADVERTISEMENT
  • #1 20815331
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3

    Following from the excellent SW5 teardown and template which works well for me, I am now struggling with the Gosund / Ghome SW2.
    It's a dimmer with both a traditional US Decora style press-button but also a touch front panel with a row of LEDs. Generally a high-quality product, as with all Ghome I've seen so far. Purchased from Amazon, also sold direct, $15-$20.
    FCC ID 2APUZ-SW2 UL listed ES09666 Model SW2 Date 05/2022. 120 V 4 A.

    GHome smart dimmer with voice and app control features.

    It contains FOUR PCBs connected by thin flex cables:
    - Main switch/relay/psu/dimmer board, including a mysterious IC "GK1DD8S003F3P6" which must do the dimming.
    - CPU board containing the BK7231T (module) and the seven LEDs
    - Touch board with an APTchip "32S1028H8S6" microcontroller.
    - 2.4 GHz antenna with coax and U.FL or IPEX

    Stock firmware offers on/off, dimming by touch / sliding finger, bar graph of LEDs, very nice.
    But it needs to run OpenBK and talk to HA.

    Questions:
    Does anyone have experience with these peripherals?
    Are there any libraries that might work?
    I can flash the BK7321 fine, but there is firmware on the other parts, which it would be best to use as-is.
    Is the next step to power it up with isolated 120 V, sniff the I2C between the boards and attempt to reverse-engineer the protocols? Urgh!
    Does the S in the APTchip indicate that it has no flash, needs to be programmed on power-up?
    I guess it would be OK to just have dimming, bar graph and wifi, ignore the touch board.

    Any other pointers or suggestions would be welcome. Am I biting off too much here?
    I'd also be happy to ship my one in pieces to a real expert...

    Thanks!


    Touch board IC:
    Close-up of a microchip with visible markings and numbers.

    Dimmer board IC:
    Close-up of an integrated circuit on a printed circuit board, labeled as BL602T.

    CPU board (nice programming pads)
    Electronic circuit board with components and wiring

    General assembly:
    Teardown of Gosund SW2 LED V1.0 electronic circuit with visible components and board.
  • ADVERTISEMENT
  • Helpful post
    #2 20815398
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Hello, why do you think this device uses I2C?

    I'd rather think it's just yet another TuyaMCU device, which should be easily supportable by OpenBeken, altough flashing may be a bit hard due to the UART1 port being used for both programming and TuyaMCU communication. It also may be required to do the UART packets capture first, and it must be done in a safe manner. They can be later analyzed in https://github.com/openshwprojects/TuyaMCUAnalyzer

    Or maybe we could just skip the UART analysis part, just make firmware backup (just in case) and then try to flash OBK and just try to query dpIDs from device and try to guess their meaning... TuyaMCU dimmers are not usually very complicated, they are often using the same dpIDs in many different models.
    Helpful post? Buy me a coffee.
  • #3 20819144
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3

    Thank you!! This pointed me in the right direction. After much investigation about TuyaMCU...

    With the stock firmware, I have found serial communications at 115200 to/from the BK7231, but not TuyaMCU packets.
    Also I2C between various things on the boards, not yet sure which parts are talking.

    A bunch of information that doesn't yet completely make sense (all values are hex)

    1) I2C seems to control the bargraph LEDs.
    Evidence: When pressing the microswitch for On, when the light was previously at full brightness, apart from the relay click, the bargraph lights run up in sequence 1 to 7. I2C packets are (writing to address A6): 00 01, then 00 03, 00 07, 00 0F, 00 1F 00 3F 00 7F.
    Turning off, they just drop instantly to a single dot, with a matching packet.

    2) Serial seems to control the dimmer.
    Evidence: When touching the dimmer touch board, with the light in the On state, apart from the LED I2C packets, now we get:
    - I2C write address A6: 01 A7
    - I2C read address A7: 00
    - BK serial RX: 24 00 01 5D 23
    -repeat- I2C write address A6: 01 A7
    -repeat- I2C read address A7: 00
    -repeat- BK serial RX: 24 00 01 5D 23
    - BK serial TX 0x41
    - BK serial TX 0x81
    - I2C write A6: 00 01 [the LED command]

    3) More serial dimming - when running a finger UP the dimmer slider:

    I2C LEDsI2C (dimmer control?)Serial RX on BK (Dimmer?)
    write:A6: 00 03read:A7: 3E 24 3E 01 5C 23
    write:A6: 00 07read:A7: 43 24 43 01 5C 23
    write:A6: 00 0Fread:A7: 4F 24 4F 01 5C 23


    3) When the relay is OFF, there are no I2C packets (because the LEDs don't change)
    But also no serial packets, so I assume whatever is Transmitting the serial dimming command is not bothering while the relay is off.

    4) The BK7231 is also sending single serial bytes at 115200, not obviously synchronised with any of the other packets, but only happening when there's some action. They're in pairs, brightness increasing:
    41 81
    41 89
    41 92
    41 98
    42 9E
    42 A3
    42 A4
    42 AA
    43 AE
    ...
    46 DA
    46 DE
    47 E4
    Maybe this could be: (0x40+number_of_LEDs_4bits 0x80+True_brightness_7bits)

    5) There's no heartbeat at all. The LED and other commands are sometimes sent a second time, 100 ms later.

    6) there's no packet on either bus associated with the relay click

    7) BUT once while flashing the BK7231 with an external serial port, forgetting the other boards connected, the relay started clicking randomly as though it was receiving a command.


    Next Steps:


    1) take one for the team and install the smart home app, send some commands that way

    2) disconnect the boards one at a time and see who is still talking to whom

    3) probe the three microcontrollers actual pins looking for these signals, to see which ones even get the various messages.


    Any other suggestions or ideas?
  • Helpful post
    #4 20825305
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    I've finished decoding most of it now.

    tl;dr is it worth trying to get OpenBeken to speak to this dimmer?
    It's definitely not the usual TuyaMCU protocol. Is it fairly simple to write something that receives and sends these messages, updates its internal dimming state etc? The LEDs and Button are easy, but how would it parse the 5-byte serial messages to get the touch input, and send the serial dimmer and LED commands?

    Have you seen a device like this before? Shall I flash it with OBK and try sending some of these commands? Thank you!



    The gory details:

    TouchController (APTchip) - reads the touch, controls the 7 LED bargraph.

    PowerDevice controls the relay and the Triac.

    PowerDevice and TouchController speak by I2C - one message A6 00 bb is the LED mask. The other A6 01 A7 tt is the touch position.
    Also an INT line for APTchip to tell PowerDevice it's been touched
    And a WAKE line for PowerDevice to tell TouchController to listen to I2C.

    The BK7231-relevant parts are as follows:
    - Physical button connected to the BK module
    - WifiLED and PowerLED connected to BK
    - Serial TX from BK to PowerDevice is to turn relay on and off, and set dimmer (via I2C eventually).
    - Serial RX from PowerDevice is to tell BK the touch state.
    - BK not connected to I2C

    The BK sends only these bytes, 115200bps:
    OFF: 0b 0000 0aaa where aaa is 1 to 7 depending on the brightness before turning off
    ON: 0b 1ddd dddd where ddd dddd is the dimmer setting, 0-100 (percent)
    LED: 0b 0100 0ggg where ggg is the LED bargraph 1 to 7.

    It's usually sent as a two-byte message, first the LEDs then the Dimmer.
    14 ms apart. Sometimes repeated after 20-100 ms or longer, but if you're sliding the brightness on the app, it keeps sending new values, no duplicates. I don't think the timing order of the bytes is useful information, they're decoded separately.

    The reason the OFF message also contains the brightness 1-7 is so the PowerDevice can tell the TouchController to leave that single LED on, indicating how bright it will be when switched on again.

    the BK receives the touch position from PowerDevice by serial, 115200, with this 5-byte packet:
    0x24 0xTT 0x01 0x69 0x23 where TT is the touch position, approximately 0x01 to 0x96
    It then usually sends out a new dimmer setting and LED bargraph (which is then relayed by i2c...)

    At startup the PowerDevice says this 9 times on the serial port:
    Packet 1, 37 bytes: 74 6F 75 63 68 20 61 64 64 72 20 6E 6F 74 20 61 63 6B 20 77 68 65 6E 20 74 78 20 77 72 69 74 65 20 63 6D 64 21
    in english, it's saying: touch addr not ack when tx write cmd!

    Then it says
    Packet 10: 72 65 73 65 74 21 0A 6D 63 75 20 76 65 72 3A 20 76 32 2E 31 2E 32
    reset!
    mcu ver: v2.1.2


    It finally stops complaining once the TouchController ACKs the I2C

    BK says nothing on startup.

    There are no heartbeats that I've seen, complete radio silence on Serial and I2C unless there's a command on the app, button press or the touch surface is touched.
  • #5 20825371
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Very good job, it reminds me of WXDM2 dual dimmer, which also had a custom UART protocol. You can read about it here:
    https://www.elektroda.com/rtvforum/topic3985978.html#20631683
    Do you need help with getting that into OBK?
    Helpful post? Buy me a coffee.
  • #6 20825408
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    Hi, I think I could get the HexSend working, and make it function as a dimmer and indicate its state on the bargraph.
    It's easy to flash, because the BK board can be isolated by disconnecting the flex cables. I'll try this tomorrow.

    Is there a way to receive the 5-byte packets, to receive the touch input?
    Or is that a major rebuild like cloning the TuyaMCU driver?

    Also - do you support dimming commands by Hue Emulation? This looks like a fairly messy process :( I don't yet have a HA server, so it would be useful to control the dimmer like this.

    Thanks!
  • ADVERTISEMENT
  • #7 20825423
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Our Hue is not ready, but we have Wemo.

    What about creating a driver directly in C? Maybe this would be easier to support this device.

    We are usually using Tasmota apps to control OBK, like Tasmota Control, etc.
    Helpful post? Buy me a coffee.
  • #8 20825586
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3

    Sorry, I'm not up for writing a new driver in C, I'll get lost.

    Ha ha if only my internet search was as good as my logic analysis. Blakadder took the SW2 apart and decoded the protocol years ago (when it was still made with an ESP).

    Thanks for all your work on OBK, it's doing well on my other switches. I hope this post helps someone else trying to figure out the SW2.
    Time to put it back together.
    Disassembled electronic circuit board with connected wires on a white background.
  • #9 20932602
    GeraldOfPataskala
    Level 1  
    Posts: 1

    Can you show how you used the Blackadder script to make it work? I assume you translated it to an autoexec.bat file?
  • #10 20932611
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    I'm not sure if @bkespoke got it working. I could do it for you, but I don't have access to this device, I would need to get one piece for testing.
    Helpful post? Buy me a coffee.
  • #11 20932670
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    Hi, sorry I didn't get it working at all.
    Blakadder had decoded the serial protocol from the ESP8266 to the other micro(s) in the switch, and written a script for Tasmota. This was back when the SW2 used an ESP, now they're BK7231. I just didn't find it when searching, and did it all again myself.

    It might be possible to write an OBK script to send and receive commands to make a SW2 work, but it really needs a new serial port driver and that's beyond me.

    You can see all of the commands above and on Blakadder.


    I'd be happy to test your script or set up a sandbox for you to work on the SW2. I just can't help much with the code.
  • #12 21025838
    mikekornikh
    Level 2  
    Posts: 2

    Hello! I just got the Shelly Plus wall dimmers, and it uses the exact same chips except for an ESP32 instead of the Beken. I'd love to get this working in ESPhome! Shelly Plus circuit board with mounted LEDs. Close-up of the internal electronic circuitry of a Shelly Plus wall dimmer. Internal view of a Shelly Plus wall dimmer showing circuit boards with an ESP32 chip. Interior of a Shelly Plus wall dimmer showing the electronics. View of the interior of a wall dimmer with an ESP32 chip. Interior of a Shelly Plus wall dimmer showing integrated circuits and circuitry. Shelly Plus wall dimmer with touch button and LED indicators.
  • ADVERTISEMENT
  • #13 21025865
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Whoa, you are lucky, how did you get one with ESP32? Which mobile app was it dedicated for, is it for Tuya or something else?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #14 21025892
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3

    Interesting! Perhaps I'll order one more to see if it's changed back to ESP.


    If the internal serial protocol is unchanged, there's a fairly straightforward recipe and script at Blakadder. As the boards are connected with flex PCBs it's easy to separate them so you can flash the ESP by its serial port without interference.

    Things to watch out for:

    1. Is the protocol the same? Check with a scope or logic analyzer, or even just your FTDI cable before you flash, that it's sending the same messages as I found. Likely to be ok because it was stable between 2021 and 2023. Back up the ESP firmware?

    2. The ESP will probably talk to the other micro with some non-standard serial port pins, not its usual Tx and Rx. You'll need to find them by staring at the board. See the blakadder page for the esp8266 version of this.


    Don't connect it to mains power and your computer at the same time! It's fairly easy to power the whole switch from 5 V on the relay/PSU board.
  • #16 21591363
    hardware4200
    Level 7  
    Posts: 3
    Rate: 1
    Very interesting discussion:

    I have a GHOME device SW17 having a LN882HK1 on it. I was able to successfully flash it using openbelken. However I discovered the same issue with the dimming, seems there is I2C, I am wondering if the capability to control the dimmer was added to the library. I am pretty new to all of this but I have some C chops and would be willing to take this on and figure it out.
  • #17 21593208
    divadiow
    Level 38  
    Posts: 5044
    Help: 438
    Rate: 892
    I don't believe anything has been written for the dimmer chip. Does your device have the same chips as seen in the first post in the SW2?

    Did you capture boot log for factory firmware? Maybe it has clues about driver loaded...
  • #18 21593400
    hardware4200
    Level 7  
    Posts: 3
    Rate: 1
    >>21593208 re: Boot.log. I am not sure how to capture this other than watching the UART. I have a connection to the device when it boots and I see nothing on the serial console.

    re: Chips. SW17 has a LN882HK1 (which I've successfully flashed with OB) and a 32S1028H8S6 which is the capacitive touch MCU.

    I think this could be a significant game changer if this device were adopted, as it costs roughly $7-9ea in quantities of 4.

    I am happy to do the work if there isn't anything existing, ideally someone who knows the firmware (that might be you) could give me some guidance of how I would actually implement this. I know it will require an I2C interface, but I am wondering more about how should surface this to the UI. How to select SCL/SCA, addresses.

    I am getting my environment setup to put the device on a logic probe, etc.
  • #19 21593412
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Helpful post? Buy me a coffee.
  • #20 21593497
    divadiow
    Level 38  
    Posts: 5044
    Help: 438
    Rate: 892
    does this help?

    https://templates.blakadder.com/gosund_SW2.html

    Code: Text
    Log in, to see the code


    https://github.com/ab0tj/esphome-devices/blob/master/gosund_sw2_output.h
    https://github.com/ab0tj/esphome-devices/blob/master/gosund_sw2_uart.h

    https://cocoontech.com/threads/gosund-wifi-dimmer-replacing-firmware.32175/

    Added after 1 [hours] 1 [minutes]:

    hardware4200 wrote:
    re: Boot.log. I am not sure how to capture this other than watching the UART. I have a connection to the device when it boots and I see nothing on the serial console.

    hmm OK. it'd be a case of flashing back factory and listening on B9. or send me dump and I'll flash and capture.

    Added after 1 [hours] 2 [minutes]:

    http://en.aptchip.com/list_112/655.html#gongju

    Part NO.Op.VoltTempFreqPinGPIOHSIOFlashRAMDflashHWDIWDTWWDTBTCNTARTCLPTEPTGPTUARTIICSPINOTTTLPWMADCTouchDeep SleepPACKAGE
    APT32S1028H8S61.8v~5.5v-40~8548MHz2422464k4k2k11211111311116bit,12ch12bitx16ch17ch5uASSOP24


    looks like a CK-Link type chip http://en.aptchip.com/tiaoshi
  • #21 21593661
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    There seem to be some confusion, the linked driver is a simple UART byte send, I can port it easily.

    I've started porting it, but it's not I2C so it may not fit your device, but anyway...
    Gosund/Ghome SW2 [BK7231T] wifi dimmer switch - subsystem identification
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1702
    Futhermore, on which platform should I enable it? LN882H?

    I am also missing one more thing - what is the baud rate there?
    Helpful post? Buy me a coffee.
  • #22 21594088
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    Re >>21593661
    The baud rate on the serial port was 115200 - for the dimming control messages, and the startup message.

    I still have the .logic captures for various operations of the dimmer, but my summary in >>20825305 contains everything I could figure out. I never tried sending the various codes from openbk to the dimmer controller.

    If you have firmware for it, and I'm the only one with hardware, I could probably flash it and try it out.
  • #23 21594301
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12620
    Well, that does not match the SW2 driver I ported... maybe we could do driver according to your specs, but I am not sure if info is complete. Do you know C basics?
    Helpful post? Buy me a coffee.
  • #24 21594323
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    Me? I can read C and hack it but not construct a whole interconnected application.

    Quote:
    that does not match the SW2 driver I ported

    From where? Perhaps the power driver microcontroller and hence its interface has been changed. My dimmer is almost 2 years old now.

    What I said about my 2023 device and investigations:
    Quote:
    The BK sends only these bytes, 115200bps:
    OFF: 0b 0000 0aaa where aaa is 1 to 7 depending on the brightness before turning off
    ON: 0b 1ddd dddd where ddd dddd is the dimmer setting, 0-100 (percent)
    LED: 0b 0100 0ggg where ggg is the LED bargraph 1 to 7.


    To explain my earlier writing a bit more carefully:
    On every power state change the BK should send something like this at 115200 bps
    1. the LED byte which is 0x40 | (state*7)
    2. pause 14 ms (this is 200 characters, a non-trivial delay (could experiment to see if it needs to be so long. Perhaps the dimmer micro can't receive serial while talking to the display on I2C?)
    3. the dimmer setting which if the power is on, should be 0x80 | (state*127).
    If the power is off, send 0x00 | (state*7) (I can't remember why the state is required. Perhaps this takes precedence over the LED byte if power is off. Dimmer LEDs??)
    4. Repeat the above a second time after 100 ms of idle time (guarding against corruption?)
    5. Max rate of about 100 ms, even if the touch input is coming in every 40 ms.

    This isn't quite what's in DRV_GosundSW2_Write() in your new code. - you're only controlling the dimmer, not the bargraph LEDs.

    DRV_GosundSW2_RunFrame() looks OK. No idea if it will stay synchronised, maybe that's taken care of by a short timeout. From my logic analyser captures, the 5-byte frames arrive about every 39 - 50 ms when sliding your finger on the touch strip.
    You'll need to adjust the touch strip limits to ensure you can get 100% and 0%. I got values up to 0x96 which is 150, so maybe use float dimmerVal = constrain(buff[1] / 145.0, 0.0, 1.0) or something.


    The original Ghome firmware has some further neat functionality for the bargraph:
    - at least one dot always showing
    - remembers the brightness when you switched off by pressing the button
    - displays this last brightness so you know what you'll get when pressing
    - possibly accepts touch inputs to change brightness while the light is off, so you can pre-dim it before turning on with the physical switch
    These could be emulated in various ways.
  • #25 21594484
    divadiow
    Level 38  
    Posts: 5044
    Help: 438
    Rate: 892
    bkespoke wrote:
    and the startup message.


    thanks for the dump of your BK7231T SW2 factory firmware. Here is boot log (on dev board so missing the other components in dimmer of course)

    Code: Text
    Log in, to see the code



    Code: Text
    Log in, to see the code
  • #26 21600913
    hardware4200
    Level 7  
    Posts: 3
    Rate: 1
    >>21593412
    p.kaczmarek2 wrote:
    But do we know the protocol?

    Regarding code - copy sample driver, or some driver using I2C, and build from there:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_sht3x.c
    How to create a custom driver for OpenBeken with online builds (no toolchain required)


    Thanks for the above. Apologies for the delayed response, been real busy here. I am going to take this on and try to figure it out. Appreciate the pointers.

    Added after 10 [minutes]:

    >>21594301 If you are asking me. Yeah, I have some decent C chops. I need to go through the links that have already been provided and figure out how I would implement/catch the I2C communication and pass that to TRIAC that controls the dimming.
  • #27 21601119
    bkespoke
    Level 5  
    Posts: 14
    Help: 1
    Rate: 3
    @hardware4200 The BK7231 doesn't use I2C - it only speaks on the serial port, to the dimmer controller ST Micro.

    Here's a sketch of the whole unit.
    Gosund/Ghome SW2 [BK7231T] wifi dimmer switch - subsystem identification
    It looks like it was cobbled together from existing / working parts, not designed from the ground up (some risk of it being redesigned...)

    Edit: We may be talking about different units - there's also a "shelly" ESP32 version. Though from the photos it is likely the same control arrangement. Maybe Mike can confirm this. It took me a while to figure out that the I2C passes through the main board, even has test pads there, but it's not a common bus, not even connected to the BK7231.

Topic summary

✨ The discussion focuses on the Gosund/Ghome SW2 WiFi dimmer switch featuring a BK7231T CPU module, a dimmer MCU labeled "GK1DD8S003F3P6," an APTchip 32S1028H8S6 touch controller, and a 2.4 GHz antenna. The device uses a complex subsystem with four interconnected PCBs communicating via I2C and serial interfaces. The bargraph LEDs are controlled over I2C, while dimming commands and touch inputs are exchanged through a custom 5-byte serial protocol at 115200 baud, distinct from the common TuyaMCU protocol. Efforts to integrate the device with OpenBeken (OBK) firmware highlight challenges due to the proprietary serial protocol and the need for a new serial driver. Flashing the BK7231T is feasible by isolating the CPU board, but decoding and implementing the dimmer control requires detailed protocol analysis and custom scripting. Related devices like the Shelly Plus wall dimmer use similar chips but with ESP32 instead of BK7231. Community members reference Blakadder’s prior ESP8266-based protocol reverse engineering and Tasmota scripts as starting points. The discussion also touches on potential development of custom drivers in C, I2C protocol reverse engineering, and integration with home automation platforms such as Home Assistant and Wemo. The conversation includes boot log analysis, logic captures, and firmware dumps to aid in understanding the device’s communication and control mechanisms.
Generated by the language model.

FAQ

TL;DR: At 115200 baud, the SW2 uses a custom UART link, not standard TuyaMCU, and one expert conclusion was: "It's definitely not the usual TuyaMCU protocol." This FAQ helps OpenBeken, Tasmota, and ESPHome users identify the SW2 subsystem layout, decode touch packets, and flash the BK7231T board safely. [#20825305]

Why it matters: Correctly identifying the SW2's internal protocol prevents wasted reverse-engineering time and reduces the risk of unsafe mains-side probing.

Platform What the thread shows Main limitation
Tasmota Old ESP-era SW2 script already exists Targets older ESP hardware, not BK7231T directly
OpenBeken BK7231T flashing works and custom driver work was discussed No ready-made full SW2 driver confirmed working
ESPHome ESP32-based similar hardware may reuse the same serial protocol Pin mapping and protocol confirmation still required

Key insight: The BK7231T is not on the SW2's I2C bus. It talks by custom 115200-baud UART to a separate power/dimmer controller, while the touch MCU handles the slider and 7-LED bargraph over I2C. [#20825305]

Quick Facts

  • The labeled SW2 hardware in the teardown was 120 V, 4 A, dated 05/2022, with FCC ID 2APUZ-SW2, and sold around $15-$20. [#20815331]
  • The switch contains four PCBs: main relay/PSU/dimmer board, BK7231T CPU board, touch board with APT32S1028H8S6, and a separate 2.4 GHz antenna board. [#20815331]
  • The custom BK7231T control link runs at 115200 bps; touch reports arrive as 5-byte frames, and the stock firmware used about 14 ms spacing between LED and dimmer bytes. [#20825305]
  • Startup diagnostics from the power controller included 9 repeats of "touch addr not ack when tx write cmd!" before reporting mcu ver: v2.1.2. [#20825305]
  • A later GHOME SW17 variant was reported at roughly $7-$9 each in packs of 4, showing the same broader reverse-engineering problem on newer hardware. [#21593400]

How can I identify whether a Gosund/Ghome SW2 BK7231T dimmer uses TuyaMCU, a custom UART protocol, or I2C between its internal boards?

Identify it by tracing which boards talk to which bus. On this SW2, the BK7231T saw serial traffic at 115200, while the touch MCU and power controller exchanged I2C messages such as writes to address A6 and reads from A7. The decisive result came later: the BK7231T was not connected to I2C at all, and the device was "definitely not the usual TuyaMCU protocol." That means UART links the BK7231T to the dimmer controller, while I2C stays inside the non-Wi-Fi subsystem. [#20825305]

What is TuyaMCU in the context of OpenBeken devices, and how is it different from the custom serial protocol used by the Gosund SW2 dimmer?

"TuyaMCU" is a serial control protocol that lets a Wi-Fi MCU exchange standardized datapoints with a separate appliance controller, using reusable dpIDs across many Tuya devices. The SW2 differs because its BK7231T sends simple custom bytes, not Tuya datapoint frames. The thread decoded ON as 0b1ddddddd, OFF as 0b00000aaa, and LED updates as 0b01000ggg, all at 115200 bps. That custom scheme is much simpler electrically, but OpenBeken cannot treat it like a stock TuyaMCU device. [#20825305]

What are dpIDs in Tuya/OpenBeken devices, and how would you query or guess them when reverse engineering a dimmer switch?

dpIDs are Tuya datapoint identifiers that label functions such as power, brightness, or mode. In OpenBeken work, you usually flash the device, query available dpIDs, and infer meanings from repeated behavior because many TuyaMCU dimmers reuse the same IDs across models. That method was suggested early for the SW2, but it stopped fitting once the traffic proved non-Tuya. So dpID guessing is useful only if captured packets actually look like TuyaMCU frames. [#20815398]

How do you safely capture UART and I2C traffic on a mains-powered Gosund SW2 dimmer without damaging your computer or yourself?

Use isolation or remove mains from the equation entirely. The thread suggested isolated 120 V for live sniffing, and later warned: "Don't connect it to mains power and your computer at the same time!" A safer workflow is: 1. Separate the flex-connected boards. 2. Power the switch from 5 V on the relay/PSU board or flash only the isolated BK board. 3. Probe UART or I2C with a logic analyzer before modifying firmware. This avoids tying a computer ground to live mains circuitry. [#21025892]

Why does the Gosund SW2 send 5-byte serial packets like 0x24 TT 0x01 0x69 0x23, and how can those packets be translated into touch slider brightness values?

Those 5-byte packets report touch-slider position from the power controller back to the BK7231T. The decoded format was 0x24 0xTT 0x01 0x69 0x23, where TT tracked touch position from about 0x01 to 0x96. When the slider was moved, matching values appeared on I2C and UART, such as 0x3E, 0x43, and 0x4F. A practical mapping is to scale TT into a 0-100% brightness range, with upper-end clipping because observed maximum touch values reached about 150 decimal. [#21594323]

How should OpenBeken send the SW2's custom 115200 baud dimmer commands for ON, OFF, and 7-LED bargraph updates?

OpenBeken should send single-byte commands at 115200 bps, usually as a two-byte sequence. The BK7231T format was decoded as: OFF 0b00000aaa, ON 0b1ddddddd for 0-100% dimming, and LED 0b01000ggg for the 7-LED bargraph. The stock behavior sent the LED byte first, then waited about 14 ms, then sent the dimmer byte, sometimes repeating after 20-100 ms. That means a working driver must update both brightness and bargraph, not only the dimmer output. [#21594323]

Which parts of the Gosund/Ghome SW2 are actually connected to the BK7231T, and what roles do the APT32S1028H8S6 touch MCU and the dimmer/power controller play?

The BK7231T is connected to the physical button, the Wi-Fi LED, the power LED, and a UART link to the power controller. The APT32S1028H8S6 touch MCU reads the capacitive slider and controls the 7-LED bargraph. The power controller drives the relay and triac, talks to the touch MCU over I2C, and sends touch state to the BK7231T over serial. The BK does not sit on the I2C bus, so the design is split into a Wi-Fi board plus a separate dimmer-control subsystem. [#20825305]

What is the APT32S1028H8S6 chip, and does it include onboard flash or require code to be loaded at power-up?

"APT32S1028H8S6" is a capacitive-touch microcontroller that reads touch inputs and includes integrated nonvolatile memory, on-chip RAM, and multiple serial peripherals. A later post cited vendor data showing 64 kB flash, 4 kB RAM, 2 kB Dflash, 1 IIC block, and 3 UARTs in an SSOP24 package. That directly answers the original doubt: the part is not a flashless slave that must be programmed on every power-up. It stores its own firmware. [#21593497]

Why might the relay click randomly when flashing the BK7231T with the other SW2 boards still connected?

The relay can click because the still-connected power controller may misread programming traffic as control commands. One flash attempt left the other boards attached, and the relay began clicking "randomly as though it was receiving a command." That failure makes sense because the BK7231T programming UART and the device-control UART share live connections inside the assembled switch. Separate the flex cables first, or you risk accidental relay or dimmer activation during flashing. [#20819144]

What is the best way to port the old Blakadder/Tasmota Gosund SW2 script to OpenBeken or ESPHome for newer BK7231T and ESP32-based versions?

Start by reusing the old serial protocol, not the old firmware assumptions. The thread found that Blakadder had already decoded the ESP-era SW2 UART commands, and an ESPHome configuration also existed for that design. For BK7231T, you need an OpenBeken serial driver or script layer that can both send command bytes and parse incoming 5-byte touch frames. For ESP32 hardware, first confirm the same packet set appears on the board's UART pins before mapping the older configuration. [#21593497]

How do Tasmota, OpenBeken, and ESPHome compare for supporting the Gosund SW2 or similar custom-UART dimmer switches?

Tasmota had the most mature historical support because an older SW2 script already handled the ESP-based serial protocol. OpenBeken could flash the BK7231T board and already supported other switches, but the thread still needed a new serial driver for full SW2 support, and Hue emulation was "not ready" while Wemo existed. ESPHome looked promising for ESP32-based clones because users found matching configs, but the thread had not confirmed pin mapping or a working final implementation. [#20825423]

What steps are needed to build a custom OpenBeken driver in C for a non-Tuya dimmer like the Gosund SW2 or GHOME SW17?

Build a small transport driver first, then layer dimmer logic on top. One OpenBeken maintainer advised copying an existing sample driver, such as the I2C drv_sht3x.c, and using the online build flow for custom firmware. For the SW2, the actual transport was UART at 115200, not I2C, so the driver must parse 5-byte touch frames and emit LED plus dimmer bytes with timing. A later pull request showed that even a partial port was easy to start, but matching the full protocol remained incomplete. [#21593661]

How can I tell whether a Shelly Plus wall dimmer with ESP32 uses the same internal protocol as the older Gosund SW2 design?

Check the UART traffic before flashing anything. The thread advised using a scope, logic analyzer, or even an FTDI cable to confirm that the ESP32-based Shelly sends the same messages already decoded for the SW2. If the internal serial protocol matches, the old Gosund recipe is reusable with new pin mapping. If the board uses different serial pins or a changed controller, the old script will not port cleanly even if the touch and dimmer chips look similar. [#21025892]

Why does the SW2 show startup messages like 'touch addr not ack when tx write cmd!' and 'mcu ver: v2.1.2', and what do they reveal about the internal controller?

Those startup strings show that the power controller actively initializes and monitors the touch MCU. At boot it sent the error message 9 times until the touch controller finally acknowledged I2C, then it reported reset! and mcu ver: v2.1.2. That reveals two important facts: the dimmer side runs independent firmware, and it depends on a second controller on the touch board. The BK7231T itself stayed silent at startup on that internal serial link. [#20825305]

What is the safest way to power and flash the separated SW2 control board through its programming pads while leaving the mains dimmer section disconnected?

The safest method is to isolate the BK board physically and flash it on its own pads. The thread noted that the flex-cable design makes the BK7231T board easy to disconnect, so you can program it without interference from the relay or dimmer boards. For ESP-era variants, users also reported powering the overall switch from 5 V on the relay/PSU board instead of mains. That keeps mains off the bench while preserving access to UART, LEDs, and the programming header. [#20825408]
Generated by the language model.
ADVERTISEMENT