core: Modbus issue - Working YAML stopped working since 25.2.0

The problem

I am using HA Modbus via Ethernet-RS485 adapter USR-TCP232-304. Everything was stable working until update on end of January 2025. When I use a switch I get message “Die Aktion light/turn_on konnte nicht ausgeführt werden. object of type ‘int’ has no len()”. Hardware is checked and fine. Reading values is also fine.

Logs show Exception in homeassistant.components.websocket_api.http.connection.

What version of Home Assistant Core has the issue?

core-2025.2.3

What was the last working version of Home Assistant Core?

core-2025.1.x

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

2025-02-13 11:09:07.197 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547958206624] Unexpected exception Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 245, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …<7 lines>… ) ^ File “/usr/src/homeassistant/homeassistant/core.py”, line 2794, in async_call response_data = await coro ^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/core.py”, line 2837, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/helpers/service.py”, line 1007, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ hass, entity, func, data, call.context ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File “/usr/src/homeassistant/homeassistant/helpers/service.py”, line 1079, in _handle_entity_call result = await task ^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/components/light/init.py”, line 644, in async_handle_light_on_service await light.async_turn_on(**filter_turn_on_params(light, params)) File “/usr/src/homeassistant/homeassistant/components/modbus/light.py”, line 40, in async_turn_on await self.async_turn(self.command_on) File “/usr/src/homeassistant/homeassistant/components/modbus/entity.py”, line 359, in async_turn result = await self._hub.async_pb_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ self._slave, self._address, command, self._write_type ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File “/usr/src/homeassistant/homeassistant/components/modbus/modbus.py”, line 424, in async_pb_call result = await self.low_level_pb_call(unit, address, value, use_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/components/modbus/modbus.py”, line 389, in low_level_pb_call result: ModbusPDU = await entry.func(address, **kwargs) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File “/usr/local/lib/python3.13/site-packages/pymodbus/client/mixin.py”, line 514, in write_registers return self.execute(no_response_expected, pdu_reg.WriteMultipleRegistersRequest(address=address, registers=values,dev_id=slave)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/local/lib/python3.13/site-packages/pymodbus/pdu/pdu.py”, line 36, in init self.count: int = count or len(self.registers) ~~~^^^^^^^^^^^^^^^^ TypeError: object of type ‘int’ has no len()

Example YAML snippet

modbus:
  - name: gateway1
    type: rtuovertcp
    host: 192.168.97.69
    port: 8234
    delay: 3
    timeout: 1
    #retry_on_empty: true
    message_wait_milliseconds: 30
    sensors:
        !include modbus_9600.yaml
        
    lights:
        -   name: "SG04LP3 - Battery Switch" 
            unique_id: "sg04lp3_battery_switch"
            slave: 1
            address: 80
            #count: 1
            write_type: holdings
            #data_type: int16
            command_on: 1
            command_off: 0

Anything in the logs that might be useful for us?

2025-02-13 11:09:07.197 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547958206624] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2794, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2837, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
        hass, entity, func, data, call.context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 644, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/modbus/light.py", line 40, in async_turn_on
    await self.async_turn(self.command_on)
  File "/usr/src/homeassistant/homeassistant/components/modbus/entity.py", line 359, in async_turn
    result = await self._hub.async_pb_call(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._slave, self._address, command, self._write_type
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 424, in async_pb_call
    result = await self.low_level_pb_call(unit, address, value, use_call)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 389, in low_level_pb_call
    result: ModbusPDU = await entry.func(address, **kwargs)
                              ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pymodbus/client/mixin.py", line 514, in write_registers
    return self.execute(no_response_expected, pdu_reg.WriteMultipleRegistersRequest(address=address, registers=values,dev_id=slave))
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pymodbus/pdu/pdu.py", line 36, in __init__
    self.count: int = count or len(self.registers)
                               ~~~^^^^^^^^^^^^^^^^
TypeError: object of type 'int' has no len()

Additional information

I did some tests with HA core versions and figured out: 2025.1.2 okay 2025.1.4 okay 2025.2.0 not okay 2025.2.1 not okay 2025.2.3 not okay 2025.2.4 not okay

So there must happended some breaking change with version 2025.2.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Which version do you see in the modbus details?

Image

For now I updated to 2025.2.4 and create custom component Modbus, where I put Modbus from version 2025.1.4 and until somebody will solve the problem, I will use this setup.

How did you do this? Could you post your code for this step?

This is a reasonable advice:

  1. Download the HA core release 2025.1.4
  2. Take the modbus folder from /homeassistant/components/modbus of the release and copy it to /config/custom_components of your HA
  3. Put a version tag to “manifest.json”
  4. Restart HA. It will find a custom integration as a substitution for the core version.

https://community.home-assistant.io/t/how-to-create-a-custom-component-from-one-removed-from-ha-itself/410602

For now I updated to 2025.2.4 and create custom component Modbus, where I put Modbus from version 2025.1.4 and until somebody will solve the problem, I will use this setup.

How did you do this? Could you post your code for this step?

Hi, same problem for me. For now I updated to 2025.2.4 and create custom component Modbus, where I put Modbus from version 2025.1.4 and until somebody will solve the problem, I will use this setup. FYI: I tried actions in developer tools and send this command:

action: modbus.write_register data: hub: planet address: 9 slave: 7 value: - 2

and action was successfully completed.

The action, which I mentioned above, I have presented i configuration.yaml this way:

- name: light_workroom_led_switch_mb
  slave: 7
  address: 9
  command_on: "3"
  command_off: "1"
  write_type: holdings
  verify:
    delay: 5

and this way of writing will cause an error TypeError: object of type ‘int’ has no len().

Johnny