Modbus Holding Register- yaml coding issues

Hello all
I am trying to read data from a RS485 Modbus output on a wind turbine.
The RS485 is converted to Ethernet via a TCP Server adaptor
Using Radzio I can read the data via rtuovertcp no problem.

However i just cannot get this data into HA so I am clearly not doing something right.
yaml code being used is thus:

modbus:
    name: "hub1"
    close_comm_on_error: true
    delay: 1
    timeout: 5
    type: rtuovertcp
    host: 192.168.2.90
    port: 502
    sensors:
      - name: TURBINE_VOLTAGE
        address: 0
        input_type: holding
        unit_of_measurement: V
        device_class: voltage
        state_class: measurement
        count: 1
        scale: 0.01
        offset: 0
        precision: 1
        data_type: uint16

Try as I might with every variation I can think of of address, data type, count etc I cannot get HA to display a value - I just get Unavailable all the time.
It must be related to the address I am calling and how I am calling off the data fields within it.

I might add that at the moment I am just trying to read the first field ‘0’ not the whole data - if i can get that working then I am sure I can add the extra fields easily.

Any pointers please?

Check your system log. If the sensor is unavailable, I’d expect an error message.

Only this one:

Pymodbus: hub1: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response

This would seem to suggest to me it is working as a code but just not looking in the right place…

Is there not a ‘register’ function in yaml?

I don’t think this is expected behavior. If you tried to read an invalid holding register, you should have received a modbus error frame.

Try enabling debug logging for modbus by adding this to configuration.yaml and restarting HA:

logger:
  default: warning
  logs:
    homeassistant.components.modbus: debug
    pymodbus.client: debug

and post the resulting logs.

I’m not sure what you mean by that.
Your sensor has input_type: holding, so it is trying to read a holding register.

Logger: homeassistant.components.modbus.modbus
Source: components/modbus/modbus.py:391
Integration: Modbus (documentation, issues)
First occurred: 14:38:20 (1 occurrences)
Last logged: 14:38:20

Pymodbus: hub1: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

So it is just not seeing the data flow for whatever reason it seems.

I think the data us coming over as uint16_t not uint16…
Is there a way to convert this in yaml?

I don’t understand what you mean.
In your yaml config, you have specified that the holding register’s data should be interpreted as uint16 – 16-bit unsigned integer.

uint16_t is just the typename for a 16-bit unsigned integer in the C programming language. The _t suffix is there only because that’s the convention for naming types in that language.

However, according to the log message, the failure occurs earlier in the communication process – much earlier that this data type conversion.

If I had to guess, I would say that either Home Assistant cannot reach 192.168.2.90 (although I’d expect to get a different error message even earlier if that was the case), or there is a problem somewhere on the modbus link (between the TCP adapter and the wind turbine). Since you were able to get it working Radzio, my guess would be that the TCP adapter is at fault here. Did you disconnect Radzio before trying to connect with Home Assistant? Perhaps it only supports one connection at a time.

OK.
If uint16 and uint16_t are in fact the same it’s not that then.
I can run more than one instance of Radzio and the data streams to all instances OK. The TCP Server is set to accept up to 4 streams currently (max 16).
I have tried it with Radzio off anyway - no difference.

I think we are getting comms just not either reading the data or interpreting it:

2023-01-18 20:53:14.042 DEBUG (SyncWorker_2) [pymodbus.client.sync] Connection to Modbus server established. Socket (‘192.168.2.45’, 49753)

2023-01-18 20:53:14.042 INFO (SyncWorker_2) [homeassistant.components.modbus.modbus] modbus hub1 communication open

2023-01-18 20:53:29.246 DEBUG (SyncWorker_7) [pymodbus.client.sync] New Transaction state ‘SENDING’

2023-01-18 20:53:32.251 ERROR (SyncWorker_7) [homeassistant.components.modbus.modbus] Pymodbus: hub1: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

I have RESOLVED this :slight_smile:
It appears that (despite the documentation saying it was not needed for non-direct serial connections) you need to add a Slave address as well.
So a valid entry is for instance:

sensors:
      - name: BATTERY_VOLTAGE
        unique_id: #anything unique
        address: 0
        slave: 1
        scale: 0.1
        precision: 1
        input_type: holding
        unit_of_measurement: V
        device_class: voltage
        state_class: measurement
        data_type: uint16

Thank you for your help!