Introduction: MODBUS-TCP ESPHOME/mqtt Gateway

Simple ModbusTCP to Esphome/Mqtt gateway

Supplies

ESP32 board

EBYTE NT1

https://www.aliexpress.com/item/1005003882507376.html

EBYTE V5.3 config tool

https://www.cdebyte.com/pdf-down.aspx?id=2081

Step 1: Starting NT1

First, connect the EBYTE NT1 to the router with a LAN cable and give it 3.3v power

Then run the EBYTE config tool to search for the device

Step 2: Config NT1 for Modbus TCP to Serial

What needs to be changed in the tool...

Network parameters:

Network mode :TCP client

Remote IP -> your modbusTCP device adress

Remote port -> your modbusTCP device port

Modbus parameters:

Modbus gateway : Simple

ModbusTCP to RTU : Enable

Step 3: TESTING

To test the connection, I recommend first trying the USB-serial connection and the ModbusPoll program. Then you can see at which addresses the data is located

https://www.modbustools.com/modbus_poll.html

Step 4: ESPHOME Config

Wiring:

NT1 RX to esp32 pin18

NT1 TX to esp32 pin19

First of all, you have to check in the manual of your ModbusTCP device where the data is located either "holding" or "read" registers. And with the ModbusPoll software, you can find out the data address .


ESPHOME CODE:

captive_portal:
   
uart:
  - id: uart_1
    tx_pin: GPIO18
    rx_pin: GPIO19
    baud_rate: 115200

modbus:
  id: modbus1

modbus_controller:
- id: modbus_device
  address: 0x1   ## address of the Modbus slave device on the bus
  modbus_id: modbus1
  setup_priority: -10


sensor:

- platform: modbus_controller
  name: "Oxyquard_1_O2"
  address: 2
  register_type: "holding"
  value_type: FP32
  accuracy_decimals: 2
  unit_of_measurement: "mg/L"
  filters:
     - filter_out: 0

- platform: modbus_controller
  name: "Oxyquard_1_o2_temp"
  address: 8
  register_type: "holding"
  value_type: FP32
  accuracy_decimals: 1
  unit_of_measurement: "C"

- platform: modbus_controller
  name: "Oxyquard_1_CO2"
  address: 12
  register_type: "holding"
  value_type: FP32
  accuracy_decimals: 2
  unit_of_measurement: "mg/L"