Elektroda.com
Elektroda.com
X
Elektroda.com

OpenBeken and TuyaMCU dimmer - configuration guide/tutorial

p.kaczmarek2 3213 4
This content has been translated flag-pl » flag-en View the original version here.
  • OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial


    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:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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.
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    The set also includes instructions:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial

    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
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    Two dimmers next to each other, functional and damaged:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    What does the dimmer have inside? First of all, the WB2S WiFi module + Holtek HT66F3195 microcontroller. They communicate via UART.
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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.
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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: script
    Log in, to see the code

    And in the App panel, drag it to the OBK file system:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    This is how the different levels of brightness look like:
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial OpenBeken and TuyaMCU dimmer - configuration guide/tutorial

    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):
    OpenBeken and TuyaMCU dimmer - configuration guide/tutorial
    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:
    Code:

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

    The one at 50% brightness:
    Code:

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

    It will turn it off after 5 seconds:
    Code:

    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 .

    Cool? Ranking DIY
    Can you write similar article? Send message to me and you will get SD card 64GB.
    About Author
    p.kaczmarek2
    Level 27  
    Offline 
    p.kaczmarek2 wrote 2159 posts with rating 3937, helped 94 times. Been with us since 2014 year.
  • #3
    p.kaczmarek2
    Level 27  
    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 (fortunately) documentation and SDK ... but this proves that BK7252 is not popular and is not used in many devices. And if it is not popular, it has a lower priority than, for example, support for WiFi systems from Realtek, type WBR3, WBR2, etc.

    Well, okay, you convinced me, I bought one A9 mini camera and we'll see what it will be when the package arrives.
  • #4
    austin007
    Level 17  
    @ 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 hence the choice. I'm more interested in zigbee devices, but streaming requires something else. The camera is cheap, it has some power, IR and motion detection as well as SD card recording. If we could keep these functionalities and enable integration with HA, it would be a very interesting solution.
    The picture itself probably does not break anything, but at this price. I just ordered it, so I don't know which converter is there. I would still lack a Lan connection to monitor the parking space in the underground garage, ... but not the cash register.
  • #5
    noel200
    Level 26  
    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 to esp? Can you upload the firmware from ESP to BK?