Error with modbus tcp

Hallo,
I have a question about Modbus in Home Assistant:

I added a Modbus extension to the configuration.yaml file (following a suggestion from Martin Kaiser at https://github.com/kaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant).

In my opinion, all parameters from the Home Assistant Modbus documentation are entered correctly, and the connection type is also TCP.

Then why do I get an error message when checking the yaml file like this:
Configuration warnings
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘baudrate’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘bytesize’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘method’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘parity’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘port’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘stopbits’ not provided
Invalid config for ‘modbus’ at configuration.yaml, line 20: required key ‘type’ Not provided


In my opinion, these parameters are only necessary for serial connections.

Where could the error lie?

Regards,
moritz54

Modbus is a serial bus protocol with after the data is collected it is in your case transported over tcp.

There is also modbus-tcp.
I assume you are using esphome for this because you didn’t provided enough info. Did you use the right component in Esphome. I am not aware if there is a modbus tcp platform available

Thank you for your fast answer.
no I’m nor using esphome. My host is a Sungrow-PV-inverter.
This device has an IP interface over which the Modbus protocol is transmitted via TCP.

Flawless communication is possible using other software, such as pymodbus or ModbusMaster, provided the TCP, IP address, and port are configured.

Here is an excerpt from the modbus.yaml file:


- name: Sungrowxy
     typ: tcp  
     host: "myIP"
     port: 502
      message_wait_milliseconds: 30
      delay: 5
     timeout: 10

     - sensors: sungrow_inverter serial
           unique_id: sg_inverter_voltage
          device_address: "mydevice"
          address: 5002
          input_typ: input
          data_type: unit16
         scan_interval: 600

No baud rate settings, etc., are required here.

Or have I misunderstood something in the documentation?

Regards
moritz54

not tested since no sungrow but it should read something like that

modbus:
  - type: tcp # <== type: not typ:
    host: xxx.xxx.xxx.xxx # <== the inverter's IP
    port: 502 # <== modbus uses port 502 not 5002 or *1)
    name: "myInverter" # <== or sungrow or whatever you like
    sensors:
      - name: inverter_serial
        unique_id: inverter_serial
        slave: 1 # <== the number you likely added at line device_address?
        address: 5002 # <== this is the modbus address you read from
        data_type: unit16
        scan_interval: 30

*1) it could be 5002 if you configured this in your inverter but I doubt since that’s very uncommon one does it like that. Normally one uses the standard port numbers.

And watch the indents your looked a bit fancy … YAML doesn’t forgive wrong indentation but simply fails.

EDIT: and the error asking for baudrate and such resulted from the line where you used “typ:” but “type:” since if type: tcp isn’t given the integration assumes serial.

Thank you, the request has been resolved. I found the error on my end.

1 Like