Hey there,
i’ve created a Modbus slave device that emulates an energy meter for my SolarEdge inverter with sensor data from Home Assistant. I’ve followed the instructions from the Modbus Controller component and created this code (UART and everything else is working fine):
### MODBUS ###
modbus:
# Energy meter
- uart_id: uart_em
id: modbus_em
role: server
### ENERGY METER ###
modbus_controller:
- modbus_id: modbus_em
setup_priority: -10
update_interval: ${device_update_interval}
command_throttle: 100ms
address: 0x05
server_registers:
# BLOCK 1001 (1000)
# Data register block
- address: 0x03E8 # total active energy
value_type: FP32
read_lambda: |-
return 0.0;
- address: 0x03EA # imported active energy
value_type: FP32
read_lambda: |-
return id(import_energy_active).state ? id(import_energy_active).state : 0;
...
# BLOCK 1601 (1600)
# Configuration register block
- address: 0x0640 # config passcode
value_type: S_DWORD
read_lambda: |-
return 0;
- address: 0x0642 # ct rated current
value_type: S_WORD
read_lambda: |-
return 100;
- address: 0x0643 # ct rated current l1
value_type: S_WORD
read_lambda: |-
return 100;
The registers are splitted into address blocks beginning at 1000, 1100, 1600, 1650 and 1700. Each block has got individual register counts.
This code produces the following issues:
- The inverter has got the device ID 0x01. The primary energy meter on the same bus the device ID 0x02. The ESPHome device with the device ID 0x05 now got requests with device ID 0x02 which ends up into CRC errors. Normally Modbus devices should only response to telegrams with the own device ID.
- The register block 1600 is requested successfully by the inverter - showing up in the logs - but no other blocks are requested by the inverter. The debug log also doesn’t show any other requests from device ID 0x01.
Did someone successfully created a Modbus slave device or have any ideas how to solve my problems?