For complex Modbus integration with many discrete inputs standard binary_sensor refresh time takes more than 1 minute when number of individual binary sensor is higher than 50. It slows down entire bus as pymodbus calls are not streamed.
In order to optimize it I would like to have a sensor with count parameter which supports discrete input type (modbus function code 2). Today sensor supports holding register (modbus function code 3) or input register (modbus function code 4).
Standard pymodbus supports count of discrete input and it could be integrated natively without big modification using custom data type and structure “>b” which delimits discrete inputs in the same way as holding or input registers.
Amended code of sensor.py attached could be found here https://github.com/kurkowskim/modbus/blob/293c24a50ffb0d3339a91c01ee3bb87e02328183/sensor, please review and consider updating it in HA core
configuration.yaml setup for sensor reading multiple inputs could look like that:
- platform: modbus
scan_interval: 5
registers:
- name: heat_pump_all_registers
hub: hub1
slave: 4
register_type: holding
register: 0
count: 60
data_type: custom
structure: ">60h"
- name: heat_pump_all_discrete_inputs
hub: hub1
slave: 4
register_type: discrete_input
register: 0
count: 16
data_type: custom
structure: ">16b"
Hi. would you please share your custom_components sources?