logo elektroda
logo elektroda
X
logo elektroda

Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

tomanyusers 6909 60
ADVERTISEMENT
  • #1 20300753
    tomanyusers
    Level 3  
    Teardown of this DIN-rail energy meter from AliExpress. https://www.aliexpress.com/i/1005004628460684.html

    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C





    I want to use the device in Home Assistant without using Tuya.

    From what I see I have a few options:
    1. Reflash the BK7231N with OpenBK7231N
    2. Replace the BK7231N with an ESP-12F flashed with Tasmota or ESP-Home (Will probably have to jump a few pins to get it to boot from what I have read)

    The issue I have is that I don't know what the energy meter chip used by this meter is and what driver I would need to use. Can anybody point me in the right direction?

    Has anybody used one of these meters before?
  • ADVERTISEMENT
  • #2 20301140
    p.kaczmarek2
    Moderator Smart Home
    Hello, I can get OpenBK working for you on this chip, but I would need a bit more of information. From the current photos, I can't see what's happening on the PCB.

    Can you provide more information, including the name of ICs on the boards, is there some kind of power measuring chip like BL0937 or BL0942 or CSE*, it there, maybe, a TuyaMCU that connects to RX1 and TX1 of CB3S?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20301240
    tomanyusers
    Level 3  
    Hi

    I had to desolder the LCD Board and this is what I found. TX and RX from the CB3S are routed thought to the LCD PCB.

    The Main Chip Is a V9911
    A FM24C64 - nonvolatile memory
    A SC02B - Best Guess The numbers are unclear


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C


  • #4 20301264
    p.kaczmarek2
    Moderator Smart Home
    Are you really sure that's a V9911? But... the photo certainly confirms. I haven't seen such chip yet.

    I am only aware about the V9261F chip. It was described here:
    https://www.creationfactory.co/2019/12/reverse-engineering-zmai-90-din-rail.html
    I already started working on V9261F driver for OBK. V9911 (or V9911F?), on other hand, doesn't seem to exist anywhere. I am also unable to find the datasheet.

    Where exactly is V9911 connected? Does it connect to RX1 and TX1 of CB3S?
    Helpful post? Buy me a coffee.
  • #5 20302175
    tomanyusers
    Level 3  
    It's definitely a V9911. I found the data sheet if that helps.

    Pin 15 and 16 (RX1 and TX1) of CB3S are connected directly to the V9911 on TXD4 and RXD4 respectively.
  • #6 20303769
    p.kaczmarek2
    Moderator Smart Home
    If that's using UART, then I can try to make you support for that if you just provide me a capture of sent data, in hex format.

    I can run OBK on Windows and easily developer drivers with 'fake' UART packets.

    Would you be able to provide Realterm hex capture (and determine baud rate) like the user in this topic?
    https://www.elektroda.com/rtvforum/topic3933836.html

    Second option: is there ANY driver for V9911 anywhere? Tasmota? From what I heard, there is only that:
    https://www.creationfactory.co/2019/12/reverse-engineering-zmai-90-din-rail.html
    but zmai-90 uses Vangotech V9821 chip so we would need to know if it is the same as V9911
    Helpful post? Buy me a coffee.
  • #7 20305709
    tomanyusers
    Level 3  
    Hi

    I have sniffed the data on the Tx and Rx. It's a new meter so most of the values are still all zero. Ill run the meter with a load connected for a bit and then give you some more results.

    The voltage: ~236.5V

    Rx PIN:
    
    (Normal Running)
    55 AA 03 07 00 14 06 00 00 08 09 1D 00 00 00 00 00 00 01 02 00 04 00 00 
    00 00 58 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 
    01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 
    AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 
    00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 
    00 00 26 55 AA 03 07 00 14 06 00 00 08 09 36 00 00 00 00 00 00 01 02 00 
    04 00 00 00 00 71 55 AA 03 00 00 01 01 04                               
                                               
    
    (Toggel Relay)
    55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 
    34 39 30 30 36 38 E8 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 
    34 39 30 30 36 38 E9 55 AA 03 00 00 01 01 04 
      
    
    



    Tx Pin
    
    (Normal Running)
    55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 55 AA 00 00 00 00 FF 55 AA 
    00 24 00 01 C2 E6 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 C3 E7 55 AA 00 
    00 00 00 FF 55 AA 00 24 00 01 C2 E6 55 AA 00 00 00 00 FF 55 AA 00 24 00 
    01 C3 E7 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BB DF 55 AA 00 00 00 00 
    FF 55 AA 00 24 00 01 BD E1 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 
    55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 55 AA 00 00 00 00 FF 55 AA 
    00 24 00 01 BD E1   
    
    (Toggel Relay)
    55 AA 00 00 00 00 FF 55 AA 00 06 00 05 10 01 00 01 00 1C 55 AA 00 24 00 
    01 B7 DB 55 AA 00 06 00 05 10 01 00 01 01 1D  
    


    Added after 1 [hours] 22 [minutes]:

    From looking at the data and some googleing this looks like the Tuya MCU protocol to me. As 55 AA 00 00 00 00 FF is the Tuya MCU heartbeat.

    What are your thoughts?
  • #8 20305850
    p.kaczmarek2
    Moderator Smart Home
    Hey, it has 55 AA header! That's a very good news, it's a Tuya MCU, like the previous one, and we already support most of it out of the box!

    Still, lets analyze the packets, because some devices have 'special' packets that we still need to parse.

    But don't worry, you will certainly get support for that device.

    Quote:

    Rx PIN:
    
    (Normal Running)
    55 AA 03 07 00 14 06 00 00 08 09 1D 00 00 00 00 00 00 01 02 00 04 00 00 
    00 00 58 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 
    01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 
    AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 
    00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 
    00 00 26 55 AA 03 07 00 14 06 00 00 08 09 36 00 00 00 00 00 00 01 02 00 
    04 00 00 00 00 71 55 AA 03 00 00 01 01 04                               
    


    This is the data send from TuyaMCU to WiFi module. It contains energy stats, voltage, etc.
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    fnID 6 looks like a compound data packet
    55 AA 03 07 00 14 06 00 00 08 09 1D 00 00 00 00 00 00 01 02 00 04 00 00
    00 00 58
    the content: 091D000000000000
    091D looks like a big endian 2333 to me, so a voltage times 10? 233.3V?
    the remaining bytes in this packet are most likely current, power etc, but they are all 0 and I can't determine which value is where, I need a sample with a 60W load

    Quote:

    Rx PIN:
    
    (Toggel Relay)
    55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 
    34 39 30 30 36 38 E8 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 
    34 39 30 30 36 38 E9 55 AA 03 00 00 01 01 04 
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Huh? A a string?
    No idea what it might be currently.
    But there is also a fnID=16 with Val 0 or 1... so, a relay.
    it looks like a relay is connected to MCU and MCU reports to WiFi module the state of relay..

    Quote:

    Tx Pin
    
    (Normal Running)
    55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 55 AA 00 00 00 00 FF 55 AA 
    00 24 00 01 C2 E6 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 C3 E7 55 AA 00 
    00 00 00 FF 55 AA 00 24 00 01 C2 E6 55 AA 00 00 00 00 FF 55 AA 00 24 00 
    01 C3 E7 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BB DF 55 AA 00 00 00 00 
    FF 55 AA 00 24 00 01 BD E1 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 
    55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BE E2 55 AA 00 00 00 00 FF 55 AA 
    00 24 00 01 BD E1   
    


    Nothing interesting here:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    Quote:

    Tx Pin
    
    (Toggel Relay)
    55 AA 00 00 00 00 FF 55 AA 00 06 00 05 10 01 00 01 00 1C 55 AA 00 24 00 
    01 B7 DB 55 AA 00 06 00 05 10 01 00 01 01 1D  
    

    Not much interesting here...
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    I would need to know:
    1. that "toggling relay" was toggling relay on the case? Not by Tuya App?
    2. Can you provide packet sample for toggling relay from Tuya App? But... maybe it's not needed, most likely just send fnID....
    3. Would you be able to provide a packet sample with 60W bulb as a load and with, for example, 12W load so I can figure out where is current stored in that compound packet?

    I just need that information, or at least info from 3 - 60W bulb load and, let's say, 12W load capture... and it will be very EASY to support that one.

    We're lucky. I was worried it was using some kind of more exotic protocol.
    Helpful post? Buy me a coffee.
  • #9 20305911
    tomanyusers
    Level 3  
    Great News. I was also a little worried.
    I don't have a light ready at hand but I do have a fan. I hope that will work. If not let me know.

    Here is the Tx Pin when toggling the relay from the App.
    
    55 AA 00 24 00 01 C7 EB 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 06 00 05 10 01 00 01 00 1C 
    55 AA 00 00 00 00 FF 
    55 AA 00 06 00 05 10 01 00 01 01 1D 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 06 00 05 10 01 00 01 00 1C 
    55 AA 00 06 00 05 10 01 00 01 01 1D 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC
    


    Here is the Rx Pin when toggling the relay from the App.
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 34 39 30 30 36 38 E8 55 AA 03 00 00 01 01 04 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 4A 00 00 84 00 00 1D 01 02 00 04 00 00 00 03 29 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Here is running with a fan on max:
    Voltage~ 234.8
    Current~0.154
    Watage~36.13
    PF ~0.999
    Frequency 50.04
    
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 16 00 00 99 00 00 23 01 02 00 04 00 00 00 03 10 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    



    Here is running with a fan on min:
    Voltage~ 235.8
    Current~0.131
    Watage~28.67
    PF ~0.93
    Frequency 50.04
    
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 33 00 00 83 00 00 1C 01 02 00 04 00 00 00 03 10 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 39 00 00 84 00 00 1C 01 02 00 04 00 00 00 03 17 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    



    Here is toggling the relay from the meter with the push button
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 42 00 00 84 00 00 1C 01 02 00 04 00 00 00 04 21 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 34 39 30 30 36 38 E8 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Added after 25 [minutes]:

    I meant to add that the total kWh is 0.03 to 0.04 but reports as 0.02 in the app so I think there is the option to use the value stored in the MCU or in the BK7231N.
    I had the same with a HiKing DDS238 meter I have used in the past.
  • #10 20306116
    p.kaczmarek2
    Moderator Smart Home
    Thank you for providing futher data for analysis. Let's see what more is hiding there.

    It seems I've found a little issue. The packets marked in my previous post as "invalid date" starting with 0x10 date (16) are not a date, they are a relay value. fnID = 16, values 0 and 1. It seems the same packet type on two different devices have different meaning.


    tomanyusers wrote:

    Here is the Tx Pin when toggling the relay from the App.
    
    55 AA 00 24 00 01 C7 EB 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 06 00 05 10 01 00 01 00 1C 
    55 AA 00 00 00 00 FF 
    55 AA 00 06 00 05 10 01 00 01 01 1D 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC 
    55 AA 00 06 00 05 10 01 00 01 00 1C 
    55 AA 00 06 00 05 10 01 00 01 01 1D 
    55 AA 00 00 00 00 FF 
    55 AA 00 24 00 01 C8 EC
    


    WiFI module sends setting of fnID 16 boolean to 1 or 0:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    tomanyusers wrote:

    Here is the Rx Pin when toggling the relay from the App.
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 34 39 30 30 36 38 E8 55 AA 03 00 00 01 01 04 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 4A 00 00 84 00 00 1D 01 02 00 04 00 00 00 03 29 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    I wonder what that string might be... 22490068 2249 00 68 ??? Maybe a wild guess



    tomanyusers wrote:

    Here is running with a fan on max:
    Voltage~ 234.8
    Current~0.154
    Watage~36.13
    PF ~0.999
    Frequency 50.04
    
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 16 00 00 99 00 00 23 01 02 00 04 00 00 00 03 10 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    The compound packet data binary looks like this: 0916000099000023
    0916 ---> Big endian 2326 ---> 232.6V
    00
    0099 ---> Big endian 153 ---> 0.153A
    00
    0023 --> Big endian 35 ---> 35W
    huh, where is the Wattage data past the decimal point?


    tomanyusers wrote:

    Here is running with a fan on min:
    Voltage~ 235.8
    Current~0.131
    Watage~28.67
    PF ~0.93
    Frequency 50.04
    
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 33 00 00 83 00 00 1C 01 02 00 04 00 00 00 03 10 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 39 00 00 84 00 00 1C 01 02 00 04 00 00 00 03 17 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    So again, let's split this compound value and check what's inside:
    093900008400001C
    0939 ---> Big endian 2361 --> 236.1V
    00
    0084 --> Bigi Endian 132 ---> 0.132A
    00
    001C --> Big endian 28 ---> 28W?
    maybe that 00 bytes belong to next values as well... idk
    Where is the power factor?

    tomanyusers wrote:

    Here is toggling the relay from the meter with the push button
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 14 06 00 00 08 09 42 00 00 84 00 00 1C 01 02 00 04 00 00 00 04 21 55 AA 03 07 00 11 10 01 00 01 00 12 03 00 08 32 32 34 39 30 30 36 38 E8 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Ok, let's focus on that:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    So basically, we have:
    - fnID 16 - relay boolean
    - fnID 6 - binary data 094200008400001C -> as explained above, voltage (0x0942 is 2370), current, power
    - fnID 1 - value - V=4 ??? No idea what it could be and why it's 4
    - fnID 18 - string - 22490068 - no idea yet. It's worth noting that it's marked as an ASCII string, it's 3232343930303638 in hex
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    but that 2249 from string doesn't match 0x0942 - 2370 hmm

    22490068 that string seems to be present in all the tests, so maybe it's some kind of constant, and not the measurements data?

    It would be really useful if you had a autotransformer and try to show me the UART packets at 180V voltage or something.... but I am aware that most of people don't have them at hand.

    PS: it is worth nothing that DDS238 is using different packet format:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    so we still need to find where the power factor is, maybe I missed that, I will recheck those packets later.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #11 20306590
    tomanyusers
    Level 3  
    Going through the LCD menu I could find the same number 22490068. Maybe a serial number? I have emailed the manufacturer for the operating instructions, perhaps we can find something there.

    I think the wattage is being reported in kW. So it is 0.035 kW

    I think the 4 might be 0.04 kWh

    I'm not sure where the Power Factor is and there should be some other parameters like two-way active energy, reactive energy, and monthly and daily electricity consumption statistics available from this meter.

    But it looks like they are not sent through to the App at the moment.

    Added after 7 [minutes]:

    From the ads the following should be available but are not being sent to the App at the moment:
    Quote:

    ▷ Multi-function parameter measurement, providing voltage, current, active power, reactive power, apparent power, power factor, phase Angle, etc
    ▷ Providing a variety of statistical data and local storage functions. Provide monthly electricity consumption statistics for the last 12 months and daily electricity consumption statistics for the last 31 days.
  • #12 20307847
    p.kaczmarek2
    Moderator Smart Home
    Ah ok, so the "22490068" is solved, altough it would be interesting to see how it's displayed. A model number?

    Can you provide a sample with larger kWh value so we can check?

    Quote:

    But it looks like they are not sent through to the App at the moment.

    So what kind of values that are available in the App we are still missing?
    Helpful post? Buy me a coffee.
  • #13 20308997
    tomanyusers
    Level 3  
    Going back through this thread I can see that the 4 is 0.04kWh as it was 0.03kWh in some of our earlier tests.

    From the screenshots looks like we have all the info.

    Here is the sample at the startup

    RX Pin
    
    55 AA 03 00 00 01 00 03 55 AA 03 01 00 2A 7B 22 70 22 3A 22 6C 69 68 34 
    76 6A 65 6F 79 61 6F 34 6A 65 6B 75 22 2C 22 76 22 3A 22 32 2E 30 2E 30 
    22 2C 22 6D 22 3A 30 7D 41 55 AA 03 02 00 00 04 55 AA 03 03 00 00 05 55 
    AA 03 00 00 01 01 04 55 AA 03 03 00 00 05 55 AA 03 07 00 14 06 00 00 08 
    09 28 00 00 00 00 00 00 01 02 00 04 00 00 00 04 67 55 AA 03 07 00 0C 03 
    00 00 08 16 0B 16 0B 00 00 00 04 66 55 AA 03 07 00 0C 04 00 00 08 0B 1D 
    0B 1D 00 00 00 00 71 55 AA 03 07 00 06 0B 00 00 02 01 00 1D 55 AA 03 07 
    00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 24 
    00 00 26 55 AA 03 1C 00 00 1E 55 AA 03 1C 00 00 1E 55 AA 03 1C 00 00 1E 
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04    
    


    TX Pin
    
    55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 
    08 00 00 07 55 AA 00 03 00 01 04 07 55 AA 00 1C 00 08 01 16 0B 1D 07 30 
    26 02 C1 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 C0 E4 
    


    On The Rx Pin when querying historical data from the app
    
    55 AA 03 00 00 01 01 04 55 AA 03 07 00 0C 04 00 00 08 0B 1D 0B 1D 00 00 
    00 00 71 55 AA 03 24 00 00 26 55 AA 03 07 00 0C 03 00 00 08 16 0B 16 0B 
    00 00 00 04 66 55 AA 03 07 00 0C 04 00 00 08 0B 1D 0B 1D 00 00 00 00 71 
    55 AA 03 07 00 0C 03 00 00 08 16 0B 16 0B 00 00 00 04 66 55 AA 03 00 00 
    01 01 04 55 AA 03 24 00 00 26                                           
    


    On the Tx Pin when querying historical data from the app
    
    55 AA 00 06 00 08 04 00 00 04 0B 1D 0B 1D 65 55 AA 00 1C 00 08 01 16 0B 
    1D 07 34 35 02 D4 55 AA 00 06 00 08 04 00 00 04 0B 1D 0B 1D 65 55 AA 00 
    06 00 08 03 00 00 04 16 0B 16 0B 56 55 AA 00 06 00 08 03 00 00 04 16 0B 
    16 0B 56 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BF E3
    



    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    Added after 1 [hour] 37 [minutes]:

    I was able to track down the datasheet for this meter.
  • #14 20310817
    p.kaczmarek2
    Moderator Smart Home
    tomanyusers wrote:

    Here is the sample at the startup

    RX Pin
    
    55 AA 03 00 00 01 00 03 55 AA 03 01 00 2A 7B 22 70 22 3A 22 6C 69 68 34 
    76 6A 65 6F 79 61 6F 34 6A 65 6B 75 22 2C 22 76 22 3A 22 32 2E 30 2E 30 
    22 2C 22 6D 22 3A 30 7D 41 55 AA 03 02 00 00 04 55 AA 03 03 00 00 05 55 
    AA 03 00 00 01 01 04 55 AA 03 03 00 00 05 55 AA 03 07 00 14 06 00 00 08 
    09 28 00 00 00 00 00 00 01 02 00 04 00 00 00 04 67 55 AA 03 07 00 0C 03 
    00 00 08 16 0B 16 0B 00 00 00 04 66 55 AA 03 07 00 0C 04 00 00 08 0B 1D 
    0B 1D 00 00 00 00 71 55 AA 03 07 00 06 0B 00 00 02 01 00 1D 55 AA 03 07 
    00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 24 
    00 00 26 55 AA 03 1C 00 00 1E 55 AA 03 1C 00 00 1E 55 AA 03 1C 00 00 1E 
    55 AA 03 00 00 01 01 04 55 AA 03 24 00 00 26 55 AA 03 00 00 01 01 04    
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    - fnId=6 Raw V=09 28 00 00 00 00 00 00 - already described above, 0x0928 is 2344 which is 234.4V, other fields are current and power
    - fnId=1 Val V=4- idk
    - fnId=3 Raw 16 0B 16 0B 00 00 00 04 - TODO?
    What could be 160B hex? That 0004 might be... just a 4. Total power consumption. full 4 bytes integer, 32 bit one. 00 00 00 04.
    Wait...
    0x16 is is 22 and 0B is 11... a date? Year and month? Hmm we would need to check in the next month if it changes to 0x0C (12 month).
    - fnId=4 Raw 0B 1D 0B 1D 00 00 00 00 - TODO?
    What could be 0B1D hex?
    0x0B is 11.... and 0x1D is 29! A day! 29th day of month 11!
    So...
    Maybe fnId==3 is a 'last month' and fnId=4 is 'last day'?
    The format would be: 2 bytes day ID, 2 bytes month ID, 4 bytes Wh consumption

    - fnId=11 Raw 01 00
    - fnId=16 Bool V=1 - relay boolean
    - fnId=18 Str "22490068" - model number


    tomanyusers wrote:

    TX Pin
    
    55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 
    08 00 00 07 55 AA 00 03 00 01 04 07 55 AA 00 1C 00 08 01 16 0B 1D 07 30 
    26 02 C1 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 C0 E4 
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    In the following packet, the current date is being sent from WiFI module to TuyaMCU. We will also have to send that, but we have NTP.


    tomanyusers wrote:

    On The Rx Pin when querying historical data from the app
    
    55 AA 03 00 00 01 01 04 55 AA 03 07 00 0C 04 00 00 08 0B 1D 0B 1D 00 00 
    00 00 71 55 AA 03 24 00 00 26 55 AA 03 07 00 0C 03 00 00 08 16 0B 16 0B 
    00 00 00 04 66 55 AA 03 07 00 0C 04 00 00 08 0B 1D 0B 1D 00 00 00 00 71 
    55 AA 03 07 00 0C 03 00 00 08 16 0B 16 0B 00 00 00 04 66 55 AA 03 00 00 
    01 01 04 55 AA 03 24 00 00 26                                           
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    - fnId 4, Raw, 0B1D0B1D00000000
    - fnId 3, raw, 160B160B00000004


    tomanyusers wrote:

    On the Tx Pin when querying historical data from the app
    
    55 AA 00 06 00 08 04 00 00 04 0B 1D 0B 1D 65 55 AA 00 1C 00 08 01 16 0B 
    1D 07 34 35 02 D4 55 AA 00 06 00 08 04 00 00 04 0B 1D 0B 1D 65 55 AA 00 
    06 00 08 03 00 00 04 16 0B 16 0B 56 55 AA 00 06 00 08 03 00 00 04 16 0B 
    16 0B 56 55 AA 00 00 00 00 FF 55 AA 00 24 00 01 BF E3
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    It seems there is still more data we could use.
    Helpful post? Buy me a coffee.
  • #15 20313173
    tomanyusers
    Level 3  
    On Startup

    
    55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 08 00 00 07 55 AA 00 
    03 00 01 04 07 55 AA 00 1C 00 08 01 16 0C 01 11 36 33 04 C5  
    


    
    55 AA 03 00 00 01 00 03 55 AA 03 03 00 00 05 55 AA 03 07 00 14 06 00 00 
    08 09 46 00 00 F9 00 00 3A 01 02 00 04 00 00 00 07 BB 55 AA 03 07 00 0C 
    03 00 00 08 16 0C 16 0C 00 00 00 03 67 55 AA 03 07 00 0C 04 00 00 08 0C 
    01 0C 01 00 00 00 03 3E 55 AA 03 07 00 06 0B 00 00 02 01 00 1D 55 AA 03 
    07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 
    1C 00 00 1E                                                             
    



    Requesting Historical Data
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 0C 03 00 00 08 16 0C 16 0C 00 00 00 
    03 67 55 AA 03 07 00 0C 04 00 00 08 0C 01 0C 01 00 00 00 03 3E 55 AA 03 
    00 00 01 01 04 55 AA 03 07 00 14 06 00 00 08 09 52 00 00 FA 00 00 3B 01 
    02 00 04 00 00 00 07 C9 55 AA 03 24 00 00 26 
    

    
    55 AA 00 06 00 08 03 00 00 04 16 0C 16 0C 58 55 AA 00 06 00 08 04 00 00 
    04 0C 01 0C 01 2F 55 AA 00 00 00 00 FF  
    






    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C


    What are the next steps from here?
  • #16 20319375
    p.kaczmarek2
    Moderator Smart Home
    Sorry for the delay, let me analyze the last packets dump.


    tomanyusers wrote:
    On Startup

    
    55 AA 00 00 00 00 FF 55 AA 00 00 00 00 FF 55 AA 00 08 00 00 07 55 AA 00 
    03 00 01 04 07 55 AA 00 1C 00 08 01 16 0C 01 11 36 33 04 C5  
    


    Here WiFi module sends time to TuyaMCU:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C


    tomanyusers wrote:

    
    55 AA 03 00 00 01 00 03 55 AA 03 03 00 00 05 55 AA 03 07 00 14 06 00 00 
    08 09 46 00 00 F9 00 00 3A 01 02 00 04 00 00 00 07 BB 55 AA 03 07 00 0C 
    03 00 00 08 16 0C 16 0C 00 00 00 03 67 55 AA 03 07 00 0C 04 00 00 08 0C 
    01 0C 01 00 00 00 03 3E 55 AA 03 07 00 06 0B 00 00 02 01 00 1D 55 AA 03 
    07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 55 AA 03 
    1C 00 00 1E                                                             
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    tomanyusers wrote:

    Requesting Historical Data
    
    55 AA 03 24 00 00 26 55 AA 03 07 00 0C 03 00 00 08 16 0C 16 0C 00 00 00 
    03 67 55 AA 03 07 00 0C 04 00 00 08 0C 01 0C 01 00 00 00 03 3E 55 AA 03 
    00 00 01 01 04 55 AA 03 07 00 14 06 00 00 08 09 52 00 00 FA 00 00 3B 01 
    02 00 04 00 00 00 07 C9 55 AA 03 24 00 00 26 
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    tomanyusers wrote:

    
    55 AA 00 06 00 08 03 00 00 04 16 0C 16 0C 58 55 AA 00 06 00 08 04 00 00 
    04 0C 01 0C 01 2F 55 AA 00 00 00 00 FF  
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    There are dpIds, but it seems I have already described them above.

    tomanyusers wrote:

    What are the next steps from here?

    Flash OpenBeken and we will try to prepare a config for this device, your help will be needed to test if it works ok.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #17 20319423
    tomanyusers
    Level 3  
    This is great news.
    I am ready and willing to test.
  • #18 20319441
    p.kaczmarek2
    Moderator Smart Home
    @tomanyusers is OpenBeken flashed to that device?

    Let's start with this autoexec.bat:
    
    // start MCU driver
    startDriver TuyaMCU
    // let's say that channel 1 is dpid16   - relay on/off
    setChannelType 1 toggle
    // map dpid16  to channel1, var type 1 (boolean)
    // linkTuyaMCUOutputToChannel dpId varType channelID
    linkTuyaMCUOutputToChannel 16 bool 1
    


    EDIT3: Please try it as is now
    Helpful post? Buy me a coffee.
  • #19 20319498
    tomanyusers
    Level 3  
    Hi

    Flashed and added the autoexec.bat with the details.

    I am not able to toggle the LED from the web portal.

    Here are the logs:
    
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 1C 00 00 1E 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 28 (SetTime) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: received TUYA_CMD_SET_TIME, so sending back time
    Info:TuyaMCU:MCU time to set: 0
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 0
    Info:TuyaMCU:ptime ->gmtime => tm_min: 0
    Info:MAIN:Time 23, idle 457309/s, free 68304, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 1C 00 00 1E 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 28 (SetTime) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: received TUYA_CMD_SET_TIME, so sending back time
    Info:TuyaMCU:MCU time to set: 0
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 0
    Info:TuyaMCU:ptime ->gmtime => tm_min: 0
    Info:MAIN:Time 24, idle 463307/s, free 76912, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 25, idle 470743/s, free 76912, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 28, idle 462074/s, free 68304, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 29, idle 475586/s, free 76912, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 30, idle 948598/s, free 76912, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:CFG:####### Set Boot Complete #######
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    


    Added after 3 [minutes]:

    Just for anybody who needs it in the future I did dump the factory flash.
  • #20 20319539
    p.kaczmarek2
    Moderator Smart Home
    @tomanyusers does the BK toggle state changes when you toggle a physical switch?

    Updated config:
    
    startDriver TuyaMCU
    startDriver NTP
    setChannelType 1 toggle
    setChannelType 2 Voltage_div10
    setChannelType 3 Power
    setChannelType 4 Current_div1000
    linkTuyaMCUOutputToChannel 16 bool 1
    // TAC2121C VoltageCurrentPower Packet
    linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP
    

    The packet used for simulator:
    
    "55AA03070014060000080916000099000023010200040000000310"
    

    Result in simulator:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    wait you need an update for that one, I will push changes to repo and do Release

    Dodano po 10 [minuty]:

    This update:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Please check, if nothing happens do a screenshot and I will add a command to send a request to get data (if that's the 0x08 packet)
    Helpful post? Buy me a coffee.
  • #21 20319569
    tomanyusers
    Level 3  
    No, the BK toggle state does not change when you toggle a physical switch.

    Still just getting the heartbeat every second. No other data is received.

    If I had to guess, it looks like the TuyaMCU is expecting something from the BK7231N at startup before it started sending other data. Like confirmation that the Wifi is connected or something...

    
    info:ntp:seconds since jan 1 1900 = 3879232163
    info:ntp:unix time  : 1670243363
    info:ntp:local time : 2022/12/05 12:29:23
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:ntp:seconds since jan 1 1900 = 3879232224
    info:ntp:unix time  : 1670243424
    info:ntp:local time : 2022/12/05 12:30:24
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes
    info:tuyamcu:tuyamcu received: 55 aa 03 00 00 01 01 04 
    info:tuyamcu:tuyamcu_processincoming[ver=3]: processing command 0 (hearbeat) with 8 bytes


    Added after 9 [minutes]:

    Have updated to the latest release.

    Here is the updated log.


    
    Info:MAIN:Started TuyaMCU.
    Info:NTP:NTP driver initialized with server=217.147.223.78, offset=0
    Info:MAIN:Started NTP.
    Info:GEN:Channel 1 type changed to toggle
    Info:GEN:Channel 2 type changed to Voltage_div10
    Info:GEN:Channel 3 type changed to Power
    Info:GEN:Channel 4 type changed to Current_div1000
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Time 1, idle 677818/s, free 81784, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 00 03 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 2, idle 480810/s, free 81784, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 01 00 2A 7B 22 70 22 3A 22 6C 69 68 34 76 6A 65 6F 79 61 6F 34 6A 65 6B 75 22 2C 22 76 22 3A 22 32 2E 30 2E 30 22 2C 22 6D 22 3A 30 7D 41 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 1 (QueryProductInformation) with 49 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"lih4vjeoyao4jeku","v":"2.0.0","m":0}
    Info:MAIN:Time 3, idle 480202/s, free 81784, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 02 00 00 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF had wrong data lenght?
    Info:MAIN:Time 4, idle 481054/s, free 81784, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 5, idle 482290/s, free 81784, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:ssid:NewNet key:XXXXXXXX
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 6, idle 470010/s, free 76120, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 7, idle 474272/s, free 76120, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 8, idle 290475/s, free 76256, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 9, idle 0/s, free 76256, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 10, idle 0/s, free 76256, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=0.0.0.0 gate=0.0.0.0 mask=0.0.0.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 0, softap: 0, b/g/n
    Info:MAIN:wl_status 3
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING
    Info:MAIN:wl_status 10
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED
    Info:MAIN:wl_status 11
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED
    Info:MAIN:Time 11, idle 147118/s, free 76568, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 12, idle 476759/s, free 76608, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass qqqqqqqqqq
    mqtt_clientID BK7231N_TAC2121C_obk08734C21
    mqtt_host mqtt.home:1883
    Info:MAIN:Time 13, idle 471917/s, free 76520, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to BK7231N_TAC2121C_obk08734C21/+/set
    Info:MQTT:mqtt_subscribed to cmnd/BK7231N_TAC2121C_obk08734C21/+
    Info:MQTT:MQTT client "BK7231N_TAC2121C_obk08734C21" request cb: err 0
    Info:MQTT:MQTT client "BK7231N_TAC2121C_obk08734C21" request cb: err 0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 14, idle 458140/s, free 64824, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 15, idle 467951/s, free 64824, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 16, idle 467092/s, free 67504, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 5/38
    Info:NTP:Seconds since Jan 1 1900 = 3879232663
    Info:NTP:Unix time  : 1670243863
    Info:NTP:Local Time : 2022/12/05 12:37:43
    Info:MAIN:Time 17, idle 451997/s, free 67912, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 18, idle 452230/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 19, idle 461773/s, free 67912, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 20, idle 451254/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.1.106 gate=192.168.1.1 mask=255.255.255.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-61,ssid=NewNet,bssid=4c:5e:0c:a2:23:b7 ,channel=5,cipher_type:CCMP
    Info:MAIN:Time 21, idle 468077/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 22, idle 467146/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 23, idle 464309/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 24, idle 462639/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 25, idle 936375/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 26, idle 466455/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 27, idle 456715/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 28, idle 463220/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 29, idle 466790/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 30, idle 465267/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.1.106 gate=192.168.1.1 mask=255.255.255.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-59,ssid=NewNet,bssid=4c:5e:0c:a2:23:b7 ,channel=5,cipher_type:CCMP
    Info:MAIN:Time 31, idle 465443/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Boot complete time reached (30 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MAIN:Time 32, idle 449495/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 33, idle 915884/s, free 76304, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 34, idle 473649/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 35, idle 466576/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 36, idle 462117/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 37, idle 468875/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 38, idle 463497/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 39, idle 457674/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 40, idle 468571/s, free 67912, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:GEN:dhcp=0 ip=192.168.1.106 gate=192.168.1.1 mask=255.255.255.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-59,ssid=NewNet,bssid=4c:5e:0c:a2:23:b7 ,channel=5,cipher_type:CCMP
    Info:MAIN:Time 41, idle 470416/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 42, idle 462259/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 43, idle 469816/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 44, idle 469101/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 45, idle 460870/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 46, idle 462540/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 47, idle 465865/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 48, idle 459534/s, free 76520, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    
    


    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
  • #22 20319600
    p.kaczmarek2
    Moderator Smart Home
    It seems that you will have to do some testing yourself. It is surprising, because for Hiking meter here:
    https://www.elektroda.com/rtvforum/topic3928897.html
    no one reported the need to send something.

    The UART send command is this: uartSendHex
    Here is what you reported being sent do TuyaMCU on startup:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Command expects argument in hex, without spaces.
    So try:
    
    
    // 0x08 packet type
    uartSendHex 55AA0008000007
    // wifistate 0x03 type
    uartSendHex 55AA000300010407
    // date - should be already send by OBK automatically?
    uartSendHex 55AA001C000801160B1D07302602C1
    // 0x24 type unk
    uartSendHex 55AA00240001C0E4
    

    try one by one and wait to see if something happens
    Helpful post? Buy me a coffee.
  • #23 20319781
    tomanyusers
    Level 3  
    Progress...

    I was able to find what needed to be sent to the meter to make it start reporting readings and toggle the relay. I have no idea what is in this command though.
    
    // wifistate 0x03 type
    uartSendHex 55AA000300010407
    


    I was also able to determine that this command sets the Wifi Signal Strength on the LCD Display
    
    // 0x24 type unk
    uartSendHex 55AA00240001C0E4
    


    The Voltage, Current and Power all match what is on the meter. Just the kWh that is still to be added.
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
  • #24 20319892
    p.kaczmarek2
    Moderator Smart Home
    Does the first command has to be send only once in order for device to work, or does it "request" an update or something?
    Helpful post? Buy me a coffee.
  • #25 20320285
    tomanyusers
    Level 3  
    I only needed to send the command
    uartSendHex 55AA000300010407
    once and the meter sends through the readings every few min. It also seems to set the Status LED to On. Toggling the relay does not change the status LED.

    I have also picked up that the time on the meter is not updated.

    If I have a look at the logs:
    
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 14 06 00 00 08 09 35 00 00 F8 00 00 3A 01 02 00 04 00 00 00 2F D1 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 27 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 6, dataType 0-DP_TYPE_RAW and 8 data bytes
    Info:MQTT:Publishing val 2357 to BK7231N_TAC2121C_obk08734C21/2/get retain=0
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 47
    

    raw data 4 int: 47 is 0.47kWh.
  • #26 20320571
    p.kaczmarek2
    Moderator Smart Home
    tomanyusers wrote:
    I only needed to send the command
    uartSendHex 55AA000300010407
    once and the meter sends through the readings every few min. It also seems to set the Status LED to On. Toggling the relay does not change the status LED.

    We can try to analyze more and figure out how to control that LED. Did you find anything else?

    tomanyusers wrote:

    I have also picked up that the time on the meter is not updated.

    You need to be more specific. What kind of time is shown?

    Wait for our NTP to get time and then use command:
    
    tuyaMcu_sendCurTime
    

    does it help? But it should be done automatically...


    tomanyusers wrote:

    If I have a look at the logs:
    
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 14 06 00 00 08 09 35 00 00 F8 00 00 3A 01 02 00 04 00 00 00 2F D1 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 27 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 6, dataType 0-DP_TYPE_RAW and 8 data bytes
    Info:MQTT:Publishing val 2357 to BK7231N_TAC2121C_obk08734C21/2/get retain=0
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 47
    

    raw data 4 int: 47 is 0.47kWh.

    Is that a total consumption, all time?
    See updated script:
    
    startDriver TuyaMCU
    startDriver NTP
    setChannelType 1 toggle
    setChannelType 2 Voltage_div10
    setChannelType 3 Power
    setChannelType 4 Current_div1000
    setChannelType 5 EnergyTotal_kWh_div100
    // link id 16 to channel 1
    linkTuyaMCUOutputToChannel 16 bool 1
    // link id 1 to channel 5
    linkTuyaMCUOutputToChannel 1 val 5
    // TAC2121C VoltageCurrentPower Packet
    // This will automatically set voltage, power and current
    linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP
    

    Expected result:
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Helpful post? Buy me a coffee.
  • #27 20320773
    tomanyusers
    Level 3  
    With the latest code here is a screen result with the latest script and after sending "uartSendHex 55AA000300010407"
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    The total kWh is always increasing and matches the LCD.

    Here is the Log after a reboot:
    
    o:GEN:Channel 1 type changed to toggle
    Info:GEN:Channel 2 type changed to Voltage_div10
    Info:GEN:Channel 3 type changed to Power
    Info:GEN:Channel 4 type changed to Current_div1000
    Info:GEN:Channel 5 type changed to EnergyTotal_kWh_div100
    Error:CMD:cmd // NOT found (args link id 16 to channel 1)
    Error:CMD:cmd // NOT found (args link id 1 to channel 5)
    Error:CMD:cmd // NOT found (args TAC2121C VoltageCurrentPower Packet)
    Error:CMD:cmd // NOT found (args This will automatically set voltage, power and current)
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Time 1, idle 689534/s, free 81752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 00 03 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 2, idle 491772/s, free 81752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 01 00 2A 7B 22 70 22 3A 22 6C 69 68 34 76 6A 65 6F 79 61 6F 34 6A 65 6B 75 22 2C 22 76 22 3A 22 32 2E 30 2E 30 22 2C 22 6D 22 3A 30 7D 41 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 1 (QueryProductInformation) with 49 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"lih4vjeoyao4jeku","v":"2.0.0","m":0}
    Info:MAIN:Time 3, idle 491034/s, free 81752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 02 00 00 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF had wrong data lenght?
    Info:MAIN:Time 4, idle 479654/s, free 81752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 5, idle 480812/s, free 81752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:ssid:NewNet key:XXXXXX
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 6, idle 477635/s, free 76088, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 7, idle 482598/s, free 76088, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 8, idle 294291/s, free 76224, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 9, idle 0/s, free 76224, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 10, idle 0/s, free 76224, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=0.0.0.0 gate=0.0.0.0 mask=0.0.0.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 0, softap: 0, b/g/n
    Info:MAIN:wl_status 3
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING
    Info:MAIN:wl_status 10
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED
    Info:MAIN:wl_status 11
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED
    Info:MAIN:Time 11, idle 153880/s, free 76536, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 12, idle 464895/s, free 64880, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass qqqqqqqqqq
    mqtt_clientID BK7231N_TAC2121C_obk08734C21
    mqtt_host mqtt.home:1883
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to BK7231N_TAC2121C_obk08734C21/+/set
    Info:MQTT:mqtt_subscribed to cmnd/BK7231N_TAC2121C_obk08734C21/+
    Info:MAIN:Time 13, idle 487808/s, free 53096, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 4/38
    Info:MQTT:MQTT client "BK7231N_TAC2121C_obk08734C21" request cb: err 0
    Info:MQTT:MQTT client "BK7231N_TAC2121C_obk08734C21" request cb: err 0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 14, idle 472560/s, free 53096, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 4/38
    Info:MAIN:Time 15, idle 459250/s, free 53096, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 4/38
    Info:MAIN:Time 16, idle 447360/s, free 76056, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:NTP:Seconds since Jan 1 1900 = 3879298425
    Info:NTP:Unix time  : 1670309625
    Info:NTP:Local Time : 2022/12/06 06:53:45
    Info:MAIN:Time 17, idle 465348/s, free 64792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 18, idle 468977/s, free 76488, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.1.106 gate=192.168.1.1 mask=255.255.255.0 mac=a0:92:08:73:4c:21 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-60,ssid=NewNet,bssid=4c:5e:0c:a2:23:b7 ,channel=5,cipher_type:CCMP
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 1C 00 00 1E 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 28 (SetTime) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: received TUYA_CMD_SET_TIME, so sending back time
    Info:TuyaMCU:MCU time to set: 1670309631
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 6
    Info:TuyaMCU:ptime ->gmtime => tm_min: 53
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 1C 00 00 1E 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 28 (SetTime) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: received TUYA_CMD_SET_TIME, so sending back time
    Info:TuyaMCU:MCU time to set: 1670309632
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 6
    Info:TuyaMCU:ptime ->gmtime => tm_min: 53
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 1C 00 00 1E 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 28 (SetTime) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: received TUYA_CMD_SET_TIME, so sending back time
    Info:TuyaMCU:MCU time to set: 1670309633
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 6
    Info:TuyaMCU:ptime ->gmtime => tm_min: 53
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:CFG:####### Set Boot Complete #######
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    


    At this stage, the date and time on the meter are not updated.

    After Sending The "uartSendHex 55AA000300010407" and "tuyaMcu_sendCurTime" commands here are the logs:
    
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 03 00 00 05 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 3 (WiFiState) with 7 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 14 06 00 00 08 09 27 00 00 F7 00 00 39 01 02 00 04 00 00 00 34 C6 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 27 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 6, dataType 0-DP_TYPE_RAW and 8 data bytes
    Info:MQTT:Publishing val 2343 to BK7231N_TAC2121C_obk08734C21/2/get retain=0
    Info:MQTT:Publishing val 247 to BK7231N_TAC2121C_obk08734C21/4/get retain=0
    Info:MQTT:Publishing val 57 to BK7231N_TAC2121C_obk08734C21/3/get retain=0
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 52
    Info:MQTT:Publishing val 52 to BK7231N_TAC2121C_obk08734C21/5/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 0C 03 00 00 08 16 0B 16 0B 00 00 00 00 62 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 19 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 0-DP_TYPE_RAW and 8 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 0C 04 00 00 08 0B 06 0B 06 00 00 00 05 48 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 19 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 4, dataType 0-DP_TYPE_RAW and 8 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 06 0B 00 00 02 01 00 1D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 13 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 11, dataType 0-DP_TYPE_RAW and 2 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 03 00 00 05 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 3 (WiFiState) with 7 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 11 10 01 00 01 01 12 03 00 08 32 32 34 39 30 30 36 38 E9 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 24 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 16, dataType 1-DP_TYPE_BOOL and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Info:MQTT:Publishing val 1 to BK7231N_TAC2121C_obk08734C21/1/get retain=0
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 18, dataType 3-DP_TYPE_STRING and 8 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:MCU time to set: 1670310008
    Info:TuyaMCU:ptime ->gmtime => tm_hour: 7
    Info:TuyaMCU:ptime ->gmtime => tm_min: 0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    


    I manually set the date and time on the meter to:
    Date: 2022.12.06
    Time: 08:44:23
    Then Send "tuyaMcu_sendCurTime"
    The result on the meter is:
    Date: 2022.11.06
    Time: 06:46:23
    The time seems correct (Just need to add the time zone) I'm GMT+2
    Why the month changes I am not sure.

    On the Command:
    uartSendHex 55AA000300010407

    I have done some testing:

    uartSendHex 55AA000300010407
    -> Turn the LED ON.
    uartSendHex 55AA000300010306
    -> LED On for 0.25 seconds and off for 1 seconds
    uartSendHex 55AA000300010205
    -> LED On for 0.25 seconds and off for 2 seconds
    uartSendHex 55AA000300010104
    -> Slow flashing
    uartSendHex 55AA000300010003
    -> Fast flashing
    This aligns with the user manual.
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    Looks like the TyuaMCU only start to send data when it thinks it's connected to the 'cloud'

    Added after 32 [minutes]:

    I did some testing on the Wifi signal strength indicator on the LCD. This is what I found.
    
    uartSendHex 55AA00240001FF23  - Sets 3 Bars
    uartSendHex 55AA00240001C0E4  - Sets 3 Bars
    uartSendHex 55AA00240001B1D5  - Sets 2 Bars
    uartSendHex 55AA00240001A2C6  - Sets 1 Bar
    uartSendHex 55AA0024000181A5  - Sets 0 Bars
    uartSendHex 55AA002400011E42  - Sets 0 Bars
    



    Did some testing and the xx in the below is the 2's complement of the RSSI. So -54dBm = CA
    uartSendHex 55AA00240001xx42
  • #28 20323453
    p.kaczmarek2
    Moderator Smart Home
    This is very good job and very useful information, but it will take some time to process.

    The wrong month number might suggest that Tuya numbers months from 1 instead of from 0 and we have to add 1 while sending the date.... let me see...
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    wait...
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C
    Tuya uses 1-12 and tm structure is 0-11? So now that's solved, I pushed a fix:
    https://github.com/openshwprojects/OpenBK7231...mmit/e52ec34cc981973fca31eb7fa7cdc51990ac9bcb
    Can you check now?


    BTW: "uartSendHex 55AA00240001xx42" this will most likely not work (I mean replacing the 'xx' with test value) because you also have to recalculate the checksum of the packet, which is the last hex number here . Checksum changes with each change in the packet.
    Helpful post? Buy me a coffee.
  • #29 20323542
    tomanyusers
    Level 3  
    Hi

    Using the version above, the date and time are now set correctly. But still, need to set the time zone. How do I do that?

    Did some more testing.
    The command "uartSendHex 55AA000300010407" needs to be sent every few hours to tell the TuyaMCU that it is still connected to the "cloud". So that the TuyaMCU will send through the readings. Seems to time out at around 6 hours.

    Also, "tuyaMcu_sendCurTime" only updated the time once the above command has been sent so that the TuyaMCU thinks it's connected to the "cloud"

    For setting the Wifi Signal Strength. I tested by using the following.
    Take the RSSI for the front web interface (eg -54), calculate the 2's complement (0xCA), and manually calculate the checksum and it works.
    "uartSendHex 55AA00240001CAEE"
    I also found a different menu on the meter and by doing the above I am able to see the RSSI displayed correctly on the meter.
  • #30 20332622
    p.kaczmarek2
    Moderator Smart Home
    Thanks, I have added a tuyaMcu_sendRSSI command with implementation. Check: "tuyaMcu_sendRSSI -80", etc

    When checked, we will need to somehow make it being send automatically to device.
    By the way, are you sure that you have to send "55AA00 03 0001 04 07", the 0x03 version packet. WiFi status, yourself?
    Home Assistant Integration: Reflashing BK7231N in Tuya Smart DIN-rail Energy Meter TAC2121C

    There is already a function Tuya_SetWifiState in Obk and it's called according to MQTT/WiFi status....
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around the integration of the BK7231N chip in the Tuya Smart DIN-rail Energy Meter TAC2121C with Home Assistant. The user seeks to reflash the device to eliminate reliance on Tuya services. Various options for reflashing are explored, including using OpenBK7231N or replacing the BK7231N with an ESP-12F flashed with Tasmota or ESP-Home. The main challenge identified is the lack of information regarding the energy meter's chip and the necessary drivers. Participants share insights on the components found on the PCB, including the V9911 chip, and discuss the UART communication protocol. They analyze data packets to extract energy statistics, voltage, and power readings. The conversation progresses to successfully sending commands to the TuyaMCU, enabling the meter to report readings and toggle the relay. The final steps involve refining the autoexec.bat configuration for optimal performance and addressing issues like RSSI display and data rounding.
Summary generated by the language model.
ADVERTISEMENT