Modbus write with automation is slow

I have 55 data points which I read via Modbus TCP. And through automations (Service “Modbus: Write register”), I write about 35 data points. It went well until 2023.9.3, but with the update to 2023.10.3 it became extremely slow. Sometimes it takes more than 10 minutes until the register is written into the PLC. If I downgrade it works again quite quickly.

I had filed a bug report (Modbus write is very slow · Issue #102513 · home-assistant/core · GitHub) but Janiversen indicated that he did not think it was a bug. I just can’t figure out what he means and how I should solve it. Can someone help me on my way?

janiversen stated the following:
No, issues are for bug reports not support, please ask in one of the support forums. Apart from that I do not use automation.

You have probably been lucky before, because the integration was a lot slower.

We decided long time ago not to break a non-serialized write, because users was against it, so now users must ensure that the writes do not happen in parallel.

# MODBUS PRIVA:
  - name: hub1
    type: tcp
    host: 10.0.0.79
    port: 502
    
    delay: 0
    message_wait_milliseconds: 100
    retries: 3
    timeout: 5
    
    sensors:

      - name: Priva_TT_Buiten
        unit_of_measurement: °C
        state_class: measurement
        scan_interval: 60
        slave: 1
        address: 11
        input_type: input
        data_type: int16
        scale: 0.1
        offset: 0
        precision: 1

      - name: Priva_TT_Garage
        unit_of_measurement: °C
        state_class: measurement
        scan_interval: 300
        slave: 1
        address: 12
        input_type: input
        data_type: int16
        scale: 0.1
        offset: 0
        precision: 1

And this is one of the automations:

alias: MODBUS.900 - Tijdsduur (minuten) naar Priva
description: ""
trigger:
  - platform: time_pattern
    minutes: /2
condition: []
action:
  - service: modbus.write_register
    data:
      hub: hub1
      address: 900
      value: "{{ as_timestamp(now()) | timestamp_custom('%M') | int * 1 }}"
mode: queued
max: 3

And another one:

alias: MODBUS.1063 Hue motion toilet 1eV [temperatuur]
description: ""
trigger: []
condition: []
action:
  - service: modbus.write_register
    data:
      hub: hub1
      address: 1063
      value: "{{ states('sensor.hue_motion_sensor_1_temperature_4') | float * 10 }}"
mode: single

wich is triggered by this automation:

alias: TIMER.MODBUS - Write Hue metingen
description: ""
trigger:
  - platform: time_pattern
    minutes: /15
condition: []
action:
  - service: automation.trigger
    data:
      skip_condition: true
    target:
      entity_id:
        - automation.modbus_1023_hue_motion_buiten_temperatuur
        - automation.modbus_1023_hue_motion_gang_temperatuur
        - automation.modbus_1043_hue_motion_toilet_bg_temperatuur
        - automation.modbus_1023_hue_motion_trap_temperatuur
        - automation.modbus_1063_hue_motion_toilet_1ev_temperatuur
        - automation.1073_temp
        - automation.1083_temp
mode: single

And I got this log very often. I can’t see the register(s) wich are giving this error. Anybody know how to see that?

Logger: homeassistant.components.modbus.modbus
Source: components/modbus/modbus.py:401
Integration: Modbus ([documentation], [issues])
First occurred: 10:50:05 (830 occurrences)
Last logged: 20:38:23

* Pymodbus: hub1: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received)
* Pymodbus: hub1: Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response

I changed the automations to 1 automation, i’m still working in 2023.9.3

Anyone have an idea where I should look for it? So I already ensure that no write actions are performed at the same time, there is 1 second between the write actions. With 2023.9.3 it takes about 3 minutes to perform all writes. But I also can’t see why he gives the errors (more than 5,000 times now). I also don’t know if it gives errors on read or write actions.

This is the automation (35 modbus write actions):

alias: MODBUS.WRITE Registers
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition: []
action:
  - service: modbus.write_register
    data:
      hub: hub1
      address: 900
      value: "{{ as_timestamp(now()) | timestamp_custom('%M') | int * 1 }}"
    alias: "Service \"Modbus: Write register 900 (pulstrein)\""
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - if:
      - condition: device
        type: is_on
        device_id: b656bce1773aea267a7cd468f2015f95
        entity_id: a3e59008a7f031b32e8999e50867f07d
        domain: light
    then:
      - service: modbus.write_coil
        data:
          hub: hub1
          address: 1011
          state: 1
    else:
      - service: modbus.write_coil
        data:
          hub: hub1
          address: 1011
          state: 0
        alias: "Service \"Modbus: Write register 1011 (Lamp eettafel rechts)\""
    alias: "VOORWAARDELIJK: Modbus: Write 1011 (Lamp eettafel rechts)"
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: modbus.write_register
    data:
      hub: hub1
      address: 1023
      value: >-
        {{ states('sensor.hue_outdoor_motion_sensor_temperature') | float * 10
        }}
    alias: "Service \"Modbus: Write register 1023 (Sensor Hue buiten TT)\""
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: modbus.write_register
    data:
      hub: hub1
      address: 1033
      value: "{{ states('sensor.hue_motion_sensor_gang_temperature') | float * 10 }}"
    alias: "Service \"Modbus: Write register 1033 (Sensor Hue gang TT)\""
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - if:
      - condition: device
        type: is_on
        device_id: 579aae427a6c09e9022f9b766d6a3005
        entity_id: ae760788ed62e4faaeefb3df3d1c8f42
        domain: light
    then:
      - service: modbus.write_coil
        data:
          hub: hub1
          state: 1
          address: 1041
    else:
      - service: modbus.write_coil
        data:
          hub: hub1
          state: 0
          address: 1041
        alias: "Service \"Modbus: Write register 1041 (Lamp toilet BG)\""
    alias: "VOORWAARDELIJK: Modbus: Write 1041 (Lamp toilet BG)"

And still the error count is increasing:

Logger: homeassistant.components.modbus.modbus
Source: components/modbus/modbus.py:401
Integration: Modbus ([documentation], [issues])
First occurred: 22 oktober 2023 om 10:50:05 (5471 occurrences)
Last logged: 10:35:49

* Pymodbus: hub1: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received)
* Pymodbus: hub1: Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response

I found the 2 problems i had.

Problem 1:
I had multiple automations that were on a 5 minute trigger. As a result, they wanted to do a writing campaign at the same time. I solved this by creating 1 automation and placing all write actions conditionally (entity must be available) one after the other so that they are written one after the other.

Problem 2:
I used address 1 to read modbus TCP data. But I had not entered it when writing. The PLC did receive the write actions, but (presumably) did not return the correct answer to Home Assistant, which caused the errors.

In summary:
Now the script runs in a short time. For the adjustments with 2023.9.3 it took him 3 minutes. Now with the adjustments in 2023.10.3 in a few seconds.