logo elektroda
logo elektroda
X
logo elektroda

Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components

TurkeyMan 19110 134
ADVERTISEMENT
  • #31 20591577
    elektradi
    Level 6  
    Ok, I think I will just flash openBK and not try to rewire anything. Do you know how many dpIDs we are missing?
  • ADVERTISEMENT
  • #32 20598145
    calcu
    Level 3  
    Hi all, any news on this ?

    I'm pretty new to the templates / finding pins, and I can't make this energy meter to work.

    Installed Obk, but no info from the device.

    Created the autoexec with the info given, but still no luck.

    Well, not completely true, I can see voltage moving, but no power / current at all.
  • #33 20598227
    p.kaczmarek2
    Moderator Smart Home
    As I said, we just need to figure out the which are dpIDs of the remaining packets. If you have flashed this device and already runs TuyaMCU driver, go to Web App->Logs , and just observe what is being received. Which dpIDs are not yet configured and what may be their meaning.

    I also seem to see that in post 30 the config for Voltage+Current+Power was posted, is Current and power not working for you?
    Helpful post? Buy me a coffee.
  • #34 20598231
    calcu
    Level 3  
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components

    It doesn't.

    But i (this afternoon) i will try to read more logs and try to find what dpi are missing.

    
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 18 14 02 00 04 00 00 09 18 12 02 00 04 00 00 00 00 13 02 00 04 00 00 00 00 8D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 31 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 20, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 2328
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 18, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 0
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 19, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 0
    
  • #35 20598234
    p.kaczmarek2
    Moderator Smart Home
    But in post 30, we have determined that dpID 19 and 18 are current/power, and in the log you've shown it seems that TuyaMCU sends 0 values there?
    Are you sure you have connected the clamp correctly?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #36 20598239
    calcu
    Level 3  
    Yes, sure.
    but now the test will have to wait ... :-(

    I moved the device to another plug and...

    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components

    a cable disconnected and fried it....

    Incredible...

    It seems it will be a bad day ...


    Edit:

    It seems it's still working!, going to work, i will check it better later
  • #37 20598263
    p.kaczmarek2
    Moderator Smart Home
    Do you know that CT should be on a single wire, not the both of them?
    Helpful post? Buy me a coffee.
  • #38 20598381
    calcu
    Level 3  
    Yes, yes.

    I checked again, everything, and now... It works!, Nothing changed, only a "hard reset" of my house electrical system xD
  • #39 20599069
    p.kaczmarek2
    Moderator Smart Home
    I am happy to hear you got your issue resolved. Judging from TuyaMCU captures, I wasn't sure whether we already have everything configured, because I also saw a "data request" packet there, which was mentioned to be required by this smart power meter topic:
    https://www.elektroda.com/rtvforum/topic3959907.html
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #40 20599250
    calcu
    Level 3  
    Interesting.
    I just installed everything, and now I can "play" with it, if I found anything new I will post it here.

    Thanks a lot!
  • #41 20619243
    elektradi
    Level 6  

    Has every piece of info been decoded already? I was wondering if we do a Tuya local, can we push that further to flash with our own firmware?
  • #42 20627063
    elektradi
    Level 6  
    Can someone confirm these DP IDs?
    
            "add_ele": 17
            "cur_current": 18
            "cur_power": 19
            "cur_voltage": 20
            "test_bit": 21
            "voltage_coe": 22
            "electric_coe": 23
            "power_coe": 24
            "electricity_coe": 25
            "fault": 26
            "power_reactive": 51
            "power_effective": 52
  • #43 20627094
    p.kaczmarek2
    Moderator Smart Home

    I've got that device:
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components
    Here is what I got with bulb test on Tuya firmware:
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components
    As you can see, I got only the following dpIDs reported by Tuya firmware:
    
            "cur_current": 18
            "cur_power": 19
            "cur_voltage": 20
    

    I am not aware of the other ones, how did you get them to show up?
    Helpful post? Buy me a coffee.
  • #45 20627108
    p.kaczmarek2
    Moderator Smart Home

    Well, it seems you are correct. I have checked again the first post and it contains one more dpID:
    
    55 AA	00	06		00 08	3402000400003E80	05	
    HEADER	VER=00	Unk		LEN	fnId=52 Val V=16000	CHK	
    55 AA	00	00		00 00		FF	
    HEADER	VER=00	Heartbeat		LEN		CHK	
    55 AA	00	06		00 08	3402000400005DC0	64	
    HEADER	VER=00	Unk		LEN	fnId=52 Val V=24000	CHK	
    55 AA	00	06		00 08	340200040000C350	5A	
    HEADER	VER=00	Unk		LEN	fnId=52 Val V=50000	CHK	
    55 AA	00	00		00 00		FF	
    HEADER	VER=00	Heartbeat		LEN		CHK	
    55 AA	00	06		00 08	3402000400005DC0	64	
    HEADER	VER=00	Unk		LEN	fnId=52 Val V=24000	CHK	
    

    I can see that I even commented on it in the past, it's just that I forgot about it, sorry! Still, I don't know what that 52 may be. According to your info, it's "power_effective" value. But the first log also doesn't contain anything more, it seems.

    Do you receive any more dpIDs on your device?
    Helpful post? Buy me a coffee.
  • #46 20627115
    elektradi
    Level 6  

    My device is still on Tuya's original firmware. Since OpenBK never overwrites the DP ID firmware, it's easier if we start hacking from there. Can you configure your OpenBK based on the info I provided and see if it all makes sense?

    Added after 2 [minutes]:

    I just searched for "power_effective tuya". Can you check this out? https://github.com/make-all/tuya-local/issues/604
  • #48 20638517
    p.kaczmarek2
    Moderator Smart Home
    There is no point in configuring other dpIDs if they are not sent at all. Adding the mappings to channels in OBK won't make them magically being sent now. As I said, on my device, with Tuya firmware, I got this:
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components
    I don't know, maybe I have different version for device, but it seems it lacks some of dpIDs mentioned on these topics:
    Code: JSON
    Log in, to see the code


    I think you should try doing UART capture on your device (make sure it's isolated from mains, maybe use wireless UART dongle or smth?), or just do a 2MB firmware backup and try with OBK, in worst case you can restore the backup.

    Or maybe, check with Tuya app, does your Tuya app show something more than voltage, current and power?
    Helpful post? Buy me a coffee.
  • #49 20638558
    elektradi
    Level 6  
    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components

    1. I'm connected tuya original firmware to my HA. I see extra things in green boxes, and those seem to be missing.
    2. On my Smart App, I see Main Module v2.1.6, MCU Module is 1.0.0
  • #50 20638571
    p.kaczmarek2
    Moderator Smart Home

    Hmmm, I didn't check that when I was testing with the Tuya app, and now the device is flashed with OBK and installed in a family member's house. I don't know which Main Module/MCU module version I had.

    But still, it looks like you don't have those even on Tuya?
    Code: JSON
    Log in, to see the code


    But I will say this:
    - Energy is calculated on the Tuya side, so I don't think it's dpID. They only have: add_ele which seems to reset periodically, it's like a delta
    - The Configuration params are things sent from the WiFi module to the MCU, they are not read results

    So currently it looks like you have almost everything the same as me...
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #51 20670011
    madmak76
    Level 10  

    Hello everyone,
    I bought a device very similar to yours from MatseePlus with only two terminals (terminals like yours 80A) but in the Zigbee version.
    I managed to get a DP map from them with a description of the functions.
    Unfortunately, the device in Zigbee2mqtt is currently unsupported but it is correctly detected.
    As a gateway, I use a Sonoff Zigbee plus USB dongle that detects the Tuya TS0601 device and the manufacturer is _TZE204_81yrt3lo.

    Can any of you, based on these DP, make some HA or Zigbee2mqtt config to make it work properly?

    Thank you in advance for your help.

    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components

    Exploring the Inner Workings of PJ-MGW1103 CT-Clamp Energy Meter: Tuya, BL0942, CB2S Components
  • #52 20694274
    jzhvymetal
    Level 3  
    >>20638571
    I understand that energy is calculated on the Tuya side. Is there any way to run a script on the OpenBK to calculate the energy consumption from polling the power value?
  • #53 20694368
    p.kaczmarek2
    Moderator Smart Home
    Well, I can easily write even a simple driver for you to do that calculation, but do you think that the update rate from TuyaMCU is good enough for those measurements to be precise enough for everyday use?
    Helpful post? Buy me a coffee.
  • #54 20694439
    jzhvymetal
    Level 3  

    I'm still trying to understand how often the data is updated from TuyaMCU. I think it is reported based on change. Also, after every TuyaMCU heartbeat, it could use the previous read value for wattage. It would be nice to have the driver take the time delta from the values and sum the total wattage and time for the calculation. Ideally, it could calculate with a 0.001 multiplier for Energy Today (kWh) and Energy Yesterday (kWh).
  • #55 20760352
    andreiciocanvlad
    Level 1  

    Hello, did anyone figure out how to configure this module? I have a similar one with 2 CT Clamps.
  • #56 20846864
    thalesmaia
    Level 6  

    I'm reading some docs to understand as well, but AFAIK.
    1) Flash using Tuya cutter or UART.
    2) Configure Wifi after access using AP Mode
    3) Create an autoexec.bat inside FileSystem tab.
    4) Paste this config:

    
    startDriver TuyaMCU
    tuyaMcu_setBaudRate 115200
    tuyaMcu_defWiFiState 4
    setChannelType 2 Voltage_div10
    setChannelType 3 Power_div10
    // linkTuyaMCUOutputToChannel dpId variableType tgChannel
    //ch 2(dpid 20) voltage
    linkTuyaMCUOutputToChannel  20 1 2
    //ch 3(dpid 19) power watts
    linkTuyaMCUOutputToChannel 19 1 3
    


    5) I'm stuck, since I can't recover my device after creating autoexec.bat. I probably did something wrong.

    EDIT: I have the feeling that this board has some kind of hardware watchdog. I can't use safemode longer than 30s.
  • #57 20846868
    p.kaczmarek2
    Moderator Smart Home
    There is nothing wrong in that autoexec.bat and I done such things many times on many devices.

    Try to boot into safe mode - do 5 quick power off/on cycles.
    Helpful post? Buy me a coffee.
  • #58 20846878
    thalesmaia
    Level 6  

    Thanks, just made an update in my last post. The device power cycles even in safe mode. I can't keep it up for much time.
  • #59 20846923
    p.kaczmarek2
    Moderator Smart Home
    I had very similiar model, as said in this post:
    https://www.elektroda.com/rtvforum/topic3946128-30.html#20627094
    and there was no such problem....

    The autoexec.bat is not run in safe mode. Are you really sure that the problem started after setting autoexec.bat?
    Helpful post? Buy me a coffee.
  • #60 20846934
    thalesmaia
    Level 6  

    Yes. Unfortunately, that was the only thing I've done.
    I faced a similar problem before.
    I tried to use ESPHome first and faced the same problem. Using kickstart, it worked. After updating my custom firmware, it just keeps rebooting.
    Is there a way to factory reset or do I need to burn it again? If so, do I need to desolder it?

Topic summary

The discussion revolves around the PJ-MGW1103 CT-Clamp Energy Meter, focusing on its teardown, functionality, and integration with Tuya and BL0942 components. Users share insights on the device's internal workings, including the communication protocols and data points (dpIDs) for voltage, current, and power measurements. Various configurations for the autoexec.bat file are provided to optimize the device's performance, including baud rate settings and channel mappings. Users also address issues related to data accuracy, calibration, and the need for firmware updates. The conversation highlights the importance of understanding dpIDs for effective monitoring and control of energy consumption.
Summary generated by the language model.
ADVERTISEMENT