OK. Been running a modified version of the modbus sensor integration. “No response from hub” warnings have fallen from one or more per hour down to around five per week… The attached diff should be applied to the modbus sensor integration, and a framer_delay added to the config.
modbus:
name: hub1
type: serial
method: rtu
port: /dev/ttyUSB0
baudrate: 9600
stopbits: 1
bytesize: 8
parity: N
timeout: 10
- sensor:
- platform: modbus
scan_interval: 30
registers:
- name: "Water Tank"
hub: hub1
slave: 32
framer_delay: 0.4
register: 0
register_type: holding
--- sensor.py 2019-05-16 12:02:50.000000000 +0100
+++ /tmp/modbus/sensor.py 2019-12-04 11:09:22.313533342 +0000
@@ -23,6 +23,7 @@
CONF_REGISTERS = 'registers'
CONF_REVERSE_ORDER = 'reverse_order'
CONF_SCALE = 'scale'
+CONF_FRAMER_DELAY = "framer_delay"
DATA_TYPE_CUSTOM = 'custom'
DATA_TYPE_FLOAT = 'float'
@@ -50,6 +51,9 @@
vol.Optional(CONF_SLAVE): cv.positive_int,
vol.Optional(CONF_STRUCTURE): cv.string,
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
+ vol.Optional(CONF_FRAMER_DELAY, default=0): vol.All(
+ vol.Coerce(float), vol.Range(min=0, max=0.75)
+ )
}]
})
@@ -96,7 +100,7 @@
register.get(CONF_UNIT_OF_MEASUREMENT), register.get(CONF_COUNT),
register.get(CONF_REVERSE_ORDER), register.get(CONF_SCALE),
register.get(CONF_OFFSET), structure,
- register.get(CONF_PRECISION)))
+ register.get(CONF_PRECISION), register.get(CONF_FRAMER_DELAY)))
if not sensors:
return False
@@ -108,7 +112,7 @@
def __init__(self, hub, name, slave, register, register_type,
unit_of_measurement, count, reverse_order, scale, offset,
- structure, precision):
+ structure, precision, delay):
"""Initialize the modbus register sensor."""
self._hub = hub
self._name = name
@@ -124,6 +128,9 @@
self._structure = structure
self._value = None
+ if delay > self._hub._client.silent_interval:
+ self._hub._client.silent_interval = delay
+
async def async_added_to_hass(self):
"""Handle entity which will be added."""
state = await self.async_get_last_state()