home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.03k stars 28.27k forks source link

Modbus issue - SMA inverter #116683

Closed SonnyBBQ closed 1 week ago

SonnyBBQ commented 2 weeks ago

I had referenced this in issue #116289 as well, but since that was closed, opening as a new issue.

The Modbus connection to SMA no longer works since upgrading to 2024.4. I'm currently on 2024.5 and the issue persists.

What version of Home Assistant Core has the issue? 2024.4 onwards

What was the last working version of Home Assistant Core? 2024.3.3

What type of installation are you running? Home Assistant OS

Integration causing the issue Modbus

Link to integration documentation on our website https://www.home-assistant.io/integrations/modbus/

Diagnostics information No response

Example YAML snippet

modbus:
  - name: SMA
    type: tcp
    host: 192.168.1.223 #fixed ip in SMA  192.168.1.223
    port: 502
    sensors:
      - name: SMA_Power_AC
        unit_of_measurement: W
        slave: 3
        address: 30775
        data_type: int32
      - name: PV Daily Yield
        unit_of_measurement: kWh
        slave: 3
        address: 30517
        scale: 0.001
        precision: 3
        data_type: uint64
      - name: PV Total Production
        unit_of_measurement: MWh
        slave: 3
        address: 30513
        scale: 0.000001
        precision: 3
        data_type: uint64
      - name: Grid Voltage
        unit_of_measurement: V
        slave: 3
        address: 30783
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: Grid frequency
        unit_of_measurement: Hz
        slave: 3
        address: 30803
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: SMA_temp
        unit_of_measurement: °C
        slave: 3
        address: 30953
        scale: 0.1
        precision: 1
        data_type: int32
      - name: SMA_status
        slave: 3
        address: 30201
        data_type: uint32
      - name: SMA_grid
        slave: 3
        address: 30217
        data_type: uint32
      - name: Insulation
        slave: 3
        address: 30225
        scale: 0.001
        unit_of_measurement: kOhms
        data_type: uint32
      - name: SMA_Residual_current
        slave: 3
        address: 31247
        scale: 1
        unit_of_measurement: mA
        data_type: int32
      - name: Apparent Power
        unit_of_measurement: VA
        slave: 3
        address: 30813
        scale: 1
        precision: 0
        data_type: int32
      - name: Reactive Power
        unit_of_measurement: VAr
        slave: 3
        address: 30805
        scale: 1
        precision: 0
        data_type: int32

Anything in the logs that might be useful for us?

2024-04-30 09:02:26.711 WARNING (MainThread) [pymodbus.logging] Failed to connect 
2024-04-30 09:02:26.711 INFO (MainThread) [homeassistant.components.modbus.modbus] modbus SMA communication open
2024-04-30 09:02:27.372 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30775 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.372 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30517 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.373 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30513 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.373 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30783 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.381 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30803 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.381 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30953 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.381 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30201 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.381 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30217 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.381 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30225 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.382 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 31247 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.382 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30813 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]
2024-04-30 09:02:27.382 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30805 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.223:502]

ValueError: Sensor sensor.modbus_sma_pv_power has device class 'None', state class 'None' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2024-04-30 09:02:53.982 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aac720>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_sma_pv_apparent_power has device class 'None', state class 'None' unit 'VA' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2024-04-30 09:02:53.990 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aac9a0>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_sma_pv_reactive_power has device class 'None', state class 'None' unit 'VAr' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2024-04-30 09:02:53.996 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aacc20>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_sma_pv_residual has device class 'None', state class 'None' unit 'mA' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2024-04-30 09:02:54.003 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aacea0>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_sma_temperature has device class 'None', state class 'None' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2024-04-30 09:02:54.008 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aad120>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'Not Measured'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_grid_frequency has device class 'None', state class 'None' unit 'Hz' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'Not Measured' (<class 'str'>)
2024-04-30 09:02:54.013 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f9b85aad440>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'Not Measured'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 41, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 491, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1075, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1261, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 439, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.modbus_grid_voltage has device class 'None', state class 'None' unit 'V' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'Not Measured' (<class 'str'>)

Additional information Resetting the inverter will make the connection work for a limited time only. Couple hours at most.

Originally posted by @SonnyBBQ in https://github.com/home-assistant/core/issues/116289#issuecomment-2084569884

Pikantje commented 1 week ago

Same issue here

dlivi74 commented 1 week ago

Same issue here, I have to reset the inverter to make the modbus connection working for a limited time.

SonnyBBQ commented 1 week ago

Is anyone able to label this issue?

Adding the link didn't work:

Link to integration documentation on our website https://www.home-assistant.io/integrations/modbus/

ebbenberg commented 1 week ago

I tried your code on HA 2024.5.1 but it all works fine. I know if a SMA inverter is too busy it can block traffic (maybe you also readout with webconnect?)

Maybe you can try to add delays to the modbus command:

modbus:
  - name: SMA
    type: tcp 
    host: 192.168.1.223 #fixed ip in SMA  192.168.1.223
    port: 502 
    delay: 5
    message_wait_milliseconds: 600
    timeout: 5
SonnyBBQ commented 1 week ago

Thanks for thinking along. I did already try the delay and eventually it will stop working as well (I can do that again and add the logs, but it didn't show anything different). Even with the set-up shared in the original post, it works fine, but only for a limited time.
My modbus set-up has been running for years without issue. Nothing was changed on the inverter side. So something else must have caused the issue. And it happened when updating to 2024.4.

ebbenberg commented 1 week ago

Might want to try with node-red to see if the SMA is not the problem? https://gathering.tweakers.net/forum/list_message/77883380#77883380

https://github.com/fonske/SMA_inverter_logging/tree/main/Node-red_flows

home-assistant[bot] commented 1 week ago

Hey there @janiversen, mind taking a look at this issue as it has been labeled with an integration (modbus) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `modbus` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign modbus` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


modbus documentation modbus source (message by IssueLinks)

janiversen commented 1 week ago

This is NOT a bug, you are using a template, but have forgotten that the sensor value can be "unavailable" and thus not possible to convert to a float. The modbus integration (like most other integrations) set a sensor to a value when available but to "unavailable" when not available, actually quite logical.

Please correct your template sensor, to respond correctly if the value of the sensor is "unavailable".

I do however have a feeling that a number of the "@metoo" are actually referring to a different problem, if that is the case they should open an issue with a proper debug.log as pr modbus integration (remember to shorten the log, to show a couple of minutes before and after the problem).

SonnyBBQ commented 6 days ago

Hi @janiversen you are right, I should have shortened my debug log indeed. Fully aware that my template sensors can be unavailable. That's not the problem for me and is expected. And I have designed my dashboard around that with conditional cards ... but that's offtopic.

The problem is that the modbus connection to my SMA inverter loses connection after a few hours. This started happening after updating to 2024.4. I had been using the Modbus integration (not the SMA integration) in it's current configuration for years and it has been super stable. So I would love to get this back up and running.

Per @ebbenberg comments. I am not using other connections to the SMA (no webconnect) and have already tried the delays, including the above proposed delays, which are way longer than suggested by SMA.
Also nothing changed on the SMA site, no firmware update or anything.

I have restarted both the inverter and HA again and will add a new log when the issue arises in a few hours. Hopefully that will give you the necessary to investigate.

SonnyBBQ commented 2 days ago

Hi @janiversen , so the Modbus connection worked since I had activated it 4 days ago and stopped again yesterday.

This is a snippet of the log - hope it helps:

2024-05-15 13:21:18.963 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.1.223:502.
2024-05-15 13:21:18.963 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-05-15 13:21:18.970 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-05-15 13:21:18.970 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:18.970 INFO (MainThread) [homeassistant.components.modbus.modbus] modbus SMA communication open

2024-05-15 13:21:36.648 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-05-15 13:21:36.648 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:36.648 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x3 0x78 0x37 0x0 0x2

2024-05-15 13:21:36.803 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x1 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x1 0x96 old_data:  addr=None
2024-05-15 13:21:36.803 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x1 0x96
2024-05-15 13:21:36.803 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-05-15 13:21:36.803 DEBUG (MainThread) [pymodbus.logging] Getting transaction 1
2024-05-15 13:21:36.804 DEBUG (MainThread) [pymodbus.logging] Frame check, no more data!

2024-05-15 13:21:37.416 DEBUG (MainThread) [pymodbus.logging] Adding transaction 2
2024-05-15 13:21:37.416 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:37.416 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x2 0x0 0x0 0x0 0x6 0x3 0x3 0x77 0x35 0x0 0x4
2024-05-15 13:21:37.553 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x2 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x0 0x0 0x10 old_data:  addr=None
2024-05-15 13:21:37.553 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x2 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x0 0x0 0x10
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] Frame check failed, missing part of message len 16, MBAP len 11 !!
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] recv: 0x13 old_data:  addr=None
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x2 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x0 0x0 0x10 0x13
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] Getting transaction 2
2024-05-15 13:21:37.554 DEBUG (MainThread) [pymodbus.logging] Frame check, no more data!
2024-05-15 13:21:38.157 DEBUG (MainThread) [pymodbus.logging] Adding transaction 3
2024-05-15 13:21:38.157 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:38.157 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0x0 0x0 0x6 0x3 0x3 0x77 0x31 0x0 0x4
2024-05-15 13:21:38.298 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x3 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x1 0x5e 0x85 old_data:  addr=None
2024-05-15 13:21:38.298 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x3 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x1 0x5e 0x85
2024-05-15 13:21:38.298 DEBUG (MainThread) [pymodbus.logging] Frame check failed, missing part of message len 16, MBAP len 11 !!
2024-05-15 13:21:38.299 DEBUG (MainThread) [pymodbus.logging] recv: 0x45 old_data:  addr=None
2024-05-15 13:21:38.299 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x3 0x0 0x0 0x0 0xb 0x3 0x3 0x8 0x0 0x0 0x0 0x0 0x1 0x5e 0x85 0x45
2024-05-15 13:21:38.299 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-05-15 13:21:38.299 DEBUG (MainThread) [pymodbus.logging] Getting transaction 3
2024-05-15 13:21:38.299 DEBUG (MainThread) [pymodbus.logging] Frame check, no more data!
2024-05-15 13:21:38.910 DEBUG (MainThread) [pymodbus.logging] Adding transaction 4
2024-05-15 13:21:38.910 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:38.911 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x4 0x0 0x0 0x0 0x6 0x3 0x3 0x78 0x3f 0x0 0x2
2024-05-15 13:21:39.053 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x4 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x5a old_data:  addr=None
2024-05-15 13:21:39.053 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x4 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x5a
2024-05-15 13:21:39.054 DEBUG (MainThread) [pymodbus.logging] Frame check failed, missing part of message len 12, MBAP len 7 !!
2024-05-15 13:21:39.055 DEBUG (MainThread) [pymodbus.logging] recv: 0xda old_data:  addr=None
2024-05-15 13:21:39.055 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0x4 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x5a 0xda
2024-05-15 13:21:39.055 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-05-15 13:21:39.055 DEBUG (MainThread) [pymodbus.logging] Getting transaction 4
2024-05-15 13:21:39.055 DEBUG (MainThread) [pymodbus.logging] Frame check, no more data!
2024-05-15 13:21:39.658 DEBUG (MainThread) [pymodbus.logging] Adding transaction 5
2024-05-15 13:21:39.658 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-05-15 13:21:39.658 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x5 0x0 0x0 0x0 0x6 0x3 0x3 0x78 0x53 0x0 0x2
2024-05-15 13:21:39.798 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x5 0x0 0x0 0x0 0x7 0x3 0x3 0x4 0x0 0x0 0x13 old_data:  addr=None

2024-05-15 18:28:00.689 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to Server not responding
2024-05-15 18:28:00.690 DEBUG (MainThread) [pymodbus.logging] callback_disconnected called: Server not responding
2024-05-15 18:28:00.690 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: SMA: Error: device: 3 address: 30775 -> Modbus Error: [Input/Output] ERROR: No response received after 3 retries
2024-05-15 18:28:00.693 DEBUG (MainThread) [pymodbus.logging] Wait comm 100.0 ms before reconnecting.
2024-05-15 18:28:00.794 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.1.223:502.
2024-05-15 18:28:00.794 DEBUG (MainThread) [pymodbus.logging] Connecting comm
janiversen commented 2 days ago

Your device is not responding, last entry shows modbus trying to reconnect, this have nothing to do with the modbus integration

SonnyBBQ commented 2 days ago

But what else could be causing this? As said, I have been running this for years without issue. These problems happened exactly at the same time as the upgrade to Home Assistant Core 2024.4. I realize coincidences do exist, but there were no other changes to the hardware or firmware of the SMA, neither to my network. Could it be a change in the Modbus communication which makes the SMA block/drop the connection? ANy other thoughts re troubleshooting this?

janiversen commented 2 days ago

This is a channel for reporting bug, not making support, please use the user forums.

florie1706 commented 2 days ago

It is a bug for me. Never happened before. Even though the debug log does not state anything when connected there must be something regarding establishing the connection.