logo elektroda
logo elektroda
X
logo elektroda

Tuya Dimmer BK7231N Serial Protocol: Hex Commands for On/Off & Backlight Control

james13 327 6
ADVERTISEMENT
  • #1 21767005
    james13
    Level 2  
    I have a Tuya dimmer switch, It has a Beken unit in it BK7231N it had a and and - symbol on it and a middle on and off switch.
    It talks serial to a chip that is unmarked with a baud rate of 9600

    Tuya Dimmer BK7231N Serial Protocol: Hex Commands for On/Off & Backlight Control

    The protocol is structured so a variable length of hex values is sent and then some are received. The ones that are received contain the status. The sending ones are telling the electronics what to do (Control). All message start with 55 this gives a nice square wave for each side to sync with. Then AA...

    Here are the signals I found that do specific thinks like

    on/off .
    This is the protocol in hex values.
    TX
    light on
    55AA0006000501010001010E

    RX
    55AA03070005010100010112
    55AA03070005010100010112
    55AA03070008020200040000030C28
    55AA03070008030200040000000A24
    55AA0307000805020004000003E807
    55AA0307000806020004000000001D
    55AA030700050E040001002155AA030700051A010001012B

    light off
    TX
    55AA0006000501010001000D

    RX
    55AA03070005010100010011
    55AA03070005010100010011
    55AA0307000802020004000000D0E9
    55AA03070008030200040000000A24
    55AA0307000805020004000003E807
    55AA0307000806020004000000001D
    55AA030700050E040001002155AA030700051A010001012B

    by holding down the middle button the back light can be turned on and off. With the following signals.

    back light on
    TX
    55 AA 00 06 00 05 1A 01 00 01 01 27

    RX
    55AA030700051A010001012B
    55AA03070005010100010011
    55AA0307000802020004000000637C
    55AA03070008030200040000000A24
    55AA0307000805020004000003E807
    55AA0307000806020004000000001D
    55AA030700050E0400010021
    55AA030700051A010001012B

    back light off
    TX
    55 AA 00 06 00 05 1A 01 00 01 00 26

    RX
    55AA030700051A010001002A
    55AA03070005010100010011
    55AA0307000802020004000000637C
    55AA03070008030200040000000A24
    55AA0307000805020004000003E807
    55AA0307000806020004000000001D
    55AA030700050E0400010021
    55AA030700051A010001002A

    Here is the TX when adjusting the brightness
    dimmness 15 byte tx
    TX Brightness
    55AA00060008020200040000001429 1%
    55AA00060008020200040000001E33 2%
    55AA0006000802020004000000283D 3%
    55AA00060008020200040000003247 4%
    55AA0006000802020004000000455A 5%
    55AA0006000802020004000000596E 6%
    55AA0006000802020004000000778C higher I can't remember what this one was.

    There is a long press on the bottom "-" button on the physical light switch that will put the beken unit into access point mode so the Tuya app can tell it what wifi details to use. I will capture this at some point.

    What I need is to work out how to get openbeken to send these serial commands over the tx0 and rx0 pins.
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #3 21773925
    james13
    Level 2  
    Thanks, that is really helpful. Do you know if I can set up a slider that sends the appropriate serial message out?
  • #4 21773951
    DeDaMrAz
    Level 21  
    Certainly, have you found which dpID does what on your device?

    Once you do, there are multiple tutorials on how to map Tuya dpID's and manipulate them, there are also several examples of that in our docs section - https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md

    There is also simulator what runs under windows so you can test your settings, not particularly suited for Tuya dpID's but you can test autoexec files and settings, home page look etc. Link for latest simulator - https://github.com/openshwprojects/OpenBK7231...s/download/1.18.225/obkSimulator_1.18.225.zip

    Feel free to share a bit more and we can try and help you customize your device more.
  • ADVERTISEMENT
  • #5 21782655
    james13
    Level 2  
    So, the good news is I have the three controls working.

    The on and off toggle.
    The backlight toggle.
    The dimmer slider in the GUI.

    I added these commands to the startup commands.
    startDriver TuyaMCU
    setChannelType 2 dimmer
    setChannelLabel 2 Light 1
    setChannelType 1 toggle
    setChannelLabel 1 Light 1
    tuyaMcu_setDimmerRange 0 1000
    tuyaMcu_setBaudRate 9600
    // always report paired
    tuyaMcu_defWiFiState 4
    
    linkTuyaMCUOutputToChannel 2 val 2
    AddChangeHandler Channel1 == 1 uartSendHex 55AA0006000501010001010E
    AddChangeHandler Channel1 == 0 uartSendHex 55AA0006000501010001000D
    
    setChannelType 3 toggle
    setChannelLabel 3 Backlight 1
    AddChangeHandler Channel3 == 1 uartSendHex 55AA000600051A0100010127
    AddChangeHandler Channel3 == 0 uartSendHex 55AA000600051A0100010026


    I wired up the TX line from the device to the RX1, but when I manually adjusted the light it did not update the web GUI. Can this be done?
  • #6 21787169
    p.kaczmarek2
    Moderator Smart Home
    Why are you doing that?
    
    AddChangeHandler Channel1 == 1 uartSendHex 55AA0006000501010001010E
    AddChangeHandler Channel1 == 0 uartSendHex 55AA0006000501010001000D
    

    You are manually sending data via UART. You're sending SetDP command:
    Screenshot of a tool decoding Tuya data packets in hexadecimal format
    Why not do it directly, with our TuyaMCU driver?
    It will work in both directions then.
    Our command is: linkTuyaMCUOutputToChannel
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    https://www.elektroda.com/rtvforum/find.php?q=linkTuyaMCUOutputToChannel

    Here is one of my dimmer guides:
    https://www.elektroda.com/rtvforum/topic3929151.html
    You can see my autoexec.bat there and how I used linkTuyaMCUOutputToChannel to link TuyaMCU dpIDs to OBK channels.

    It's very easy to run TuyaMCU with OBK, it's the recommended solution. You can do it also manually with OBK scripts and uartSendHex , but why?

    My suggestion: remove all uartSendHex calls and use linkTuyaMCUOutputToChannel for all dpIDs.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21788054
    james13
    Level 2  
    Yep, it turns out this worked in the end

    startDriver TuyaMCU
    setChannelType 2 dimmer
    setChannelLabel 2 Light 1
    setChannelType 1 toggle
    setChannelLabel 1 Light 1
    tuyaMcu_setDimmerRange 0 1000
    tuyaMcu_setBaudRate 9600
    // always report paired
    tuyaMcu_defWiFiState 4
    
    linkTuyaMCUOutputToChannel 2 val 2
    
    linkTuyaMCUOutputToChannel 1 bool 1
    
    setChannelType 3 toggle
    setChannelLabel 3 Backlight 1
    linkTuyaMCUOutputToChannel 26 bool 3


    Thanks. It works bidirectionally also now.

Topic summary

The discussion focuses on the serial communication protocol of a Tuya dimmer switch incorporating a Beken BK7231N microcontroller. The device communicates via a 9600 baud serial interface with an unmarked chip, using variable-length hexadecimal command sequences. Commands start with a synchronization byte 0x55 followed by 0xAA, enabling control signals such as turning the light on or off and adjusting backlight settings. Example hex commands for light on and off states are provided, along with corresponding response packets that include status information. A tool named TuyaMCUAnalyzer is recommended for detailed analysis of these serial packets to better understand and decode the protocol.
Summary generated by the language model.
ADVERTISEMENT