Problem with connecting the DME D301 MID counter via Modbus

Good morning,

I bought the meter mentioned in the title some time ago. I’d like to connect it to Home Assistant.

I chose the ESPHome Modbus software and wanted to connect the meter using an RS485<->UART converter. My converter is exactly like the one in the example: Modbus Controller - ESPHome - Smart Home Made Simple.

Unfortunately, I’ve encountered problems. I can’t communicate with the meter at all. I can’t find any resources online that could help me.

Here is the link to the technical docs about the meter: https://catalogue.lovatoelectric.com/us_en/Energy-meter-three-phase-with-neutral-non-expandable-MID-certified-80A-direct-connection-4U-RS485-interface-multi-measurements/DMED301MID/snp

Please help me configure it or direct me to a place where I can get technical support.

Here’s my configuration:

esphome:
  name: modbusproxy

esp32:
  board: mhetesp32devkit
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  reboot_timeout: 0s

mqtt:
  broker: 192.168.4.120
  username: homeassistant
  password: !secret mqtt_password

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: "xxx"
  password: "xxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Modbus-Proxy Fallback Hotspot"
    password: "xxx"

captive_portal:
    
web_server:
  port: 80

uart:
  - id: uart_modbus_client
    tx_pin: 17 # UART2 TX pin
    rx_pin: 16 # UART2 RX pin
    baud_rate: 9600

modbus:
  - uart_id: uart_modbus_client
    id: modbus_client

modbus_controller:
- id: lovato_dmed301mid
  address: 0x1   ## address of the Modbus slave device on the bus
  modbus_id: modbus_client
  setup_priority: -10
  update_interval: 5s

sensor:
  - platform: modbus_controller
    modbus_controller_id: lovato_dmed301mid
    name: "Voltage L1"
    id: voltage_l1
    address: 0x0002
    register_type: holding
    value_type: U_DWORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement

Every 5s in the console, I see the following error:

[D][modbus_controller:039]: Modbus command to device=1 register=0x02 no response received - removed from send queue

Please help.

How is your wiring? Long/short? Soldered connections on converter?
Rx-rx, tx-tx between esp and converter, not crossed.

Thank you for your response.

Wiring is short (40cm max). Definitely not crossed. Double checked the A, B and Rx, Tx connections with a multimeter. Tx LED is blinking when sending the data. Rx seems to be dead. Cables are mounted to terminals directly soldered to the converter.

I’ve now tried two converters of the same model and three different ESP32 devkit boards.

Also tried TR on the meter to bridge it with A.

Still no luck.

So you confirm that esp tx pin (gpio17) is connected to converter tx pin?

Yes. Thank you for your help.

After a long time struggling with the integration, I finally got it working properly.

I’ve reached out to the Lovato support in Poland also to get involved, and they were very helpful.

There were 2 main problems I’ve fixed:

  1. I’ve changed the UART PINs on the ESP32 board from
    tx_pin: 17 # UART2 TX pin
    rx_pin: 16 # UART2 RX pin
    to
    tx_pin: 33
    rx_pin: 13

I have no idea why it worked. Maybe someone on this forum will have some suggestions?

  1. The support gave me a hint to offset the registers mentioned in the documentation by -1 so that register 0x0002 will become 0x0001 in the YAML script. The link to the Lovato meter documentation is available in the issue description.

Also, the ESPHome feature of UART debugging was very helpful to get the error codes from the meter. To translate the error codes, I’ve reached the MODBUS documentation at Exception Codes | Simply Modbus Software. I’ve found the exception code I was getting from the MODBUS. 02 was the incorrect register address.

The actual script that works and reads the voltage on L1, L2, and L3 phases from Lovato meter is presented below:

esphome:
  name: modbusproxy

esp32:
  board: mhetesp32devkit
#  board: esp-wrover-kit
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
#  password: ""
#  homeassistant_services: true
#  homeassistant_states: true
  reboot_timeout: 0s

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Modbus-Proxy Fallback Hotspot"
    password: !secret ap_password

captive_portal:
    
web_server:
  port: 80

switch:
  - platform: gpio
    id: builtin_led
    name: "LED"
    pin:
      number: GPIO2
      inverted: true

uart:
  - id: uart_modbus_client
#    tx_pin: 17 # UART2 TX pin
#    rx_pin: 16 # UART2 RX pin
    tx_pin: 33 # UART2 TX pin
    rx_pin: 13 # UART2 RX pin
    baud_rate: 9600
    data_bits: 8
    parity: NONE
    stop_bits: 1
#    debug:
#      direction: BOTH
#      dummy_receiver: false
#      after:
#        delimiter: "\n"
#      sequence:
#        - lambda: UARTDebug::log_string(direction, bytes);

modbus:
  - uart_id: uart_modbus_client
    id: modbus_client

modbus_controller:
- id: lovato_dmed301mid
  address: 1   ## address of the Modbus slave device on the bus
  modbus_id: modbus_client
  setup_priority: -10
  update_interval: 5s

sensor:
  - platform: modbus_controller
    modbus_controller_id: lovato_dmed301mid
    name: "Voltage L1"
    id: voltage_l1
    address: 0x0001
    register_type: holding
    value_type: U_DWORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
  - platform: modbus_controller
    modbus_controller_id: lovato_dmed301mid
    name: "Voltage L2"
    id: voltage_l2
    address: 0x0003
    register_type: holding
    value_type: U_DWORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
  - platform: modbus_controller
    modbus_controller_id: lovato_dmed301mid
    name: "Voltage L3"
    id: voltage_l3
    address: 0x0005
    register_type: holding
    value_type: U_DWORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

Nice that you resolved it.
Manual of your device presents address 0002h, I wonder how it should translate to anything else than 0x0002 hex

Only reason I can imagine is bad pin connection/soldering.