Modbus - reading multiple registers

Hello,
I am having trouble understanding how to correctly read more than 1 register via Modbus at a time. For example, as part of my Modbus config I wanted to insert this entity:

      - name: "Heating mode"
        unique_id: 52b65b39-fbb5-414d-8eca-5873d140d222
        scan_interval: 30
        slave: 1
        address: 2
        input_type: holding
        count: 2
        scale: 1
        offset: 0
        precision: 0
        data_type: uint16

If the count is set to 1, then HA correctly creates an entity called sensor.heating_mode. But when I set it to 2, then this entity value is unavailable. What I was expecting is something like 2 entities called sensor.heating_mode_0 and sensor.heating_mode_1

Right now I am reading a lot of registers one by one. It would be more efficient communication wise to do that in bulk, but I don’t know how to parse the read data.

I would appreciate all help!

slave_count

      - name: "EB9 reg38 c3" # 0x0026
        slave: 1
        address: 38
        input_type: input
        count: 3
        slave_count: 2 # count - 1
        data_type: uint16

Hi, thank you for the answer. How to understand this config when count = 3 and slave_count = 2? The documentation states it is usefull for coils only though…

If uint16, count = number of registers = sensors created.

slave_count = count - 1

Because starts with 0.

Only useful for same type of registers.

It’s not perfect

Thank you for the additional explanation. So I have added this to read 3 registers starting from 1025 dec:

      - name: "broetje_reg1025"
        unique_id: fb3fe7c2-cb11-49d7-99f0-e748b62da948
        scan_interval: 30
        slave: 1
        address: 1025
        input_type: holding
        unit_of_measurement: °C
        count: 3
        slave_count: 2
        scale: 0.015625
        offset: 0
        precision: 1
        data_type: uint16

The created entities are:

The indexes seem to be flipped… Which entity has the starting address 1025?

1 Like

The indexes seem to be flipped… Which entity has the starting address 1025?

Look for the name only. I think

You can change entity id.

Hi there again…

I have just noticed an issue with this approach. I have few registers defined in a row. They should be the same unit:

    sensors:
      - name: "g310-5_addr0"
        unique_id: 43f7816c-6959-4fa1-9c2f-abaa6430aed7
        scan_interval: 30
        slave: 100
        address: 0
        input_type: input
        count: 8
        slave_count: 7
        scale: 1
        offset: 0
        precision: 0
        unit_of_measurement: mV
        data_type: uint16

Problem is that the unit appears only for the first entity. Here an exemplary card for the 8 entities:

image

This doesn’t bother me as such, but the actual problem is that only entities consisting of unit_of_measurement can be displayed on a graph. So the graph work for the 1st entity:

image

But not the second one and after:

image

Do you have any idea how to work this around…? I would appreciate all help.

Use customize.yaml

# fix error log

sensor.athom_p1_energy_factor:
  unit_of_measurement: "%"

# MariaDB

sensor.db_size:
  icon: mdi:database
  state_class: measurement

Thank you for the reply. I think I am missing the full context. I tried adding this part to the configuration.yaml but it did not “compile”:

sensor.sensor.g310_5_addr0_1:
  unit_of_measurement: mV

What did you mean exactly by customize.yaml?

configuration.yaml

# ...
homeassistant:
  customize: !include customize.yaml

# ...

customize.yaml

sensor.g310_5_addr0_1:
  unit_of_measurement: mV
1 Like

Works exactly as intended, thank you very much!

1 Like