Modbus failure

Hello, I am a pure noob to HA and programming.

i tried to integrate my victron system with the modbus.

but as soon as i add “modbus: !include modbus.yaml” to the “configuration.yaml”, create the “modbus.yaml” in the same folder and add:

Example configuration.yaml entry for a TCP connection

modbus:

  • name: “Victron”
    type: tcp
    host: 192.168.1.140
    port: 502
    sensors:
    • name: Grid Voltage L1 in
      unit_of_measurement: V AC
      slave: 100
      address: 817
      scale: 0.1
      precision: 2

I get the following failures:

Failure N°1:
Logger: homeassistant.setup
Source: setup.py:178
First occurred: 09:04:24 (1 occurrences)
Last logged: 09:04:24
Setup failed for modbus: Invalid config.

Failure N°2:
Logger: homeassistant.config
Source: components/modbus/validators.py:249
First occurred: 09:04:23 (1 occurrences)
Last logged: 09:04:23
Unknown error calling modbus CONFIG_SCHEMA

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config.py”, line 842, in async_process_component_config
return component.CONFIG_SCHEMA(config) # type: ignore
File “/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py”, line 386, in validate_mapping
cval = cvalue(key_path, value)
File “/usr/local/lib/python3.9/site-packages/voluptuous/validators.py”, line 215, in _run
return self._exec(self._compiled, value, path)
File “/usr/local/lib/python3.9/site-packages/voluptuous/validators.py”, line 339, in _exec
v = func(path, v)
File “/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/src/homeassistant/homeassistant/components/modbus/validators.py”, line 249, in duplicate_modbus_validator
if hub[CONF_TYPE] == SERIAL:
KeyError: ‘type’

Where do i start to chase that error?

General:
There are some inconsistencies between HA modbus guide and other tutorials, for example with the ‘name’ or name… this confuses me even more.

Hi, have the same problem, have you already found a solution?

A few things to take note of:

  • Read the documentation Modbus - Home Assistant
    That will show you how to properly format this
  • When you create a separate yaml, in this case modbus you do not need to specify its modbus again, since thats what the line modbus: !include modbus.yaml already does.
    Again, Read the documentation: Splitting up the configuration - Home Assistant
  • So something like this in your modbus.yaml:
- type: tcp
  host: 192.168.1.140
  port: 502
  name: “Victron”

  sensors:
    -  name: Grid Voltage L1 in
       unit_of_measurement: V AC
       slave: 100
       address: 817
       scale: 0.1
       precision: 2

okay i will test it. I’m not a programmer but rather an end user.
thanks

Neither am i :smiley: Dont get me wrong, but everything you have todo in HA is for you to find out.
There is no pro support just alot of people in this community that help out: How to help us help you - or How to ask a good question
But do read each document, there are many examples in them that will help you understand what the code does.

1 Like

Excuse me, this is the basic framework that I intend to take, but as I am a layman it is not that easy for me, you still have an idea.
that is currently all that works without errors:
modbus:

  • type: tcp
    host: host number
    port: 502
    name: STP etc.

sensor:

  • platform: modbus
    scan_interval: 60 #time in seconds for getting values
    registers:

    • name: SMA_Power_AC
      unit_of_measurement: W
      slave: 3
      register: 30775
      count: 2
      data_type: int
    • name: PV Daily Yield
      unit_of_measurement: kWh
      slave: 3
      register: 30517
      scale: 0.001
      precision: 3
      count: 4
      data_type: uint
    • name: PV Total Production
      unit_of_measurement: MWh
      slave: 3
      register: 30513
      scale: 0.000001
      precision: 3
      count: 4
    • name: Grid Voltage
      unit_of_measurement: V
      slave: 3
      register: 30783
      count: 2
      scale: 0.01
      precision: 2
      data_type: uint
    • name: Grid frequency
      unit_of_measurement: Hz
      slave: 3
      register: 30803
      count: 2
      scale: 0.01
      precision: 2
      data_type: uint
    • name: SMA_temp
      unit_of_measurement: °C
      slave: 3
      register: 30953
      count: 2
      scale: 0.1
      precision: 1
      data_type: int
    • name: SMA_status
      slave: 3
      register: 30201
      count: 2
    • name: SMA_grid
      slave: 3
      register: 30217
      count: 2
    • name: Insulation
      slave: 3
      register: 30225
      count: 2
      scale: 0.001
      unit_of_measurement: kOhms
    • name: SMA_Residual_current
      slave: 3
      register: 31247
      count: 2
      scale: 1
      unit_of_measurement: mA
    • name: Apparent Power
      unit_of_measurement: VA
      slave: 3
      register: 30813
      scale: 1
      precision: 0
      count: 2
      data_type: int
    • name: Reactive Power
      unit_of_measurement: VAr
      slave: 3
      register: 30805
      scale: 1
      precision: 0
      count: 2
      data_type: int
  • platform: template
    sensors:
    modbus_sma_pv_power:
    entity_id: sensor.sma_power_ac
    friendly_name: ‘Power Output’
    value_template: >-
    {% if states(‘sensor.sma_power_ac’)|float < 0 or states(‘sensor.sma_power_ac’)|float > 10000 %}
    0
    {% else %}
    {{ states(‘sensor.sma_power_ac’) }}
    {% endif %}
    unit_of_measurement: “W”
    icon_template: mdi:flash-circle
    modbus_sma_pv_apparent_power:
    entity_id: sensor.apparent_power
    friendly_name: ‘Apparent Power’
    value_template: >-
    {% if states(‘sensor.apparent_power’)|float < 0 or states(‘sensor.apparent_power’)|float > 10000 %}
    0
    {% else %}
    {{ states(‘sensor.apparent_power’) }}
    {% endif %}
    unit_of_measurement: “VA”
    icon_template: mdi:flash-circle
    modbus_sma_pv_reactive_power:
    entity_id: sensor.reactive_power
    friendly_name: ‘Reactive Power’
    value_template: >-
    {% if states(‘sensor.reactive_power’)|float < 0 or states(‘sensor.reactive_power’)|float > 10000 %}
    0
    {% else %}
    {{ states(‘sensor.reactive_power’) }}
    {% endif %}
    unit_of_measurement: “VAr”
    icon_template: mdi:flash-circle
    modbus_sma_pv_residual:
    entity_id: sensor.sma_residual_current
    friendly_name: ‘Residual Current’
    value_template: >-
    {% if states(‘sensor.sma_residual_current’)|float < 0 or states(‘sensor.sma_residual_current’)|float > 10000 %}
    0
    {% else %}
    {{ states(‘sensor.sma_residual_current’) }}
    {% endif %}
    unit_of_measurement: “mA”
    icon_template: mdi:flash-circle
    modbus_sma_temperature:
    entity_id: sensor.sma_temp
    friendly_name: ‘Inverter Temp’
    value_template: >-
    {% if states(‘sensor.sma_temp’)|float < 0 or states(‘sensor.sma_temp’)|float > 100 %}
    0
    {% else %}
    {{ states(‘sensor.sma_temp’) }}
    {% endif %}
    unit_of_measurement: “°C”
    modbus_grid_frequency:
    entity_id: sensor.grid_frequency
    friendly_name: ‘Grid Frequency’
    value_template: >-
    {% if states(‘sensor.grid_frequency’)|float < 30 or states(‘sensor.grid_frequency’)|float > 100 %}
    Not Measured
    {% else %}
    {{ states(‘sensor.grid_frequency’) }}
    {% endif %}
    unit_of_measurement: “Hz”
    modbus_grid_voltage:
    entity_id: sensor.grid_voltage
    friendly_name: ‘Grid Voltage’
    value_template: >-
    {% if states(‘sensor.grid_voltage’)|float < 180 or states(‘sensor.grid_voltage’)|float > 300 %}
    Not Measured
    {% else %}
    {{ states(‘sensor.grid_voltage’) }}
    {% endif %}
    unit_of_measurement: “V”
    modbus_inverter_status:
    entity_id: sensor.sma_status
    friendly_name: ‘Inverter Status’
    value_template: >-
    {% if is_state(‘sensor.sma_status’, ‘307’ ) %}
    OK
    {% elif is_state(‘sensor.sma_status’, ‘303’ ) %}
    Off
    {% elif is_state(‘sensor.sma_status’, ‘455’ ) %}
    Warning
    {% elif is_state(‘sensor.sma_status’, ‘35’ ) %}
    Fault
    {% endif %}
    modbus_grid_contactor:
    entity_id: sensor.sma_grid
    friendly_name: ‘Grid contactor’
    value_template: >-
    {% if is_state(‘sensor.sma_grid’, ‘51’ ) %}
    Closed
    {% else %}
    Open
    {% endif %}

Pretty plz use formatting for the code:

Type or paste your code with  ``` code goes here ```

Due to how the forum works what u pasted is now unusable, note the bullet points that appeared
Its also a quick and dirty check, if all the text is red you prob already made a mistake.
Makes me think you still didnt read :stuck_out_tongue:

Sorry, I got it from the link

i have solved it with a new image, guess i screwed it up somewhere.
Finally i moved to mqtt, this is easier as the values are pushed and does not need to be known before.

Hi, yes, I already understood that, so I also use TCP, but I come right here with the example posted and then that’s the end for me now it’s about the sensors that I cannot access. Now for me is that


so any solution ?

Yeah almost.

and any inputs about the solution ?

I haven’t gotten around to it yet

that’s how it worked for me now.
however, had to restart the inverter.

modbus:

  • type: tcp
    host: 192.168.2.155 # SMA TriPower
    port: 502
    name: “sma”
    close_comm_on_error: true
    delay: 5
    timeout: 5
    sensors:
    • name: PV_Gesamtertrag
      unit_of_measurement: kWh
      slave: 3
      address: 30531
      input_type: input
      count: 2
    • name: PV_Leistung
      unit_of_measurement: W
      slave: 3
      address: 30775
      input_type: input
      count: 2
    • name: PV_Tagesertrag
      unit_of_measurement: Wh
      slave: 3
      address: 30517
      count: 4
      data_type: int
    • name: Netzverbrauch
      slave: 3
      address: 30865
      unit_of_measurement: ‘W’
      count: 2
      data_type: uint

Hello, a short report.
Sensors all work as soon as I exchange the register for an address.

Hey there!

Did you find the solution for the keyerror? Cause I got same error, and don’t know how to get rid of it.
Thanks! :slight_smile:

2021-11-26 20:43:50 ERROR (MainThread) [homeassistant.config] Unknown error calling modbus CONFIG_SCHEMA
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config.py", line 842, in async_process_component_config
return component.CONFIG_SCHEMA(config) # type: ignore
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
return self._compiled([], data)
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
cval = cvalue(key_path, value)
File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 215, in _run
return self._exec(self._compiled, value, path)
File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 339, in _exec
v = func(path, v)
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
return schema(data)
File "/usr/src/homeassistant/homeassistant/components/modbus/validators.py", line 236, in duplicate_modbus_validator
if hub[CONF_TYPE] == SERIAL:
KeyError: 'type'
2021-11-26 20:43:50 ERROR (MainThread) [homeassistant.setup] Setup failed for modbus: Invalid config.

This is my config:

modbus:
  - type: tcp
    host: 192.168.50.4 # use the IP address of your CCGX
    port: 502
    name: "victron"
    close_comm_on_error: true
    delay: 5
    timeout: 5
    sensors:
      - name: "Battery Monitor State" # 0=Initializing (Wait start);1=Initializing (before boot);2=Initializing (Before boot delay);3=Initializing (Wait boot);4=Initializing;5=Initializing (Measure battery voltage);6=Initializing (Calculate battery voltage);7=Initializing (Wait bus voltage);8=Initializing (Wait for lynx shunt);9=Running;10=Error (10);11=Unused (11);12=Shutdown;13=Slave updating;14=Standby;15=Going to run;16=Pre-charging
        scan_interval: 10
        slave: 245
        address: 1282

Hello, for me it was so that I entered address instead of register.
I don’t have a battery, so I don’t know about it, but just try without sensors and the rest and then look at the log again.
In the beginning, it only worked for me when I performed a cold start on the inverter.

I found the issue:
in my config.yaml the include line looked like this:
modbus: !include modbus.yaml

and my modbus.yaml started like this:
modbus:
after I deleted the first line of modbus.yaml, it was fine. Now I have new issue:
“This entity (‘sensor.battery_monitor_state’) does not have a unique ID, therefore”
Whats should I do? Am I missing an other parameter from the yaml?

- type: tcp
  host: 192.168.50.4
  port: 502
  name: "victron"
  sensors:
    - name: "Battery Monitor State"
      scan_interval: 10
      slave: 245
      address: 1282
1 Like