logo elektroda
logo elektroda
X
logo elektroda

Reverse engineering of the unusual protocol of the Tuya FS-05R dimmer based on UART

p.kaczmarek2 
Light bulb in a socket on a wooden table
Today it`s fun again reverse engineering . The Tuya FS-05R dimmer was sent to me by a reader asking me to decipher the UART protocol of communication between the WiFi module and the microcontroller responsible for dimming. Contrary to appearances, this is not a typical dimmer based on TuyaMCU , just like EDM-01AA-EU , the protocol in this product is non-standard. Here I will describe how I intercepted and decrypted this communication. The topic will also include a presentation of subsequent scripting of the operation of this dimmer OBK so that it can work with Home Assistant.


FS-05R dimmer
This dimmer first appeared in the topic on our English-language website . He managed to read the dunk with our flasher , which allowed us to preview Tuya`s JSON:
Code: JSON
Log in, to see the code

This JSON usually contains either the baud setting for TuyaMCU or the GPIO roles. Here it is unusual, because we have this and that here. We have baud rate:
Code: JSON
Log in, to see the code

and we also have GPIO roles:
Code: JSON
Log in, to see the code

This is unusual, because in the case of TuyaMCU the MCU itself controls everything, the buttons and LEDs too, so usually the WiFi module does not use the GPIO at all.
Short tests on that topic showed that this is not a TuyaMCU product and the baud rate refers to something else.
The work got stuck, so the reader sent me the equipment so I could examine it myself:
Side of the Tuya FS-05R dimmer packaging with feature markings. MiNi Smart Switch box on a wooden table
Mini dimmer module FS-05R with packaging and instructions on a wooden table.
Instruction:
MNINI FS-05R dimming switch module manual Instruction manual for the Tuya FS-05R dimmer Tuya app operation instructions shown on an unfolded leaflet, depicting various device control screens. User manual for smart modules with Bluetooth and Zigbee functions.
Thank you for sending me the equipment! Time for analysis.

Interior of the FS-05R
The first thing that catches your eye after looking inside is: invalid CB2S description layer : :
Close-up of a blue PCB with a green screw terminal block and visible silkscreen showing pins.
Location of 3.3V (VDD) and GND is incorrect .
I`ve checked it many times, and it`s not the first time I`ve come across a poorly described CB2S, and I know that the correct schedule is available on the Tuya website:
Pin layout diagram with dimensions for an electronic module.
Plus - here`s the interior:
Interior of the Tuya FS-05R dimmer showing electronic components on the PCB.
Here we have a non-isolated step down converter which, interestingly, directly powers the microcontroller itself. There is no additional LDO AMS1117-3.3V here, as is usually the case.
Additionally, you can see that the CB2S WiFi module is connected to the element in the SOIC8 housing via RX and TX lines.
Now the view from above:
Close-up of Slkor BTA16-800B triac and green terminal block PCB with electronic components including capacitors and a green screw terminal block. Close-up of a circuit with a BTA16-800B triac and capacitors on a PCB
Dimming is performed on the BTA16-800B triac, which is controlled by 3022 F462H.


Interception of FS-05R communication
I decided on a method based on the Sigrok analyzer, similarly to the one above this topic .
Normally there would be a problem here, because you cannot connect the analyzer to a system powered from the mains, you would have to use special opto-isolation systems/modules, but I powered the whole thing from 3.3V and the arrangement started anyway:
Interior of an electronic circuit with voltage labels
Here is the traffic on TX/RX:
UART signal measurements in PulseView
While the MCU is idle, it sends something to us...
Screenshot of protocol analyzer with UART signals
View of captured UART protocol on a logic analyzer
Screenshot of UART signal analysis using Saleae Logic.
It sends three bytes with the AA header, which I associate with the BL0942 protocol. This is not TuyaMCU.
But what happens when we press the button?
Screenshot from PulseView showing UART data.
When you press the button, the WiFi module sends something to the MCU:
Screenshot of UART signal analysis in a logic analyzer.
Wait, heading 55 AA? This looks like TuyaMCU though! This protocol must be some simplified version of it.
Screenshot from a logic analyzer showing UART data.
Let`s see what mine says TuyaMCU analyzer
TuyaMCU Explorer application interface displaying raw packet data in hex format.
This is a TuyaMCU compatible package , even the checksum is calculated correctly.
I collected some of these packages and noticed that second and third bytes payload changes when I press the button - maybe the brightness levels?


Changing the FS-05R load
CB2S communicates with the MCU via the UART port used for programming, so you need to desolder CB2S. You need flux and braid.
FS-05R dimmer circuit board next to solder wick
I program with my flasher:
https://github.com/openshwprojects/BK7231GUIFlashTool
Desoldered, cables need to be connected ignoring the descriptive layer, looking at the catalog note : :
Electronic module with connected wires on a wooden surface.
Whole system:
Breadboard with connected electronic equipment on a desk
After uploading, we solder the module into place.


Configuration for OBK FS-05R
My first experiment was to create a script that sends hard-captured UART packets:

startDriver TuyaMCU
tuyaMcu_setBaudRate 115200

again:
delay_s 1
uartSendHex 55AA0030000300000638
delay_s 1
uartSendHex 55AA0030000300000032
goto again

Everything works, the dimmer responds:




Then I added a wrapper for sending TuyaMCU commands so as not to have to provide the checksum and header in the script, now the last byte is counted automatically:

startDriver TuyaMCU
tuyaMcu_setBaudRate 115200

again:
delay_s 1
tuyaMcu_sendCmd 0x30 000000
delay_s 1
tuyaMcu_sendCmd 0x30 0001FF
goto again

The syntax of tuyaMcu_sendCmd is very simple. The first argument is the TuyaMCU command number and the second is its payload. The checksum is calculated automatically.
Effect:



Here you can also see that the smooth transition effect is handled by the MCU itself, not the WiFi module.
Now it`s time to turn this proof of concept demo into something functional .
OBK allows you to define channel types and create simple scripts, you can read about it in the documentation:
https://github.com/openshwprojects/OpenBK7231T_App/tree/main/docs
Based on this, I prepared the following script:

// this is not really tuyaMCU but we will treat it as such
startDriver TuyaMCU
// set baud rate
tuyaMcu_setBaudRate 115200

// create a toggle and a dimmer
setChannelType 1 toggle
setChannelType 2 dimmer256


// invoke refresh on change
addEventHandler OnChannelChange 1 startScript autoexec.bat refresh
addEventHandler OnChannelChange 2 startScript autoexec.bat refresh


refresh:
// channel 5 is temporary variable, from 0 to 255*3, multiplied also by toggle value
setChannel 5 $CH2*3*$CH1
// split into two bytes
setChannel 3 $CH5/256
setChannel 4 $CH5%256
// send the two bytes
tuyaMcu_sendCmd 0x30 00$CH3$$CH4$

This script creates a dimmer controller on foot that supports both turning it on and off, as well as changing the brightness level. The brightness level is remembered after turning it off and on. It`s all about the scripts. The brightness level is manually split into two bytes and sent in the packet already discussed.
This is what it looks like in LittleFS:
Screenshot of OBK script editor with autoexec.bat
And on the panel:
OpenBK7231N dimmer control panel.
Thanks to the new Home Assistant Discovery system, a dimmer scripted in this way will be seen automatically by HA, without writing Yaml!


We are adding the missing FS-05R buttons
I almost forgot about the buttons that are worth adding here too. I mean a separate GPIO responsible for turning on and increasing and decreasing the brightness:
Code: JSON
Log in, to see the code

Just set their roles Btn_ScriptOnly . Then we add button events to autoexec.bat, according to the pattern:

addEventHandler [Event] [PinIndex] [Command]

More examples: https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
According to my script, the channel responsible for the on-off state is 1.
So, for the on-off button, P7, I propose:

addEventHandler OnClick 7 toggleChannel 1

Alternatively, you can set P7 to the Btn role and give it channel 1, and you can also set the flags to respond immediately to button presses.
For the + and - buttons, I suggest:

addEventHandler OnHold 26 addChannel 2 10 0 255

Of course, we change the added value for this second button from 10 to -10, so that it subtracts instead of adding.
Let me remind you of the addChannel syntax:

addChannel [Channel] [ValueToAd] [MinClamp] [MaxClamp]

Although in fact it could be combined into one button and set its events separately:
- OnClick toggles OnOff
- OnHold e.g. increases the brightness level
- and e.g. OnDblClick can set full brightness automatically

Summary
Typically, Tuya dimmers are based on the TuyaMCU protocol. In this case it was a bit different, the protocol here is simplified. The WiFi module sends a single packet, somewhat compatible with TuyaMCU, and the MCU responds with something, but I have not analyzed the format of the response data (or maybe prompt?). There is certainly no exchange here heartbeats be dpID as in normal TuyaMCU, there is only this one packet with checksum.
Operating this dimmer in OpenBeken turned out to be quite simple, because the existing OBK scripting language fully coped with the new task. Scriptable channel types (here on/off state and dimmer) allow you to easily handle the logic of such a dimmer in the script itself, even with button operation.
PS: it is also worth reading a related topic where the dimmer protocol was also based on UART, but was not based on TuyaMCU: WXDM2 dual dimmer - reverse engineering - weird UART protocol

About Author
p.kaczmarek2
p.kaczmarek2 wrote 11842 posts with rating 9938 , helped 566 times. Been with us since 2014 year.

Comments

tretyakalex 16 Mar 2024 17:06

Hello. Thank you for your job. I have the same dimmer. I use your script in autoexec.bat. But i haven't dimmer effect. When i move slider up the bulb only light up with full brightness. Toogle works... [Read more]

p.kaczmarek2 16 Mar 2024 17:11

Please try updating OBK to latest version. You may have an older one, depending on the way you've flashed your dimmer. [Read more]

tretyakalex 16 Mar 2024 17:16

I've updated to 1.17.507 ver. by OTA [Read more]

p.kaczmarek2 16 Mar 2024 17:37

If it's still not working, then try executing the test autoexec.bat: startDriver TuyaMCU tuyaMcu_setBaudRate 115200 again: delay_s 1 tuyaMcu_sendCmd 0x30 000000 delay_s 1 tuyaMcu_sendCmd... [Read more]

tretyakalex 16 Mar 2024 18:30

Just switch on and switch off. May be try dimmer1000? [Read more]

p.kaczmarek2 16 Mar 2024 19:02

What if you change the hex bytes here: startDriver TuyaMCU tuyaMcu_setBaudRate 115200 again: delay_s 1 tuyaMcu_sendCmd 0x30 000000 delay_s 1 tuyaMcu_sendCmd 0x30 0001FF goto again ... [Read more]

tretyakalex 16 Mar 2024 20:50

Tomorrow I'll try other type of bulb. This bulb has small interval of dimming. [Read more]

p.kaczmarek2 16 Mar 2024 21:06

Sure, please try, but still, didn't you say that the same bulb worked with Tuya? [Read more]

tretyakalex 17 Mar 2024 20:21

Yes. It works with Tuya, but in very small range. Today i've changed the bulb and... it works perfectly with your script. It is very strange, but it is. Thank your for reverse engeneering!!! I think... [Read more]

p.kaczmarek2 22 Mar 2024 08:59

Of course not all of the bulbs are dimmable nowadays. I would even say that it's safe to assume that bulb is not dimmable unless otherwise specified. @ElektrodaBot which bulbs are dimmable? How to... [Read more]

ElektrodaBot 22 Mar 2024 09:00

Hello there! It's great that you're asking about dimmable bulbs. The ability to dim lights can really change the ambiance of a space, not to mention it can be energy-saving too. Let's delve into how you... [Read more]

Nanganator 22 Mar 2024 21:44

Great work on this reverse engineering! I was able to flash 2X FS-05R today and, with your script, added to home assistant. I am using these dimmers to control some long 24V LED strips driven by KGP... [Read more]

p.kaczmarek2 22 Mar 2024 21:47

I don't know any way to slow down the transition speed. Well, unless you can write a little C code snippet to run on OBK, but that may look jerky, because you will get two levels of smoothing that way. As... [Read more]

gunthervc 05 Aug 2024 12:44

Thanks, works perfectly. i Got 5 of these. Can this also work with ESPhome? [Read more]

jahara 31 Oct 2024 03:41

I got this working on ESPhome. Check out this post on the Home Assistant forum: https://community.home-assistant.io/t/how-to-wire-switch-to-dimmer-fs-05r/763236/15?u=nschimme [Read more]

cbcelek 20 Jan 2025 22:57

Hi, I also got FS-05R dimmer module, except it had a Zigbee module. I figured I wanted WiFi so I replaced the module with and ESP equivalent of CB2S. This is exactly the same 'motherboard'. However I... [Read more]

@GUTEK@ 16 Mar 2025 20:12

Hello, I am currently playing with this dimmer and have a problem. It is also the FS-05R version, although there is no model designation on the housing and there are minimal differences in the position... [Read more]

p.kaczmarek2 16 Mar 2025 20:20

And when you send in an "artificial" command to change the brightness it always arrives? [Read more]

@GUTEK@ 16 Mar 2025 20:30

I understand that I have to go into "Execute Custom Command" and send, for example, something like "tuyaMcu_sendCmd 0x30 0001FF" ? It doesn't, it also only responds after the first time. [Read more]