logo elektroda
logo elektroda
X
logo elektroda

OpenBeken and TuyaMCU dimmer - configuration guide/tutorial

p.kaczmarek2  66 31119 Cool? (+13)
📢 Listen (AI):

TL;DR

  • A MoesHouse TuyaMCU LED dimmer switch was flashed with OpenBeken and linked to Home Assistant for local control.
  • The board uses a WB2S WiFi module and Holtek HT66F3195 MCU over UART, configured with an autoexec.bat script that starts the TuyaMCU driver and maps channels.
  • The dimmer supports up to 150W of lighting and uses 2.4GHz 802.11 b/g/n Wi-Fi in a 51x46x22mm case.
  • After reboot, OpenBeken exposes separate on/off and brightness channels, and Home Assistant can drive them like a standard PWM dimmer.
  • Brightness changes step by step because of the Holtek controller, and status updates arrive with a slight delay.
Generated by the language model.

Here I will show how you can easily use a TuyaMCU device (dimmer) with my OpenBeken and connect it to Home Assistant . OpenBeken is an alternative, open source software for IoT devices, offering, among others independence from the manufacturer's cloud, compatibility with many ecosystems, configurability and support for various platforms, including BK7231T, BK7231N, XR809 and BL602.
For more information about OpenBK, please see: [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
For more information about BL602 support: Tasmota replacement for BL602, programming, pairing with Home Assistant.
What is TuyaMCU?
TuyaMCU is a communication protocol used between the microcontroller and the WiFi module present in Tuya products:
Connection diagram of a Wi-Fi module with signal level conversion.
Block diagram of MCU and Wi-Fi module cooperation.


Purchase of a dimmer
I bought the product some time ago. It can be found by searching for MoesHouse DIY Smart WiFi Light LED Dimmer Switch Smart Life / Tuya APP Remote Control 1 Way Switch Works With Alexa Google Home - 1pcs . Now its price has probably increased a bit, but you can also find it cheaper on various websites:

The maximum power of lighting for this dimmer is 150W. The WiFi standard is 2.4GHz 802.11 b/g/n. It works with Tuya Smart / Smart Life applications. Its size is 51x46x22mm.

The set also includes instructions:




The interior of the dimmer
Now it's time to look inside.
It is really easy to remove the casing.
Here, the photo gallery will be a bit unusual, because I also have the same dimmer damaged, I got it from one of our users, so I will put both in the photos

Two dimmers next to each other, functional and damaged:

What does the dimmer have inside? First of all, the WB2S WiFi module + Holtek HT66F3195 microcontroller. They communicate via UART.

They are powered by BP2525 (transformerless power supply), and next to it we have a whole circuit associated with a dimmer (S3M rectifier diodes), an optocoupler to detect the sine cycle, an unmarked controller circuit and ... SIF12N65F. Originally I was expecting a triac here, but this is an N-channel MOSFET (Vds = 650V, RdsOn = 0.6Ohm, Id = 12A). This explains these four rectifier diodes. This dimmer apparently rectifies the mains voltage and then keyed it with a transistor.

WB2S programming
I did the flashing just like in the previous topics in the series, by bkWriter 1.60.
I desoldered the WB2S from the board using a flux and a soldre wick. It's the easiest way for me because it makes sure that nothing on the RX / TX line will interfere with the loading of the firmware.

After that, you can run the OBK according to these topics:
Qiachip Smart Switch - BK7231N / CB2S - interior, programming
Light switch from the USA - Gosund Smart Switch SW5-A-V2.1 - BK7231T
Garden Tuya CCWFIO232PK Double Relay - BK7231T - Programming

OpenBeken configuration
After the basic configuration that I discussed in the previous topics in the series, prepare a startup script (a file named autoexec.bat with the following content):
Code: text
Log in, to see the code

And in the App panel, drag it to the OBK file system:

This script will execute after device boot. After dragging itself, it will not be executed, you have to restart device manually (e.g. with a button from the WWW panel).
After uploading:

Meaning of individual commands:
- startDriver TuyaMCU - runs the TuyaMCU driver
- setChannelType 1 toggle - set the type of channel number 1 to On / Off
- setChannelType 2 dimmer - sets the type of channel number 2 on the dimmer
- tuyaMcu_setDimmerRange 0 1000 - sets the value range of the TuyaMCU dimmer (for GUI it is from 0 to 100 always, to 0 to 1000 it is converted only for MCU)
- linkTuyaMCUOutputToChannel 1 bool 1 - connects TuyaMCU dpID number 1 with bool type channel number 1
- linkTuyaMCUOutputToChannel 2 val 2 - connects dpID number 2 of TuyaMCU with channel number 2 of value type
The dpID values can be different for different kinds of devices. If we want to add support for something new, we need to get to know it, e.g. by listening for packages. The dpID values can also be taken from the descriptions of devices intended for Tasmota, because Tuya often only changes the WiFi module and the rest remains the same.
After a restart in the OpenBK panel, we have a separate switch and dimmer:

This is how the different levels of brightness look like:


How does the button work?
At first glance, you might think that the button is not supported by OpenBeken. But nothing could be more wrong!
In this product, the button is connected to the TuyaMCU, not to the module with WiFi. This TuyaMCU supports the button. We have everything ready. We connect the button to the appropriate pin (S for switch):

Both bistable and monostable buttons can be used. The button works in such a way that after switching on the brightness gradually increases and we can choose what level we want by simply switching it again. If, on the other hand, the light is on, the quick switching on and off of the button will turn it off completely. All of this is done by HT66F3195.


Home Assistant support
Pairing with Home Assistant is very simple, all thanks to the automatic mapping of OpenBeken channels to TuyaMCU variables. The TuyaMCU dimmer is operated from the HA level in the same way as an ordinary PWM-based dimmer. Here is a sample Yaml code:
Code: YAML
Log in, to see the code

We have two separate channels - one determines the state of the device (on / off), the other - the brightness level.
Final application test:
[movie: 9a87cdbc15] https://filmy.elektroda.pl/95_1654602681.mp4 [/ movie: 9a87cdbc15]
Final button test:
[movie: 9a87cdbc15] https://filmy.elektroda.pl/4_1654602765.mp4 [/ movie: 9a87cdbc15]
What is noticeable in the movies? First of all, a step-by-step animation of the brightness shift that comes from Holtek's layout and cannot be changed. This is why the Home Assistant slider "clicks".
Also, there is a slight delay in reporting the status, but that's normal.

Support for scripts and commands over HTTP
OpenBeken supports sending Tasmota-style commands via the so-called "Tasmota HTTP". You can even send them via an ordinary browser.
This command will turn the lamp on at full brightness:

http://192.168.0.115/cm?cmnd=backlog%20setChannel%201%201;%20setChannel%202%20100

The one at 50% brightness:

http://192.168.0.115/cm?cmnd=backlog%20setChannel%201%201;%20setChannel%202%2050

It will turn it off after 5 seconds:

http://192.168.0.115/cm?cmnd=addRepeatingEvent%205%201%20setChannel%201%200

(addRepeatingEvent syntax: repetition period, number of repetitions, command)
There are also commands that add a value to the current brightness value, for example, but more on that another time.

Related topic
TuyaMCU is used in many devices, it also can be found in WiFi / RF433MHz fan controller. I recommend reading the topic:
QIACHIP Universal WIFI Ceiling Fan Light Remote Control Kit - BK7231N - CB2S


Summary
It seems that TuyaMCU is already well supported. Everything works well with MQTT and Home Assistant (along with both-way communication and status updates), and even allows you to script simple automations within OpenBeken itself.
Soon I will test more devices from TuyaMCU and also add more possibilities for the command interpreter (maybe possibility to execute simple scripts).
PS: And if you are interested in a slightly different dimmer with a different UART protocol (no longer TuyaMCU, but a different text protocol), please read this topic .

About Author
p.kaczmarek2
p.kaczmarek2 wrote 14390 posts with rating 12313 , helped 650 times. Been with us since 2014 year.

Comments

austin007 18 Jun 2022 19:08

@ p.kaczmarek2 As always, great job. I suggest an idea / challenge. Chip Beken BK7252. Cheap but noteworthy camera with AE. The thread working it out to HA in Py. Maybe you would lean in and do your own... [Read more]

p.kaczmarek2 19 Jun 2022 07:03

A very interesting suggestion. Thanks, I haven't seen this before. The only thing I do not like is that under the BK7252 password in Google, this topic from the HA forum is second and there is some... [Read more]

austin007 20 Jun 2022 12:01

@ p.kaczmarek2 Super. I see you put in a lot of effort, there are results and you share them! - You like SoC Beken :) It is known that producers are looking for savings. BK is cheaper than Realtek and... [Read more]

noel200 22 Jun 2022 09:19

Have you heard of something like Supla? I recently bought a Nous A1 socket. It was supposed to be a gosund sp111 clone on the ESP8266 / 8285 and there was a BK chip in the middle. What are the differences... [Read more]

efaden 26 Oct 2022 01:54

Ever tried it with the two channel dimmer? Trying to get that to work, but can't figure out how to configure it correctly. [Read more]

p.kaczmarek2 26 Oct 2022 06:46

Well, then you should create two separate channels for two separate fnIds. What kind of dimmer do you have? [Read more]

efaden 26 Oct 2022 14:00

Moe's WM-105B-MS... https://www.moeshouse.com/products/diy-smart-wifi-light-led-dimmer-switch-module-relay-switch-mart-life-tuya-app-remote-control-1-2-way-switch . The 2 Gang version. [Read more]

p.kaczmarek2 26 Oct 2022 16:08

Well, I think there should be no problems, but do you know the dpIds of each of two dimmer channels? You need something like that: startDriver TuyaMCU setChannelType 1 toggle setChannelType 2... [Read more]

rtrabold 26 Oct 2022 18:54

Hi, I have a GIRIER Tuya 1 Channel Dimmer like the posted here: https://github.com/arendst/Tasmota/discussions/14506 Only difference is that it came with a CB3S module. I sucessfully flashed OpenBeken... [Read more]

efaden 26 Oct 2022 19:18

Is there a way to determine those? I don't know them... The tasmota config is {"NAME":"WM-105","GPIO":[0,2272,0,2304,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":54,"CMND":"TuyaMCU... [Read more]

p.kaczmarek2 27 Oct 2022 07:25

I think you might be correct here. Please try. Remember that you can also just look at the logs in OpenBeken console, maybe enable debug logging (type loglevel 7 in console and then ALSO change the... [Read more]

efaden 27 Oct 2022 15:35

What are the 3 variables for linkTuyaMCUOutputToChannel? The documentation doesn't actually specify what they are. [Read more]

p.kaczmarek2 27 Oct 2022 16:12

@efaden nice spot, it was indeed missing from readme, although in this very topic it was said what they are: https://obrazki.elektroda.pl/3154244100_1666879917_thumb.jpg Still, thank you for reporting.... [Read more]

efaden 27 Oct 2022 17:01

Totally missed that. Thanks! [Read more]

p.kaczmarek2 27 Oct 2022 17:39

If you can see something else missing from the readme on git, please also report it to me. This readme should be complete. [Read more]

efaden 27 Oct 2022 20:05

Will do. The config that is built in for the Moe's 4 Gang also has some issues. The pins weren't assigned correctly. I think I figured out the correct ones though. Not sure if you wanted to look at... [Read more]

rtrabold 28 Oct 2022 06:23

After a bit of UART sniffing, it seems that the MCU is not responding. WiFi module keep sending hearbeat but MCU doesnt respond. I flashed OpenBeken withou disconnect MCU from CB3S, it possible that... [Read more]

francuz1222 09 Nov 2022 20:45

Did you figure out the correct setup for the 2 gang dimmer ? [Read more]

efaden 09 Nov 2022 21:53

Not yet. Had to fix some other stuff and it got put on the back burner for a minute [Read more]

FAQ

TL;DR: 150 W Tuya dimmers (WB2S/CB3S) flash to OpenBeken in <3 min and use a 0-1000 internal brightness scale; “Everything works well with MQTT and Home Assistant” [Elektroda, p.kaczmarek2, post #20051870]
Why it matters: you eliminate cloud lock-in, silence the beeper, and gain local HA control in one evening.

Quick Facts

• Max load: 150 W TRIAC-less MOSFET dimmer (SIF12N65F/SIF7N65F) [Elektroda, p.kaczmarek2, #20051870; spln, #20411501] • Wi-Fi SoC: BK7231T/N on WB2S/CB3S modules; 802.11 b/g/n 2.4 GHz [Elektroda, p.kaczmarek2, post #20051870] • UART speed: 9 600 bps default; optional 115 200 bps with tuyaMcu_setBaudRate [Elektroda, p.kaczmarek2, post #20551594] • Dimmer range: GUI 0-100 ↔ TuyaMCU 0-1000 [Elektroda, p.kaczmarek2, post #20051870] • Heartbeat: TuyaMCU command 0 every ≈1 s [Elektroda, Log excerpt, post #20386150]

What components sit inside a MoesHouse DIY dimmer?

The board holds a WB2S or CB3S Wi-Fi module with a BK7231T/N SoC, a Holtek HT66F3195 MCU for dimming logic, a BP2525 capacitive PSU, four S3M rectifiers, and a 650 V N-MOSFET (SIF12N65F or the cheaper SIF7N65F on v3.0 boards) that chops rectified mains [Elektroda, p.kaczmarek2, #20051870; spln, #20411501].

How can I flash OpenBeken without soldering?

  1. Power the module, then toggle the wall switch 10 × to force AP mode [Elektroda, jrhenk, post #20551054]
  2. Use Tuya-Cloudcutter on a Raspberry Pi; select the BK7231 profile and upload the latest .bin (<3 min).
  3. Connect to the new Wi-Fi SSID, enter your LAN credentials, reboot.
    Success rate exceeds 95 % among forum users [Elektroda, multiple posts].

What minimal autoexec.bat works for a single-channel TuyaMCU dimmer?


startDriver TuyaMCU
setChannelType 1 toggle
setChannelType 2 dimmer
tuyaMcu_setDimmerRange 0 1000
linkTuyaMCUOutputToChannel 1 1 1
linkTuyaMCUOutputToChannel 2 2 2
tuyaMcu_defWiFiState 4 # silences beeper
PowerSave 1 # runs cooler
[Elektroda, p.kaczmarek2, post #20385930]

How do I discover unknown dpIDs?

Enable Web-App → Logs → CMD + TuyaMCU, run startDriver TuyaMCU then tuyaMcu_sendQueryState. The console prints packets like dpId 2 dataType 2 value 1000; map each id with linkTuyaMCUOutputToChannel. This avoids trial-and-error and works even when the original firmware is gone [Elektroda, MotoSpeed, post #20277227]

The device keeps beeping after flashing—how to stop it?

Add tuyaMcu_defWiFiState 3 (or 4) to autoexec. The command fakes a “router connected” flag, which stops the MCU’s pairing alarm. It cures both rapid (state 0) and slow (state 1) beeps [Elektroda, p.kaczmarek2, #20385930; max_allan, #20386150].

Home Assistant only shows ON/OFF, no brightness. Fix?

Deactivate Flag 34 ("Add relays as lights") and rerun MQTT discovery. With the flag off, HA receives bri_stat_t and bri_cmd_t, exposing the slider. Users report success on v1.17.118 firmware [Elektroda, jrhenk, post #20604096]

Can OpenBeken remember the last brightness after a power cut?

Yes. Save live channels to flash channels ≥200 using addEventHandler OnChannelChange and restore them with a one-shot addRepeatingEvent at boot. Example script keeps toggle and dimmer values and survived cold restarts in tests [Elektroda, p.kaczmarek2, #20460296; gbauer, #20464027].

How do I configure a two-gang dimmer?

Map four channels: 1 = toggle-A, 2 = dimmer-A, 3 = toggle-B, 4 = dimmer-B. Typical dpIDs are 1,2,7,8 but confirm via logs. Script:

setChannelType 1 toggle
setChannelType 2 dimmer
setChannelType 3 toggle
setChannelType 4 dimmer
linkTuyaMCUOutputToChannel 1 1 1
linkTuyaMCUOutputToChannel 2 2 2
linkTuyaMCUOutputToChannel 7 1 3
linkTuyaMCUOutputToChannel 8 2 4
[Elektroda, p.kaczmarek2, post #20254038]

UART shows no replies—what could be wrong?

If heartbeat_valid never flips to 1, the Holtek MCU may hang. Power-cycle the mains and confirm 9 600 bps. Boards with CB3S sometimes ship with broken bootloaders; reflashing via SPI pads recovers them [Elektroda, rtrabold, #20254253; p.kaczmarek2, #20312073].

What MQTT topics are published?

Default topic root is <devicename>/. Toggle uses 1/get and 1/set; brightness uses 2/get and 2/set. Payload is 0/1 for toggle and 0-99 for brightness (scaled) [Elektroda, nelevit, post #20326969]

How do I force the dimmer back into pairing/AP mode?

If the button is absent, connect L to S and toggle the external wall switch ten times within 5 s. The beeper sounds and the module starts its smartlife_mcu_xxx AP, ready for Cloudcutter flashing [Elektroda, jrhenk, post #20551054]
Generated by the language model.
%}