Write data to modbus

I am tyring to emulate a energy meter dtsd1352 which is for sungrow inverter. But I can’t find any example for writing data to modbus. I tried modbus output but I couldn’t make it work.
My solar inverter makes these modbus requests:

[23:55:49][D][uart_debug:114]: <<< 20:73:00:00:00:01:C3:70
[23:55:49][W][modbus:105]: Modbus CRC Check failed! C010!=3F
[23:55:49][D][uart_debug:114]: <<< FE:03:00:3F:00:01:A0:09
[23:55:49][W][modbus:105]: Modbus CRC Check failed! 3A55!=00
[23:55:49][D][uart_debug:114]: <<< 20:73:00:00:00:01:C3:70
[23:55:49][W][modbus:105]: Modbus CRC Check failed! C010!=3F
[23:55:49][D][uart_debug:114]: <<< FE:03:00:3F:00:01:A0:09
[23:55:49][W][modbus:105]: Modbus CRC Check failed! 3A55!=00

I have to answer it with 2 data to start communication. 003FH high byte should be the address and low byte should be baud rate 1 (9600pbs).
How can I make it with esphome modbus controller?

Here is my yaml part:

modbus:
  id: modbus2
  flow_control_pin: GPIO5
  send_wait_time: 500ms

modbus_controller:
  - id: dtsd1352_modbus
    address: 0x20
    modbus_id: modbus2
    setup_priority: -10
    update_interval: 5s
output:
  - platform: modbus_controller
    modbus_controller_id: dtsd1352_modbus
    id: comm_path
    address: 63
    register_type: holding
    write_lambda: |-
                 return ?????;
1 Like