Reading 3 renogy batteries and a charge controller using modbus platform

I want to read in a bunch of registers for my electrical system: three batteries and one charge controller. I have this all working with AppDaemon and an USB serial doodad, but I want to make it “wireless” using a nifty little TTGO T-CAN485 board. The yaml seems straightforward but oh-so-tedious repeating the same dozen items for each address.

Is there an example of lambda code that I can start with illustrating a modbus read and maybe creating subroutines (class header?)? I have searched around a bit and am not coming up with anything obvious.

Maybe a list of sensors, no refresh rate and an interval that calls the subroutines with the address (which can be tacked onto the “id” to disambiguate?) and forces a read? Is this even possible?

Ok, I have done this, but only in yaml: I created some include files with the basics, then included them under packages with some variable substitution. All great.

Now, I want to measure how long it takes to read all my peripherals and report that, either as a sensor or a log output (don’t need to do this all the time).

How does one go about doing something like this? Is it possible? I tried using “runtime_stats” component, but it didn’t really report anything useful (AFAICT) Just total time in the underlying components: modbus & modbus_controller, not the actual time in the transaction sequences which should be ~50-100 ms for each controller every 10 seconds (~40 bytes data @ 9600 in three transaction).

Thanks.

[06:21:16.350][I][runtime_stats:031]: Period stats (last 60000ms):
[06:21:16.366][I][runtime_stats:050]:   wifi: count=6103, avg=0.67ms, max=1ms, total=4085ms
[06:21:16.371][I][runtime_stats:050]:   light: count=6103, avg=0.08ms, max=1ms, total=488ms
[06:21:16.372][I][runtime_stats:050]:   modbus_controller: count=6109, avg=0.06ms, max=11ms, total=373ms
[06:21:16.382][I][runtime_stats:050]:   modbus_controller: count=6109, avg=0.04ms, max=9ms, total=245ms
[06:21:16.386][I][runtime_stats:050]:   modbus_controller: count=6109, avg=0.04ms, max=9ms, total=242ms
[06:21:16.392][I][runtime_stats:050]:   modbus_controller: count=6109, avg=0.04ms, max=9ms, total=239ms
[06:21:16.400][I][runtime_stats:050]:   modbus: count=6103, avg=0.03ms, max=1ms, total=199ms
[06:21:16.404][I][runtime_stats:050]:   api: count=6103, avg=0.02ms, max=3ms, total=117ms
[06:21:16.406][I][runtime_stats:050]:   web_server: count=6109, avg=0.02ms, max=3ms, total=103ms
[06:21:16.478][I][runtime_stats:050]:   esphome.ota: count=6103, avg=0.01ms, max=1ms, total=32ms
[06:21:16.480][I][runtime_stats:050]:   uptime.text_sensor: count=12, avg=1.83ms, max=3ms, total=22ms
[06:21:16.484][I][runtime_stats:050]:   safe_mode: count=6027, avg=0.00ms, max=13ms, total=21ms
[06:21:16.487][I][runtime_stats:050]:   wifi_signal.sensor: count=1, avg=1.00ms, max=1ms, total=1ms
[06:21:16.493][I][runtime_stats:050]:   preferences: count=1, avg=0.00ms, max=0ms, total=0ms