ESP32 as RS-485 bridge for modbus

Hi to all!
I have remote solar controller with modbus (RS-485) interface.
I am currently collecting data using a 4G wireless router (Teltonika RUT955) using its embedded RS-485 interface.
I need to use one of the several RUT240 model I don’t use instead buying new RUT955 (in this case RS-485 interface not available), so I thought to create my own wireless RS-485 bridge using ESP32.

I ordered ESP32 board and RS-485 adapter, meanwhile I am taking a look to the code… Modbus Controller

I am confused about client (so my ESP32) code: I already set on my HA code for reading register at 0x9001 when using RUT955:

# CHR Grado
- name: CHR_Grado
  type: tcp
  host: 10.55.44.20
  port: 503

  sensors:
    - name:  "Battery Capacity"
      slave: 1
      address: 0x9001
      input_type: holding
      unit_of_measurement: AH
      device_class: voltage
      state_class: measurement
      scale: 0.01
      offset: 0
      precision: 1
      data_type: U_WORD

why need I write on ESP32 code for register at 0x9001 again?
Thanks.

I’m not sure what are you trying to do. But with Esphome + rs485 you do the whole setup on esphome.

If you use esphome you don’t need modbus: in Home Assistant

What!?!?!?
I need “modbus” in HA to collect data through modbus protocol, I am currently using this for several RUT955 and it works, why do you say I don’t need it if I want swap RUT955 with ESP?

Because you do it in Esphome…

Esphome it’s not a transparent bridge.

Esphome convert modbus to sensors.

You can use Tasmota.

It’s now possible to have a RS485 ESPHome bridge on ESP8266 and ESP32 – I hope you’ll find it helpful. GitHub - rosenrot00/esphome_modbus_bridge

2 Likes

Hi @rosenrot00, thanks for creating this modbus bridge for ESPhome. I was was originally using ESPhome but then had to move to tasmota because there wasn’t a modbus bridge previously available.

I am using HA modbus component to control an air conditioner with the modbus bridge acting as the tcp to serial interface. In tasmota I was able to configure the serial baud rate, parity bit and bit size using the command here (Modbus Bridge - Tasmota) , but I cant see anywhere in the yaml to do this apart from configuring the serial communication between the ESP32 and the UART RTU adapter but not the RTU to the Modbus devices. Please correct me if im wrong.

Hi @vijaykbhatia the UART parameters are directly mapped to the Modbus RTU configuration. When a Modbus transceiver is connected, communication is forwarded according to the configured UART settings. Just set your baud, parity,… in UART and it will work.

2 Likes

Ahhh thanks, this makes sense. I’ll give it a go then.

Let us know how it goes.

I started out with Tasmota as well but I felt it as a loss to have a ESP32 which I can’t use for other tasks in parallel. With ESPHome it can now act as a bluetooth relay and much more. At least if you work with Homeassistant for me using ESPHome over Tasmota is much more versatile.

Reporting back it is all working well with an Actron BMS board. Fairly smooth swap over once I remembered it had an even parity. Thanks for your work, its great t have this working in ESPhome and can have all the other benefits like Bluetooth proxy etc

1 Like