logo elektroda
logo elektroda
X
logo elektroda

Template for Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller

torte 2970 14
ADVERTISEMENT
  • #1 21029166
    torte
    Level 3  
    Posts: 5
    https://www.aliexpress.us/item/10050060833418...ain.24.33be5c5fya5BlM&gatewayAdapt=4itemAdapt
    Hello,

    I have flashed the Beken firmware to the device, but I failed to copy the template from the original device.
    Now I can manage the single click on both buttons, but I can't manage the battery status and double or long click.
    Can anyone help me?
    ThankYou
    Torsten

    {
    "vendor": "Tuya",
    "bDetailed": "0",
    "name": "Full Device Name Here",
    "model": "enter short model name here",
    "chip": "BK7231N",
    "board": "TODO",
    "flags": "1024",
    "keywords": [
    "TODO",
    "TODO",
    "TODO"
    ],
    "pins": {
    "16": "dInput;47",
    "20": "dInput;43",
    "26": "Rel;37"
    },
    "command": "PowerSave 1",
    "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
    "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }


    Template for Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller Template for Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller Template for Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller Template for Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller
  • ADVERTISEMENT
  • Helpful post
    #2 21030110
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    Ha. You beat me to the first post of this device. I dumped and flashed one of these last week and was working on an autoexec to complete the button usefulness in home assistant. I'll post what I have tomorrow, but from memory BAT_ADC is P23 (as always) and BAT_Rel is P17. The measurements will be ~300mA too high until further config.

    Added after 10 [minutes]:

    Also. It's clear this scene switch build shares some pcb/chassis moulds with this https://www.elektroda.com/rtvforum/topic4042463.html

    Which I thought was interesting
  • #3 21030167
    torte
    Level 3  
    Posts: 5

    Great!
    Screen view of a user interface showing control status and battery level.

    Battery is working now.
  • Helpful post
    #4 21030248
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    great.

    so I haven't actually got that far. I'm still not that familiar with HA/MQTT.

    What does your autoexec look like? I was thinking about using this device to control lounge light, single presses of a button to turn on/off but then longer presses of 1 or 2 buttons to dim/brighten. Thing is, if you use the device on battery you'll want it to wake from deep sleep on button push, connect to MQTT, then send your actions all in a very short space of time or it'll be frustrating waiting for your actions to be effective. I'm not waiting 5s to turn the light on!

    Or, more likely, I was going to make a hole in the back of the device and solder in an AMS117/USB 5V cable to give a constant 3v or 3.3v, so it's always on.

    if on battery I'd want something to make it go into safe mode. that battery_setup is what gave me accurate battery voltage at 100% - I was powering it from a 3v external PSU. my basic autoexec beginning:

    Code: Text
    Log in, to see the code


    Widget displaying battery level and voltage of the device.

    Battery-powered wireless switch connected to an electronic circuit on a workbench.

    Added after 29 [minutes]:

    pics and things for the library/device list

    Wireless two-key switch and its box on a wooden surface. View of AAA batteries in an electronic device Close-up of an electronic module Model CBU on a PCB, showing pins and markings. Part of a device casing with the model designation LKWSW201_0202. Interior of a plastic battery compartment showing slots for two AAA batteries. Printed circuit board with buttons and electronic components. Printed circuit board with electronic components. Close-up of an electronic module with wires and soldered connections. Box of a Wi-Fi-enabled two-key remote. Notification of adding Wireless Switch device in the app. App interface for managing a wireless smart switch with different gesture clicks. Action selection menu for a wireless switch with options: Single Click, Long Press, Cancel. App screen showing no updates available.

    UART boot output

    Code: Text
    Log in, to see the code


    Tuya API

    Code: Text
    Log in, to see the code


    Code: JSON
    Log in, to see the code


    JSON
    Code: JSON
    Log in, to see the code


    https://github.com/OpenBekenIOT/webapp/pull/9...mits/c79c58d37697358f7ec4b6eb263d08038c0c2c26

    Device uses a custom firmware, so no GPIO extraction in Easy Flasher
  • ADVERTISEMENT
  • #5 21031178
    torte
    Level 3  
    Posts: 5

    Hi,

    I am very very new to the beken devices. This was the first time I flashed one.
    So I have zero idea :-)
    I only got this so far by reading here in the forum and youtube.
    My Autoexec.bat only contains "PowerSave 1"
    The batteries have lost 18% since yesterday.
    I will now try your Autoexec.

    But you can't do the double or long clicks, can you?
    I plan to use the switch for a roller shutter, a click is then up or down by step double click would then be automatically up or down

    Thank You
    Torsten
  • #6 21031184
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    Ah yes. We need a lot more to finish setup. Powersave 1 will not be enough to stop the batteries dying within a day or two.

    My device is not of use so far. I'll do some more playing.
  • #7 21031231
    torte
    Level 3  
    Posts: 5
    I tried the template and the buttons no longer worked for me.
    pin 16 is set to 47
    pin 20 is at 43

    :-)
    I locked myself out and removed the two slashes before the deep sleep 600 :-)
    thinking before doing is sometimes better
  • ADVERTISEMENT
  • Helpful post
    #8 21031239
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    ha, yes. does the safe mode button hold work? i've not tested that yet. you can always go into safe mode by removing power 5 times. it will broadcast AP when in safe mode
  • #9 21031359
    torte
    Level 3  
    Posts: 5

    your template also works
    hold button has not activated the save mode.

    pin 16, 20 works with 5, 6, 47, 43



    Screen displaying status of various switches and battery information.
  • Helpful post
    #10 21031367
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    yes. mostly the channel # doesn't matter as long as theyre different (with some exceptions).

    for example, this would be a working channel assignment for a simple device with one push button, one LED and one relay, where you want the LED to come on when you push the button to close the relay

    "6": "Btn;1",
    "7": "LED;1",
    "24": "Rel;1"

    Added after 10 [minutes]:

    to start us off we need to review this and make use of timer and button wake from deep sleep https://www.elektroda.com/rtvforum/topic4041971.html#21000316

    other posts around that contain the necessary config will be about battery powered temperature/humidity sensors and door/windows sensors. we should be able to adapt some of the relevant autoexec bits for us from those.

    Added after 3 [minutes]:

    so already we can see we should use pindeepsleep or pindeepsleep with timer

    Added after 10 [hours] 29 [minutes]:

    I'm slightly worried that however we set it up to work with batteries that we won't get it to wake, connect to wifi, wait for mqtt and send commands quickly enough to be useful/not annoying. Even if you set a static IP on the device so you're not waiting on DHCP.

    It would be good to see how quickly you could get achieve this with OBK (don't know Tuya do this to be so quick) but I may just pursue using it on 5v USB so it's always powered. Then I don't have to care about battery and deepsleep.

    Added after 46 [seconds]:

    Unless anyone else wants to chime in to say it *can* be achieved, with decent results, on battery.
  • #11 21176455
    hutchpe
    Level 1  
    Posts: 1
    I've managed to get simple functionality working with PinDeepSleep using the following pinout and autoexec.bat, haven't tested battery life yet.

    Code: JSON
    Log in, to see the code


    Code: Text
    Log in, to see the code
  • #12 21520643
    glate
    Level 2  
    Posts: 2
    For the life of me I can't get this switch to boot into download mode. There's not a ton of information about this specific switch so I thought I'd reach out in case any of you are willing to share some tips.

    Thanks in advance.
  • #13 21520881
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    >>21520643

    what does your wiring look like? how are you powering the device/module?
  • ADVERTISEMENT
  • #14 21521306
    glate
    Level 2  
    Posts: 2
    >>21520881

    I have the switch connected to a breadboard and a Sparkfun AP63203 - I had it connected to a cheap power supply but the voltage drop wasn't giving me confidence so I moved to use the buck converter.

    I only have one USB/UART adapter.

    Things I'm unsure of:
    1. I'm unsure whether I should have a common ground between my (single) usb/uart adapter and the power supply connected to GND. I've tried both ways.
    2. Some sites say I should connect SWS to ground as well?
    3. If I need to solder directly to the chip, if the pin headers are sufficient or if I have to desolder the CBU (scary)

    I've tried swapping TX/RX multiple times, etc. I can get boot logs off TX1/RX1 (pins 10 and 11) but besides that nothing. Have tried with both ltchiptool and BK7231Flasher.

    Pics:
    A breadboard with connected jumper wires, a UART module, and a push button, all set on a desk next to a keyboard.

    Electronic board with connected wires and visible programming pins.

    Thanks very much.

    Added after 7 [hours] 4 [minutes]:

    after all that it turns out the jumpers on my usb adapter had been bumped and it was in TTL to 232 mode. Overly complicated a simple process. Thanks!
  • #15 21521878
    divadiow
    Level 38  
    Posts: 4879
    Help: 427
    Rate: 868
    good job!

Topic summary

✨ The discussion revolves around the Tuya Smart Push Button Switch 2Gang 6 Scene Wireless Smart Home Remote Controller, specifically issues related to flashing Beken firmware and configuring button functionalities. The user, Torsten, successfully managed single-click operations but struggled with battery status and double/long click functionalities. Other participants shared insights on pin configurations, battery management, and autoexec scripts to enhance device performance. Suggestions included using specific pins for battery status and implementing deep sleep modes to conserve battery life. The conversation highlighted the need for a comprehensive setup to fully utilize the device's capabilities, including safe mode activation and button event handling.
Generated by the language model.

FAQ

TL;DR: “PowerSave 1 will not be enough,” and batteries can die in 1–2 days on the BK7231N Tuya LKWSW201. Use PinDeepSleep, map P16/P20 buttons, set battery pins, and run Battery_setup for correct 0–100% reporting. Safe‑mode recovery is available if deep sleep locks you out. [Elektroda, divadiow, post #21031184]

Why it matters: This helps makers flash and tune the 2‑gang LKWSW201 for reliable buttons, accurate battery, fast wake‑to‑MQTT, and safe recovery.

Quick Facts

What’s the correct pin mapping for this Tuya 2‑gang scene switch?

Use this tested mapping in OpenBeken. Buttons: P16 and P20 as Btn. Battery sense: P23 as BAT_ADC and P17 as BAT_Relay. Wi‑Fi LED: P26 as WifiLED_n. This pinout supports PinDeepSleep and MQTT workflows. [Elektroda, hutchpe, post #21176455]

How do I calibrate and publish battery percentage?

Start the battery driver, then calibrate. Run: startDriver battery; Battery_setup 2200 3000 2.05 2400 4096. Use Battery_cycle 20 for periodic reporting. Connect BAT_ADC to P23 and BAT_Relay to P17. This yields 0–100% battery via MQTT or UI. [Elektroda, hutchpe, post #21176455]

Why don’t double‑click events appear?

The Tuya model exposes “single_click” and “long_press” only. Double‑click is not a defined datapoint. Emulate it with firmware logic or automations if required. [Elektroda, divadiow, post #21030248]

How can I speed up wake‑to‑action on battery?

Wake on button, publish quickly, then sleep again. Deep sleep adds connection delay on battery. One expert wrote, “I may just pursue using it on 5V USB.” Consider USB power for always‑on responsiveness. [Elektroda, divadiow, post #21031367]

Do I need unique channel numbers for buttons and LEDs?

Channel numbers must be unique, not tied to GPIO numbers. Quote: “channel # doesn’t matter as long as they’re different.” Example: 6: Btn;1, 7: LED;1, 24: Rel;1. [Elektroda, divadiow, post #21031367]

How do I set up PinDeepSleep with MQTT publishing?

Use this wake‑and‑publish pattern.
  1. Map P16/P20 as Btn; set P23 BAT_ADC, P17 BAT_Relay; startDriver battery; Battery_setup 2200 3000 2.05 2400 4096; Battery_cycle 20.
  2. Add OnClick handlers to publish topics; add OnHold SafeMode; waitFor MQTTState 1.
  3. After 20 s, call PinDeepSleep 21600; add a 30 s failsafe sleep if MQTT fails. See working autoexec for exact aliases. [Elektroda, hutchpe, post #21176455]

I enabled DeepSleep and lost access. How do I recover?

Power‑cycle the device five times to enter SafeMode. It broadcasts an AP for recovery and reconfiguration. This bypasses a misconfigured deep‑sleep loop. [Elektroda, divadiow, post #21031239]

Does “PowerSave 1” meaningfully extend battery life?

No, not by itself. Quote: “PowerSave 1 will not be enough to stop the batteries dying within a day or two.” Use PinDeepSleep and short wake windows instead. [Elektroda, divadiow, post #21031184]

What battery drain did users observe before deep‑sleep tuning?

One user reported ~18% drop in about 24 hours. That was after flashing, with only PowerSave 1 configured. Tune deep sleep and MQTT flow to improve this. [Elektroda, torte, post #21031178]

Which Tuya datapoints does the device expose?

DP 1 and 2 are switch_type_1 and switch_type_2. They report “single_click” or “long_press.” DP 10 is battery_percentage, 0–100% integer. Product key is l8yaz4um5b3pwyvf. [Elektroda, divadiow, post #21030248]

Why are my battery readings offset?

Early battery readings can be too high without calibration. Quote: “The measurements will be ~300mA too high until further config.” Run Battery_setup to correct the scale and thresholds. [Elektroda, divadiow, post #21030110]

How do I get into download mode reliably on BK7231N?

Use a 3.3 V TTL USB‑UART and share ground with power. A unit stuck in RS‑232 mode blocked download mode. Swap TX/RX as needed; boot logs appeared on TX1/RX1 (pins 10/11). [Elektroda, glate, post #21521306]

What’s the Tuya product key and model string for this board?

Tuya lists this board as model LKWSW201 with “Wireless Switch” category. Product_id is l8yaz4um5b3pwyvf and schema 000004h1bx. [Elektroda, divadiow, post #21030248]

Does this scene switch share hardware with other Tuya devices?

Yes, it shares PCB/chassis molds with a related “double switch” build. This affects casing and mounting compatibility only. [Elektroda, divadiow, post #21030110]
Generated by the language model.
ADVERTISEMENT