Looking for direction on reading a accumulator register on a TUF-2000M flow meter

Hey all - hoping someone can help a newbie figure out how to get a value from my flow meter.

I have managed to get the flow rate into HA, but I can't figure out how to get the accumulator total.

Here is the original sensor section (below) in ESPHome, and the MODBUS info from the meter at the bottom. I have currently deleted the second sensor (Positive_Accumulator) and the value I see on the meter console for flow rate (flowmeter at address 0x1) is the same one I see in the HA sensor. :tada:

I had tried changing the value_type for Positive_Accumulator from FP32 to U_DWORD after I noticed that the MODBUS shows LONG as the format. I thought I would at least get the integer portion of the Net Accumulator, but I just get random(?) numbers. Same thing when I changed the register to 0x19. Can anyone point me in the right direction? I thought I might have to add the LONG value to the decimal fraction from the next register, but that is beyond me...

sensor:
  - platform: modbus_controller
    modbus_controller_id: tuf2000m
    name: flowmeter
    id: flow
    register_type: holding
    address: 0x1
    register_count: 2
    response_size: 2
    accuracy_decimals: 3
    value_type: FP32
    unit_of_measurement: m³/h
  - platform: modbus_controller
    modbus_controller_id: tuf2000m
    name: Positive_Accumulator
    register_type: holding
    address: 0x9
    register_count: 2
    value_type: FP32
    device_class: water
    state_class: measurement
    unit_of_measurement: m³

This is esphome, right?
Try U_DWORD as the type

Yeah - as I noted, I tried that after I noticed the LONG format in the MODBUS table

Modbus registers are always 16 bits long (2 words), but quite what goes into them depends on the manufacturer.

Here, the docs suggest that everything uses 2 concurrent registers (4 words), and is either a "long" or a "real4".

REAL4, or FLOAT, is said to be a Singular IEEE-754 number, which apparently is a 32-bit (hence 4 words) format with the leading bit being the sign, then 8 bits for the exponent (offset by -127) and 23 bits for the mantissa.

So, once you have read the 2 registers into a buffer, the actual number is

value = (-1)sign + 1 * mantissa 2 * exponent -127

The LONG is easier, being a signed (presumably leading bit) integer, with lower byte first (little-endian).

To make it even more interesting, yes the accumulator has a LONG for the value followed by a REAL4 for the decimal fraction.

Since this is probably all little-endian, I think that the U_DWORD_R has to be used to get a basic unsigned double reversed integer. After that, it probably means unpicking the sign, then hacking away at the IEEE-754.

Since the positive accumulator must be flow one way, and the negative accumulator flow the other way, the "Net accumulator" is most likely just the sum of the two, and being a LONG is possibly easier to work with?

Even if the LONG is signed, this only applies for negaive numbers, hence for a flow meter where the flow is always 'positive' the net will always be positive, and therefore the signed can be treated as an unsigned and just used...

As long as you get the endian correct.

Thanks for your reply!

Yeah - I really only care about the NET accumulator - the negative accumulator is turned off in any case. Most of what you wrote is WAYYY above my pay grade, though I do understand some of it as I did learn some assembly programming many many years ago in the mid-80s.

I did see some references to "endianness" in this post where someone else who knows way more than I do was trying to figure this out, but I guess I have to try reading up on "endianness", as I have zero idea about that (or no longer remember?)

Bottom line, it looks like I may just have to give up the quest for the net accumulator value and just live with the flow rate. This is a Chinese meter with limited documentation, as I was simply intending to try to figure an economical way to set up a high flow leak alert in HA, which I can do with the flow rate number. The accumulator value was just going to b e nice extra. I did get what they referred to as a "TUF-2000M Ultrasonic Flow Meter RS485 Communication Protocol Manual" - but I am not 100% sure it gives me the info I need.

I will do some research on the areas you pointed out. Thanks!

I don't use ESPhome, so it took me a while to find the documented list of data types

The default is big-endian (the byte order is high-low in the word), but if the manufacturer uses little-endian (byte order low-high) then you will need

U_DWORD_R
S_DWORD_R
FP32_R

I think that you can get away with S_DWORD_R for the LONG and FP32_R for the REAL4. Also try reading S_DWORD_R just on register 25-26.

Good luck!

Could you provide some of those "random" numbers vs the expected one?

I did change the value_type to U_DWORD_R for register 0x19 (25) and it now at least shows a consistent number - though the number I am getting is 2,937,126,912 m³ :joy: instead of what the meter display says should be 8507. I guess I am out of my depth. :man_shrugging:

OK - I think we cross-posted as I had just tried U_DWORD_R - I will switch it to S_DWORD_R on 0x19 (25) to see if I can at least get the integer portion out correctly. Thanks again!

Thanks - I think the random numbers came from the values being transmitted as Endian, to that issue may be sorted.

FYI - switching the value_type for register 25 from U_DWORD_R to S_DWORD_R changed the reported value from 2,937,126,912 m³ to -1,357,840,384 m³

The value reported on the meter display is 8507.

I have just disabled that sensor for now and I will see if I can find more information.

Thanks everyone for your help!

While you are troubleshooting and narrowing down your data, try the Protocol Wizard to send and receive data.