Hello folks! First of all thanks for the great piece of work you did!
Inspired by your upgrade of this relay, I've started my teardown. First of all, I faced quite a different PCB with the Tuya CBU module instead of the one mentioned in this topic. The next thing that prevented me from proceeding was being unable to flash it in place, which seemed to happen because TuyaMCU interfered with UART. The "easiest" way was to desolder the wifi module and flash it. Thanks God and that LCD is made of "crystals" so my overheated areas perfectly cured themselves slowly 😅
The most recent problem was that I've been struggling to make things work properly with the latest autoexec.bat posted by AngelOfDeath which also is included in the OpenBeken repository. If I use this one, the main relay toggle goes off constantly. Just in a second after switching it on it goes off on the WebUI and also the same behavior with the physical button. Only the "original" autoexec.bat was working and some of the next revisions. Nothing interesting was mentioned in the logs so I had to perform manual debugging by commenting out the most needed features line by line.
And as for now my learning is that placing "combined energy dpid" to the channel before the main relay one fixes the issue. What I mean by that is that combination DpID 16 -> channel 1, DpID 6 -> channel 2,3,4 wont work, while DpID 6 -> channel 1,2,3 DpID 16 -> channel 5 works fine.
Here is the code that works fine on my device:
Can anyone explain to me what's going on with that channels case?
P.S. Right now, when I somehow have operational autoexec, I tried to upload alternative web UI but failed 🥲 I guess that the alternative web page is too big to be uploaded (POST request just fails) So I plan to rewrite the web page from scratch with some frontend best practices but keeping it close to the original. Will share with you if come up with anything good.
Inspired by your upgrade of this relay, I've started my teardown. First of all, I faced quite a different PCB with the Tuya CBU module instead of the one mentioned in this topic. The next thing that prevented me from proceeding was being unable to flash it in place, which seemed to happen because TuyaMCU interfered with UART. The "easiest" way was to desolder the wifi module and flash it. Thanks God and that LCD is made of "crystals" so my overheated areas perfectly cured themselves slowly 😅
Spoiler:
Here is the PCB itself. Even the pinout for GND and 3.3V were shifted compared to one from the topic.

The most recent problem was that I've been struggling to make things work properly with the latest autoexec.bat posted by AngelOfDeath which also is included in the OpenBeken repository. If I use this one, the main relay toggle goes off constantly. Just in a second after switching it on it goes off on the WebUI and also the same behavior with the physical button. Only the "original" autoexec.bat was working and some of the next revisions. Nothing interesting was mentioned in the logs so I had to perform manual debugging by commenting out the most needed features line by line.
And as for now my learning is that placing "combined energy dpid" to the channel before the main relay one fixes the issue. What I mean by that is that combination DpID 16 -> channel 1, DpID 6 -> channel 2,3,4 wont work, while DpID 6 -> channel 1,2,3 DpID 16 -> channel 5 works fine.
Here is the code that works fine on my device:
clearIO
SetFlag 46 1
// start TuyaMCU driver
startDriver TuyaMCU
tuyaMcu_setBaudRate 9600
waitFor MQTTState 1
// tuyaMcu_defWiFiState 4
// Breaker Id - Dpid 19 "breaker_id" -> channel 0
linkTuyaMCUOutputToChannel 19 str 0
setChannelType 0 ReadOnly
setChannelLabel 0 "Breaker ID"
// Measurements - Dpid 6 "phase_a" - channel RAW_TAC2121C_VCP -> channel(s) 1,2,3
// TAC2121C VoltageCurrentPower Packet
// This will automatically set voltage, power and current
linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP
setChannelType 1 Voltage_div10
setChannelLabel 1 "Voltage"
setChannelType 2 Power
setChannelLabel 2 "Power"
setChannelType 3 Current_div1000
setChannelLabel 3 "Current"
// Main Relay - Dpid 16 "switch" -> сhannel 4
linkTuyaMCUOutputToChannel 16 bool 4
setChannelType 4 toggle
setChannelLabel 4 "Relay"
// Prepayment on-off - Dpid 11 "switch_prepayment" -> channel 5
linkTuyaMCUOutputToChannel 11 bool 5
setChannelType 5 toggle
setChannelLabel 5 "Prepayment"
// Clear Energy Counters - Dpid 12 "clear_energy" -> channel 6
linkTuyaMCUOutputToChannel 12 bool 6
setChannelType 6 toggle
setChannelLabel 6 "Clear Energy Counters"
// Total energy - Dpid 1 "total_forward_energy" -> channel 7
linkTuyaMCUOutputToChannel 1 val 7
setChannelType 7 EnergyTotal_kWh_div100
setChannelLabel 7 "Total Energy"
// Leakage current - Dpid 15 "leakage_current" -> channel 8
linkTuyaMCUOutputToChannel 15 val 8
setChannelType 8 Current_div1000
setChannelLabel 8 "Leakage Current"
// Fault - Dpid 9 "fault" -> channel 9
linkTuyaMCUOutputToChannel 9 raw 9
setChannelType 9 ReadOnly
setChannelLabel 9 "Fault"
// Settings 2 - Dpid 18 "alarm_set_2" -> channel 10
linkTuyaMCUOutputToChannel 18 raw 10
setChannelType 10 ReadOnly
setChannelLabel 10 "UV, OV, Max. Current Protections Settings"
// Prepaid energy - Dpid 13 "balance_energy" -> channel 11
linkTuyaMCUOutputToChannel 13 val 11
setChannelType 11 EnergyTotal_kWh_div100
setChannelLabel 11 "Total Prepaid Energy"
// The above are read only channels. Except Settings 2 (mapped on channel 10), but since we cannot set it due to wrong parse of TuyaMCU driver - for now read only
// Charge Prepayment - Dpid 14 "charge_energy" - channel 12
linkTuyaMCUOutputToChannel 14 val 12
setChannelType 12 TextField
setChannelLabel 12 "Purchased Energy [kWh*100], i.e. 1kWh = 100"
// Settings 1 - Dpid 17 "alarm_set_1" - channel 13
linkTuyaMCUOutputToChannel 17 val 13
setChannelType 13 TextField
setChannelLabel 13 "Leakage Current Protection Settings"
// Protection Reaction Time - Dpid 104 "over_vol_protect_time" (applied for all protections, regardless the name of DpID) -> channel 14
linkTuyaMCUOutputToChannel 104 val 14
setChannelType 14 TextField
setChannelLabel 14 "Protection Reaction Time [s]"
// Protection Recovery Time - Dpid 105 "over_vol_recovery_time" (applied for all protections, regardless the name of DpID) -> channel 15
linkTuyaMCUOutputToChannel 105 val 15
setChannelType 15 TextField
setChannelLabel 15 "Protection Recovery Time [s]"
tuyaMcu_sendQueryState
Can anyone explain to me what's going on with that channels case?
P.S. Right now, when I somehow have operational autoexec, I tried to upload alternative web UI but failed 🥲 I guess that the alternative web page is too big to be uploaded (POST request just fails) So I plan to rewrite the web page from scratch with some frontend best practices but keeping it close to the original. Will share with you if come up with anything good.