Hello there,
Writing custom Lua scripts is unfortunately out of our scope here, so we’re not able to help you out much. However, recently, I’ve had a user that had a very similar issue to yours, and they have shared their script, which might help you get started: RUTX11 Modbus MQTT - #9 by jsampaio
Regards,
M.