logo elektroda
logo elektroda
X
logo elektroda

Avatto DMS16-W1 CBU Dimmer + Puya PY32F002A MCU: OpenBeken Flashing and Autoexec Setup

divadiow 4662 62

TL;DR

  • Avatto DMS16-W1 1-channel dimmer smart switch uses a CBU module talking to a Puya PY32F002A TSSOP-20 MCU.
  • The CBU riser was de-soldered, the factory firmware dumped with Easy Flasher, and TuyaMCU traffic captured with TuycaMCU Analyser and dual USB-TTL adapters.
  • The extracted firmware config showed baud 115200, and the full dpID map includes values the user still never saw for dpIDs 13 and 47.
  • OpenBeken autoexec now works for most functions and mirrors factory MCU communications, but mains testing is pending and the brightness-range dpID3 behavior remains unresolved.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • #61 21711887
    sp4rk1e
    Level 10  
    Posts: 37
    Help: 3
    Rate: 5
    great. I didn't realize that 'OnRelease' is *not* sent for other button presses (OnClick etc.) than 'OnHold'. That's why I made the conditionals.

    Testet now the firmware support with a super simple script (but same functionality) - works 👍‍

    // device: Moyes MS-105
    //
    // features:
    // short press: switches on/off
    // long press if device is on: dim either up or down
    // long press if device is off: turn on at brightness zero, continue from there with dim up
    // if brightness reaches the upper or lower bound: reverse dim direction (ping pong)
    // after long press: reverse dim direction

    
    startDriver TuyaMCU
    tuyaMcu_defWiFiState 4
    PowerSave 1
    SetFlag 10 0                // Flag 10 - [MQTT] Broadcast self state on MQTT connect DONT CLUTTER LOG
    SetButtonTimes 2 3 2        // provides fast response and low lag, works with bDPCache==2 only (see below)
                                // must use Version: noread_e8ef72c891b1 for that
    SetChannel 14 4             // define dim stepsize
    
    // P6 connected to the push button
    SetPinChannel 6 10
    SetPinRole 6 Btn
    
    alias turn_on_at_zero backlog SetChannel 1 1; SetChannel 2 1
    
    setChannelType 1 toggle
    linkTuyaMCUOutputToChannel 1 bool 1
    
    setChannelType 2 dimmer
    tuyaMcu_setDimmerRange 0 1000
    linkTuyaMCUOutputToChannel 2 val 2 2    // new "bDPCache" "flags" arg: 2 means "do not read"
    
    addEventHandler OnClick    6 toggleChannel 1
    addEventHandler OnHold     6 if $CH1==0 then turn_on_at_zero else "addChannel 2 $CH14 0 100 2" 
    addEventHandler OnRelease  6 addChannel 2 $CH14 0 100 3  // new flag 3
    
    
  • ADVERTISEMENT
  • #62 21711892
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    It should work, however.... I think it's actually sent for other events than hold, it's just it does not break anything in this approach.
    Helpful post? Buy me a coffee.
  • #63 21773291
    paede
    Level 5  
    Posts: 4
    How long does it take to dim from low to high? I had an issue with the MS-105 that it took approx 5 sec.
    If you switch on, does it goes straight to 100% brightness or does it dims up to 100% ?
📢 Listen (AI):

Topic summary

✨ The discussion focuses on the Avatto DMS16-W1 1-channel dimmer smart switch featuring a CBU module communicating with a Puya PY32F002A MCU (TSSOP-20). Users explore flashing the device with OpenBeken firmware, identifying and mapping Tuya dpIDs for channel control, and configuring autoexec.bat scripts for proper operation. Key findings include dpID assignments for power on/off, brightness control, brightness range, switch type, power-on status, and timer functions, with variations noted in similar models like the Avatto DMS16-Y1 and 2-channel versions. Contributors share firmware dumps, flashing experiences, and configuration examples, including setting dimmer ranges, linking TuyaMCU outputs to channels, and enabling HTTP button drivers. The conversation also references tools and resources for sniffing dpIDs, restoring original firmware, and improving UI via REST pages. Overall, the thread provides practical insights into customizing and controlling Avatto dimmer switches using OpenBeken firmware and Puya MCU integration.
Generated by the language model.

FAQ

TL;DR: For OpenBeken users modding Avatto dimmers, the proven path is 115200 baud with a TuyaMCU mapping; as one expert put it, "the ignore flag support is the only change really required" for stable scripted dimming. This FAQ shows how to flash the CBU, map 1CH/2CH dpIDs, and build reliable autoexec dimming with MCU feedback control. [#21711817]

Why it matters: This thread turns a partly working Tuya dimmer conversion into a repeatable OpenBeken setup, including stable dimming, dual-channel mapping, and custom button behavior.

Wariant Kanały Kluczowe dpIDs jasności Baud TuyaMCU Stan w wątku
Avatto DMS16-W1 1 2, 3, 5 115200 Działa z autoexec; min/max nadal niestandardowe
Avatto DMS16-Y1 1 2, 3, 6 115200 Potwierdzony timer i test z żarówką tradycyjną
Avatto 2CH 2 CH1: 2/3/5, CH2: 8/9/11 115200 Działa po mapowaniu dpID 7–12
Moyes MS-105 1 2 niewskazany w cytowanym skrypcie Użyty do porównania zachowania ping-pong

Key insight: Najlepsze efekty dało przeniesienie przycisku z MCU na GPIO modułu BK7231N/CBU i sterowanie jasnością zdarzeniami OpenBeken. Gdy MCU odsyła opóźnione poziomy dimmera, flaga mapowania 2 może ignorować ten odczyt i wygładzić działanie. [#21708368]

Quick Facts

  • Puya PY32F002A to MCU ARM Cortex-M0+ do 24 MHz, z do 20 KB Flash, 3 KB SRAM i zasilaniem 1.7–5.5 V; w tym dimmerze współpracuje z modułem CBU przez UART. [#21164436]
  • Dla Avatto DMS16-W1 autor potwierdził konfigurację fabryczną "baud":"115200", a ten sam baud wykorzystano potem w tuyaMcu_setBaudRate 115200. [#21164436]
  • Zakresy DP dla 1CH są konkretne: jasność 10–1000, timer 0–86400 s, a pamięć stanu po zasileniu ma trzy tryby: off / on / memory. [#21164436]
  • W wersji 2CH drugi kanał kontynuuje numerację logicznie od dpID 7 do 12, co pozwoliło uruchomić osobne On/Off, brightness, min, max i countdown dla CH2. [#21441155]
  • Dla szybkiego ściemniania po przepięciu przycisku na GPIO działały ustawienia SetButtonTimes nawet 2 3 2 lub 10 3 1, ale stabilność zależała od ignorowania sprzężenia zwrotnego dimmera i czasem od kolejki TuyaMCU. [#21711591]

How do I flash OpenBeken onto an Avatto DMS16-W1 dimmer with a CBU module and a Puya PY32F002A MCU?

Flash the CBU, not the Puya MCU. 1. De-solder the CBU riser so you can dump or flash the Wi-Fi module separately with Easy Flasher. 2. Read the factory dump first and note the extracted UART config, which was 115200 on this device. 3. Reinstall the CBU, boot OpenBeken, then use TuyaMCU mapping to talk to the Puya over UART. J-Link access to the Puya failed in the thread even with NRST held low, so the working route was replacing only the CBU firmware. [#21164436]

What is TuyaMCU Analyzer, and how does it help capture dpIDs and UART traffic on Avatto dimmers?

"TuyaMCU Analyzer" is a UART analysis tool that captures Tuya MCU packets, identifies dpIDs, and correlates app actions with serial traffic in real time. In this thread it was the winning method for recording what changed when the official Tuya app toggled power, brightness, countdown, switch type, and memory settings. With the CBU riser removed and two USB-TTL adapters connected, the author could compare factory behavior against OpenBeken autoexec commands and build a correct mapping for dpIDs 1, 2, 6, and 14. [#21164436]

Which dpIDs are used by the Avatto DMS16-W1 1-channel dimmer for power, brightness, min/max brightness, countdown, switch type, and power-on state?

The 1-channel Avatto DMS16-W1 uses dpID 1 for power, 2 for brightness, 3 for minimum brightness, 5 for maximum brightness, 6 for countdown, 47 for switch type, and 14 for power-on state. The thread also lists dpID 4 as led_type_1 and dpID 13 as work_mode. Specific ranges are given: brightness and min/max are 10–1000, countdown is 0–86400 s, and power-on state supports off, on, and memory. [#21164436]

How should I write an OpenBeken autoexec.bat for the Avatto DMS16-W1 using startDriver TuyaMCU, tuyaMcu_setBaudRate 115200, and linkTuyaMCUOutputToChannel?

Use a minimal TuyaMCU mapping first, then add extras. Start with startDriver TuyaMCU, tuyaMcu_setBaudRate 115200, and tuyaMcu_defWiFiState 4. Map dpID 1 as bool to channel 1, dpID 2 as val to channel 2, dpID 6 as a text/countdown field, and dpID 14 as enum for power-on behavior. Set channel 2 as Dimmer and apply a hardware range such as 90 600 or 200 1000. The thread’s working scripts also add httpButtons, SetFlag 43 1, and event handlers when the physical switch is rewired to a GPIO. [#21708368]

Why does OpenBeken show a 0-100 dimmer slider in the GUI even when tuyaMcu_setDimmerRange is set to 200 1000 or 90 600?

OpenBeken shows the dimmer as a normalized 0–100 GUI value even when the TuyaMCU hardware range is different. The author explicitly observed that tuyaMcu_setDimmerRange 200 1000 still displayed a fixed 0-100 slider, while UART traffic proved the module sent correct raw Tuya values to the MCU. Later scripts kept the same pattern with ranges like 90 600 and comments that this hardware range is mapped to 0, 100 in the GUI. [#21164436]

What is the difference between the Avatto DMS16-W1/W1 and DMS16-Y1 dimmer variants discussed in the thread?

The thread treats DMS16-W1 and DMS16-Y1 as very similar 1-channel dimmers, but the Y1 variant added a visible countdown-to-off behavior in testing. The Y1 owner reported it worked great with a traditional incandescent bulb and listed the same core dpIDs: 1 for power, 2 for brightness, 3 for brightness range, 4 for switch type, 6 for timer, and 14 for power-on state. The reported baud in extracted config was also 115200, matching the W1 workflow. [#21173417]

How can I map the 2-channel Avatto dimmer dpIDs in OpenBeken, including CH2 values like dpID 7, 8, 9, 10, 11, and 12?

Map the 2-channel unit as CH1 on dpID 1–6 and CH2 on dpID 7–12. In the working 2CH autoexec, CH2 used dpID 7 for On/Off, 8 for brightness, 9 for minimum brightness, 10 for switch type, 11 for maximum brightness, and 12 for countdown. dpID 14 stayed global for power-on behavior. The author confirmed this layout by extracting the Tuya model JSON, where switch_led_2, bright_value_2, brightness_min_2, led_type_2, brightness_max_2, and countdown_2 followed the first channel directly. [#21441155]

What is the best way to handle brightness_min and brightness_max dpIDs in OpenBeken when the Tuya app uses a custom dual-ended range control?

The practical solution is to expose brightness_min and brightness_max as separate controls, not to mimic Tuya’s custom dual-ended slider. OpenBeken did not have a built-in channel type for that UI, and the firmware author said it would need to handle two dpIDs at once. The suggested fallback was two independent sliders, one for minimum and one for maximum, or a custom REST page if you want a better UI. That matches the thread’s conclusion: the Tuya range widget is custom, while OBK’s core mapping stays simpler. [#21164833]

Why does dimming flicker or jump on some TuyaMCU dimmers when using addChannel from OpenBeken event handlers?

Dimming can jump because the MCU reports delayed brightness feedback after OBK already sent a newer value. In logs, a hold event raised channel 2 to 91, but the MCU then reported raw value 554, which OBK mapped back to 90; the same pattern repeated at 93→92 and 95→94. Later testing showed these dimmers change brightness smoothly inside the MCU, so feedback can lag scripted commands. On Avatto DMS16-W1, that lag still caused sporadic flicker even after other fixes, while the compared Moyes MS-105 did not show the same issue. [#21707334]

How does Flag 43 '[TuyaMCU] Use queue' affect stability when sending rapid dimmer commands to a TuyaMCU device?

Flag 43 enables a TuyaMCU send queue so OBK does not push two packets at once. The firmware author described it as a stability aid for rapid command bursts, especially during hold-based dimming. It improved the theory of packet timing, but it did not fully cure Avatto flicker in this thread; the user still saw sporadic brightness flashes during addChannel dimming. The flag was also reported as a GUI/template inconsistency at one point, but it could be set with SetFlag 43 1 in autoexec and was shown correctly in the main flags page. [#21706850]

What does the new linkTuyaMCUOutputToChannel flags argument do, and how does flag value 2 ignore dimmer feedback from the MCU?

The new flags argument extends linkTuyaMCUOutputToChannel so 2 means “ignore read” for that mapping. In practice, linkTuyaMCUOutputToChannel 2 val 2 2 lets OBK send brightness to the MCU while discarding the MCU’s delayed dimmer feedback. That mattered because user scripts on rewired buttons expected their own channel values to win. The firmware author changed the older bDPCache argument into a flags field, where 1 keeps DP cache behavior and 2 suppresses incoming readback for that mapped channel. [#21707931]

How can I rewire the external S1 switch from the MCU to a BK7231N/CBU GPIO and use OpenBeken OnClick, OnHold, and OnRelease events for dimming?

Move S1 off the MCU and wire it to a CBU GPIO plus ground, then let OpenBeken handle the logic. 1. Physically isolate the switch terminal from the old MCU trace and connect it to a GPIO such as P28 on Avatto or P6 on Moyes; users noted terminal N was already tied to 3.3 V circuit ground. 2. Set that pin as Btn. 3. Bind OnClick to toggle power, OnHold to addChannel dimming, and OnRelease to reverse direction if needed. This gave short-press, long-press, and custom dimming behaviors the factory MCU logic did not provide. [#21706499]

What is ping-pong dimming mode in OpenBeken addChannel, and how is mode 2 different from mode 3?

Ping-pong mode makes addChannel bounce between the minimum and maximum instead of clamping or wrapping. With mode 2, OBK remembers direction and automatically reverses when the channel reaches limits such as 0 or 100; the author’s self-test showed a sequence like 0, 25, 50, 75, 100, 75, 50. With mode 3, OBK does not change brightness; it only flips the stored ping-pong direction in place. That let users dim on hold and reverse direction on release or another event. [#21711805]

OpenBeken event scripting vs the original MCU-controlled switch logic on Avatto and Moyes dimmers — which approach works better for custom dimming behavior?

OpenBeken event scripting works better when you want custom dimming behavior. The original MCU-controlled external switch on these dimmers mainly handled On/Off, and users could not get brightness control from the stock Avatto switch logic even after trying flip, sync, and button modes. By moving the switch to a BK7231N GPIO, users added short-press toggle, long-press dimming, release-triggered direction changes, and ping-pong dimming. One thread expert summarized the benefit clearly: rewiring to the Wi-Fi module “allows interesting new features the original device is lacking.” [#21708368]

How long does it take these OpenBeken-configured Avatto or Moyes dimmers to go from minimum to maximum brightness, and what happens on power-on: instant full brightness or a smooth ramp-up?

The thread does not give a confirmed low-to-high timing for Avatto or Moyes after the final scripts, and one later user asked whether the MS-105 still took about 5 s. What is clear is that both devices dim smoothly inside the MCU, and the user scripts often turn the light on at a very low level first, for example with SetChannel 2 1, then continue dimming upward on hold. That means power-on in the custom script can be a controlled low-start rather than an instant jump to 100%, but no final benchmark in seconds was posted. [#21773291]
Generated by the language model.
ADVERTISEMENT