Modbus Block Reading with Mixed Data Types

Hi everyone,

I’m currently running into an issue where my device (read via Modbus) can’t really keep up with lots of single requests. It kind of works, but with ~40–50 sensors / single reads per second, the requests sometimes don’t even fit into one second anymore, so delays start to build up.

So I’d like to switch to block reading. According to the docs and also this thread:
https://community.home-assistant.io/t/extract-data-from-modbus-multiple-register/607120/7
it seems possible, but apparently only if you use the same data type, because you then split/offset the data yourself afterwards.

My problem is that the register ranges I need contain mixed types (e.g. int32, int16, uint16, uint32).

In the end I’d probably end up with ~20 block reads, which would already be a lot better but I’d have to read some registers multiple times.

Is there a way in Home Assistant to read one block and define different data types within that block? For example: read registers 5000–5100, and then specify that certain parts are int32, others uint16, etc.

Thanks for your Help.

you’re asking for the data_type: custom + structure + count ? It’s all in the docs.

modbus:
  sensors:
  - name: xxxx
    slave: 1
    count: 15
    address: 12345
    data_type: custom
    structure: ">5h2H4I"

see struct — Interpret bytes as packed binary data — Python 3.14.3 documentation for details about what the struct content is for. If you got it, you see that the example does match the count: 15

oh and a final note since you asked for 100 in one go.
Remember that an entity states unfortunately got a length limit which sort of ruins this clever feature since if the resulting comma separated list of values exceeds this lengthlimit it’ll get cut off.
The example works but if you build a struct with a count of 65 or more it might fail.

1 Like