Just wanted to share a quick hardware solution that finally solved my Modbus nightmares. Like many of you, my HA server is in a rack, but my energy meter is locked in a metal breaker box in the garage.
I started with a cheap USB-to-RS485 dongle and a long wire. It was terrible. I had random disconnects, Linux port mapping issues (the classic /dev/ttyUSB0 changing on reboot), and massive EMI from the breakers causing CRC errors.
I eventually decided to ditch the USB route entirely and moved to a TCP bridging method.
I dropped a Valtoris serial-to-ethernet server directly into the panel next to the meter (honestly, any decent industrial Modbus TCP gateway like this or a Waveshare would work). It handles the serial polling locally and just outputs clean Modbus TCP over ethernet to my LAN switch.
Since HA natively supports Modbus TCP, you don't need any drivers or USB mapping. You just point it to the gateway's IP. Here is the YAML snippet in case anyone wants to replicate this setup:
```yaml
modbus:
- name: "TCP_Meter_Bridge"
type: tcp
host: 192.168.1.188 # Replace with your gateway's static IP
port: 502
sensors:
- name: "Main Power"
slave: 1 # Your RS485 meter ID
address: 30052 # Register address (check your manual)
input_type: input
device_class: power
state_class: measurement
My connection has been rock solid since I switched and not a single drop since. If you are having issues with your USB adapters constantly dropping off your HA instance, I highly recommend spending a little extra money and moving the physical layer to a dedicated TCP server.
If anyone needs help setting registers for certain meters let me know!