Modbus TCP - invalid configuration - new YAML formatting (extra keys / key not provided errors)

Hi,

I had this Modbus integration working a few months ago, and I understand that the Modbus YAML formatting has changed over the summer, so I’m now revisiting to try and get it working again.

I’m using this reference to try and configure it correctly:

A section of this web link looks like this:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    sensors:
      - name: Sensor1
        unit_of_measurement: °C
        slave: 1
        address: 100

I’ve simplified my configuration as much as possible to try and solve this, and it looks like this:

modbus:
  - name: CC2
    type: tcp
    host: 192.168.2.22
    port: 502
    sensors:
      - name: WattsNow
#        unit_of_measurement: W
        address: 4119
#        count: 2
#        device_class: power

The problem I’m having is under: Home Assistant / Server controls / check configuration. I’m receiving these errors:

Invalid config for [modbus]: extra keys not allowed @ data['modbus'][0]['host']. Got '192.168.2.22'
extra keys not allowed @ data['modbus'][0]['sensors']. Got [OrderedDict([('name', 'WattsNow'), ('address', 4119)])]
not a valid value for dictionary value @ data['modbus'][0]['type']. Got 'tcp'
required key not provided @ data['modbus'][0]['baudrate']. Got None
required key not provided @ data['modbus'][0]['bytesize']. Got None

(and more similar ones…)

So it sort of looks like it’s looking for serial connection details, and not a TCP connection?

If I remove the ‘sensors’ section, the configuration is valid - but isn’t much use without any sensors(!)

Been trying different things for a couple of hours and no joy. I think I’ve carefully checked all the YAML indentations etc…

Any help would be greatly appreciated.

cheers

/steve

1 Like

Working here

Maybe it is your file editor

Hi and thanks for the comment!

The editor I’m using is the ‘file editor’ HA add-on, so should be OK, but the fact that the configuration is working somewhere else was VERY useful.

I started looking elsewhere and found that for some reason (maybe because I uploaded a backup?), I was running a really old version of the core.

I ended up reinstalling HA, and now the configuration is working.

I really appreciate that you took the time to try out my configuration, it really helped me a lot!
Thank you!

/steve