Home / Knowledge Base / Integration Hub / Home Assistant
Smart Home & OT Integration

Home Assistant: Modbus RTU to MQTT Auto-Discovery

Decouple physical RS485 wiring from your Home Assistant server. Push clean, parsed data from industrial inverters and meters directly into HA using native MQTT auto-discovery JSON payloads.

1. The Limitations of Direct USB-RS485 Dongles

The standard way of integrating industrial hardware (e.g. Growatt inverters or Eastron energy meters) into Home Assistant is to plug a USB to RS485 adapter into the machine running HA (e.g. Raspberry Pi or NUC), and defining the modbus: platform in the configuration.yaml file.

This approach introduces two critical points of failure:

  • Physical Distance & Ground Loops: Industrial equipment is usually not located near the HA server. Long RS485 cables throughout a residential or light commercial building will cause voltage drops, ground loops, and CRC errors.
  • OS-Level Disconnects: In Linux environments it is common to reset USB ports experiencing electromagnetic interference (EMI), causing the /dev/ttyUSB0 path to drop and all data acquisition to stop indefinitely until reboot.

2. The MQTT Edge-Decoupled Solution

Isolating the physical OT network from the IT server resolves these instabilities. By deploying an Edge Gateway locally at the inverter or meter panel, the RS485 cable run is kept under 1 meter.

The Gateway performs the Modbus polling natively and transmits the parsed data to Home Assistant’s Mosquitto broker over Ethernet or Wi-Fi via MQTT.

Eliminating YAML Maintenance

Rather than having to write complicated YAML templates in HA to parse the data coming from a generic MQTT state topic, you can format the Gateway’s output to use Home Assistant’s MQTT Auto-Discovery. The devices and their entities will populate in the HA Devices dashboard.

3. Structuring the Auto-Discovery Payload

🔓 Open-Source HA Blueprint

For Home Assistant to automatically recognize a sensor, the Edge Gateway must publish a specific JSON configuration payload to the discovery topic structure: <discovery_prefix>/<component>/<node_id>/<object_id>/config. Feel free to copy and adapt these payloads for your own projects.

Phase A: Publishing the Configuration Payload (Retained = True)

Topic: homeassistant/sensor/inverter_01/active_power/config

{ “name”: “Inverter Active Power”, “state_topic”: “valtoris/inverter_01/state”, “value_template”: “{{ value_json.power_kw }}”, “unit_of_measurement”: “kW”, “device_class”: “power”, “state_class”: “measurement”, “unique_id”: “inv01_power_001”, “device”: { “identifiers”: [“inv01_hardware”], “name”: “Deye Hybrid Inverter”, “manufacturer”: “Deye” } }

Phase B: Publishing the State Payload (Continuous Polling)

Topic: valtoris/inverter_01/state

{ “power_kw”: 5.42, “grid_voltage”: 230.1 }

4. Hardware Implementation Options

To execute this architecture, the edge device must support native Modbus polling, data normalization (handling Float32 byte-swapping), and custom MQTT payload templating.

❌ DIY: ESP32 & ESPHome

A popular hobbyist route is wiring a MAX485 chip to an ESP32 flashed with ESPHome.

  • The Risk: Generic ESP32 boards lack Galvanic Isolation. A voltage spike or common-mode transient from a large inverter will instantly fry the microcontroller.
  • The Hassle: Wi-Fi drops require manual reboots, and you must write and compile custom C++/YAML logic for every single Modbus register mapping.

✅ Valtoris Edge Gateways

Dedicated DIN-rail protocol bridges designed for continuous industrial environments.

  • Built to Survive: The board has built-in 2500V isolation for protection. Hardware watchdogs to automatically recover lost MQTT connections.
  • Zero-Code JSON: Simply copy and paste the HA Auto-Discovery payload into the Web UI. The gateway natively decodes IEEE 754 and automatically pushes standard JSON.

Need offline documentation?

Download the complete YAML and JSON payload blueprint for Home Assistant Integrations.

Download PDF

Eliminate YAML Maintenance and USB Dropouts

No more debugging custom ESP32 scripts and flaky serial connections at the OS level. Valtoris Edge Gateways have native MQTT Auto-Discovery formatting that allows legacy Modbus hardware to be seamlessly integrated into Home Assistant.