This guide will help you quickly set up and use modbus2mqtt.
Before you begin, make sure you have:
- A Modbus device (RTU or TCP)
- MQTT broker (e.g., Mosquitto)
- For Modbus RTU: USB-to-RS485 adapter
Open your browser and navigate to:
http://localhost:3000
(Replace localhost with your server's IP if running remotely)
- Go to Settings → MQTT Configuration
- Enter your MQTT broker details:
- URL:
mqtt://your-broker-ip:1883 - Username: (if authentication is enabled)
- Password: (if authentication is enabled)
- URL:
- Click Test Connection
- Click Save
A "bus" represents a physical connection to your Modbus devices.
- Go to Busses → Add Bus
- Select RTU
- Configure:
- Serial Port:
/dev/ttyUSB0(Linux) orCOM3(Windows) - Baud Rate:
9600(check your device manual) - Data Bits:
8 - Parity:
none - Stop Bits:
1 - Timeout:
1000ms
- Serial Port:
- Click Save
- Go to Busses → Add Bus
- Select TCP
- Configure:
- Host: IP address of your Modbus TCP device
- Port:
502(default Modbus TCP port) - Timeout:
1000ms
- Click Save
- Select your bus from the list
- Click Scan for Devices (if supported)
- Or manually add: Click Add Device
- Enter:
- Slave ID: The Modbus address of your device (e.g.,
1) - Poll Interval: How often to read data (e.g.,
5000ms)
- Slave ID: The Modbus address of your device (e.g.,
- Click Save
A specification defines what data to read from your device.
- Click on your device
- Click Select Specification
- Browse available specifications
- Search for your device model
- Select and click Apply
- Click on your device
- Click Create New Specification
- Fill in device information:
- Name: Device model name
- Manufacturer: Device manufacturer
- Add entities (data points):
- Click Add Entity
- Configure:
- Name: Descriptive name (e.g., "Temperature")
- Modbus Address: Register address
- Register Type: Holding Register, Input Register, etc.
- Data Type: Int16, UInt16, Float32, etc.
- Converter: How to convert the value
- Unit: Unit of measurement
- Click Save
- Go to Devices → Select your device
- View the Entities tab
- Check that values are being read correctly
- Values should update according to your poll interval
If you're using Home Assistant, modbus2mqtt automatically creates MQTT discovery messages.
- Go to Settings → Devices & Services
- Add MQTT integration (if not already added)
- Configure with the same broker details
- Your modbus2mqtt devices should appear automatically
- Go to Settings → Devices & Services → MQTT
- You should see your devices listed
- Click on a device to view all entities
- Go to your Home Assistant dashboard
- Click Edit Dashboard
- Click Add Card
- Select entity type (e.g., Sensor)
- Select entities from your Modbus device
- Customize the card
- Click Save
Data is automatically polled at the interval you configured. You can:
- View current values in the Web UI
- Subscribe to MQTT topics:
modbus2mqtt/<device>/<entity> - Use Home Assistant entities
For writable entities:
- In the Web UI, click on the entity
- Enter the new value
- Click Write
Or publish to MQTT:
Topic: modbus2mqtt/<device>/<entity>/set
Payload: <value>
- Dashboard: View all devices at a glance
- Logs: Check for connection issues or errors
- MQTT: Use an MQTT client (e.g., MQTT Explorer) to monitor messages
- Check bus connection:
- For RTU: Verify serial port and wiring
- For TCP: Ping the device IP
- Verify slave ID is correct
- Check Modbus address in specification
- Increase timeout if needed
- Check device manual for correct settings
- Verify broker is running
- Check broker IP and port
- Test with MQTT client (e.g.,
mosquitto_pub) - Verify authentication credentials
- Check firewall settings
- Verify MQTT integration is configured
- Check MQTT broker logs
- Restart Home Assistant
- Check discovery topic:
homeassistant/sensor/modbus2mqtt/+/config
Add your user to the dialout group:
sudo usermod -a -G dialout $USERLog out and back in for changes to take effect.
- Check the FAQ
- Search GitHub Issues
- Ask in GitHub Discussions