Toscanaccio
(Filippo Pardini)
January 3, 2025, 1:57pm
1
Hi,
I have a solar system consisting of an off-grid hybrid subsystem (MUST Pro 5Kw-220V) and an on-grid microinverter subsystem (Deye SUN-M220G4-EU-Q0). I intend to use a bidirectional energy meter to check the balance between the active energy supplied and the active energy injected. For this I have been testing the Eastron SDM230M meter successfully, except for one particular issue, which despite research, I have not been able to resolve. This refers to changing the holding register 463776 (modbus 0xF920) from the default mode 2 (total = import + export) to mode 3 (total = import - export). To do this, I need to write this holding register with two bytes (0x0003) and I don’t know how to do it, the ESPHome documentation on this is confusing to me, so I am asking the community for help. Thanks!
Karosm
(Karosm)
January 3, 2025, 3:20pm
2
You could use modbus custom command:
custom_command: [ 0x1, 0x10, 0xF920, 0x03]
(slave address 1)
if you only need it once, remove from your code after.
or
number:
number:
- platform: modbus_controller
modbus_controller_id: modbus_device
name: "Mode"
id: total_mode
register_type: holding
address: 0xF920
value_type: U_WORD
min_value: 2
max_value: 3
Toscanaccio
(Filippo Pardini)
January 5, 2025, 3:32pm
3
I tried both proposed methods, but neither worked:
custom_command: [ 0x1, 0x10, 0xF9, 0x20, 0x03]
and
number:
platform: modbus_controller
modbus_controller_id: mod_cont_sdm230
name: “Mode”
id: total_mode
register_type: holding
address: 0xF920
value_type: U_WORD
min_value: 2
max_value: 3
I also tried:
custom_command: [ 0x1, 0x06, 0xF9, 0x20, 0x03]
without success. I checked with Open ModScan which confirmed the mode remained as 2.
Karosm
(Karosm)
January 5, 2025, 3:52pm
4
Toscanaccio:
also tried:
custom_command: [ 0x1, 0x06, 0xF9, 0x20, 0x03]
Sorry for that, 0x06 is correct fc for single register.
So what are getting on runtime log ?
Modbus number component works like this: When you change the number it writes it to the register. Every update interval it reads the register and updates the number like sensor.
Can you post/link your protocol sheet.
Toscanaccio
(Filippo Pardini)
January 5, 2025, 9:19pm
5
I run this yaml:
esphome:
name: “sdmholding”
platform: esp32
board: esp32dev
api:
encryption:
key: “…”
ota:
platform: esphome
password: “…”
wifi:
ssid: …
password: …
manual_ip:
static_ip: 192.168.0.9
gateway: 192.168.0.1
subnet: 255.255.255.0
time:
platform: homeassistant
id: homeassistant_time
logger:
baud_rate: 115200
level: VERY_VERBOSE
uart:
id: uart_sdm
tx_pin: 17
rx_pin: 16
baud_rate: 9600
stop_bits: 1
modbus:
id: mod_bus_sdm230
send_wait_time : 3s
uart_id: uart_sdm
modbus_controller:
id: mod_cont_sdm230
address: 1
command_throttle: 3s
modbus_id: mod_bus_sdm230
setup_priority: -10
update_interval: 10s
number:
-platform: modbus_controller
modbus_controller_id: mod_cont_sdm230
name: “Mode”
id: total_mode
register_type: holding
address: 0xF920
value_type: U_WORD
min_value: 2
max_value: 3
sensor:
platform: modbus_controller
modbus_controller_id: mod_cont_sdm230
id: mode
name: “Mode”
address: 0xF920
register_type: holding
register_count: 1
value_type: U_WORD
In number: I set the value and in sensor: I read the value. When I set 3, the value read remains 2 and after a few seconds the value in number: automatically returns to 2.
[17:43:10][W][component:237]: Component modbus_controller took a long time for an operation (73 ms).
[17:43:10][W][component:238]: Components should block for at most 30 ms.
[17:43:19][VV][scheduler:226]: Running interval ‘update’ with interval=10000 last_execution=13425 (now=23426)
[17:43:19][V][modbus_controller:232]: Updating modbus component
[17:43:19][VV][modbus_controller:236]: Updating range 0xF920
[17:43:19][V][modbus_controller:199]: Range : F920 Size: 1 (3) skip: 0
[17:43:19][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:19][VV][uart.arduino_esp32:194]: Flushing…
[17:43:19][V][modbus:223]: Modbus write: 01.03.F9.20.00.01.B5.5C (8)
[17:43:19][V][modbus_controller:569]: Command sent 3 0xF920 1 send_count: 1
[17:43:19][VV][modbus:053]: Modbus received Byte 1 (0X1)
[17:43:19][VV][modbus:053]: Modbus received Byte 3 (0X3)
[17:43:19][VV][modbus:053]: Modbus received Byte 2 (0X2)
[17:43:20][VV][modbus:053]: Modbus received Byte 0 (0X0)
[17:43:20][VV][modbus:053]: Modbus received Byte 2 (0X2)
[17:43:20][VV][modbus:053]: Modbus received Byte 57 (0X39)
[17:43:20][VV][modbus:053]: Modbus received Byte 133 (0X85)
[17:43:20][V][modbus_controller:081]: Modbus response queued
[17:43:20][V][modbus:159]: Clearing buffer of 6 bytes - parse succeeded
[17:43:20][V][modbus_controller:089]: Process modbus response for address 0xF920 size: 2
[17:43:20][V][modbus_controller:170]: data for register address : 0xF920 :
[17:43:20][D][modbus.number:023]: Number new state : 2.00
[17:43:20][D][number:012]: ‘Mode’: Sending state 2.000000
[17:43:20][VV][api.service:260]: send_number_state_response: NumberStateResponse {
key: 3313201736
state: 2
missing_state: NO
}
[17:43:20][D][modbus_controller.sensor:025]: Sensor new state: 2.00
[17:43:20][V][sensor:043]: ‘Modo’: Received new state 2.000000
[17:43:20][D][sensor:094]: ‘Modo’: Sending state 2.00000 with 0 decimals of accuracy
[17:43:20][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
key: 3313201730
state: 2
missing_state: NO
}
[17:43:20][W][component:237]: Component modbus_controller took a long time for an operation (73 ms).
[17:43:20][W][component:238]: Components should block for at most 30 ms.
[17:43:28][VV][api.service:872]: on_number_command_request: NumberCommandRequest {
key: 3313201736
state: 3
}
[17:43:28][D][number:054]: ‘Mode’ - Setting number value
[17:43:28][D][number:113]: New number value: 3.000000
[17:43:28][D][modbus.number:061]: Updating register: connected Sensor=Mode start address=0xF920 register count=1 new value=3.00 (val=3.00)
[17:43:28][D][number:012]: ‘Mode’: Sending state 3.000000
[17:43:28][VV][api.service:260]: send_number_state_response: NumberStateResponse {
key: 3313201736
state: 3
missing_state: NO
}
[17:43:28][W][component:237]: Component api took a long time for an operation (54 ms).
[17:43:28][W][component:238]: Components should block for at most 30 ms.
[17:43:28][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:28][VV][uart.arduino_esp32:194]: Flushing…
[17:43:28][V][modbus:223]: Modbus write: 01.06.F9.20.00.03.F8.9D (8)
[17:43:28][V][modbus_controller:569]: Command sent 6 0xF920 1 send_count: 1
[17:43:29][VV][scheduler:226]: Running interval ‘update’ with interval=10000 last_execution=23425 (now=33426)
[17:43:29][V][modbus_controller:230]: 1 modbus commands already in queue
[17:43:29][VV][modbus_controller:236]: Updating range 0xF920
[17:43:29][V][modbus_controller:199]: Range : F920 Size: 1 (3) skip: 0
[17:43:31][V][modbus:042]: Stop waiting for response from 1
[17:43:31][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:31][VV][uart.arduino_esp32:194]: Flushing…
[17:43:31][V][modbus:223]: Modbus write: 01.06.F9.20.00.03.F8.9D (8)
[17:43:31][V][modbus_controller:569]: Command sent 6 0xF920 1 send_count: 2
[17:43:34][V][modbus:042]: Stop waiting for response from 1
[17:43:34][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:34][VV][uart.arduino_esp32:194]: Flushing…
[17:43:34][V][modbus:223]: Modbus write: 01.06.F9.20.00.03.F8.9D (8)
[17:43:34][V][modbus_controller:569]: Command sent 6 0xF920 1 send_count: 3
[17:43:37][V][modbus:042]: Stop waiting for response from 1
[17:43:37][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:37][VV][uart.arduino_esp32:194]: Flushing…
[17:43:37][V][modbus:223]: Modbus write: 01.06.F9.20.00.03.F8.9D (8)
[17:43:37][V][modbus_controller:569]: Command sent 6 0xF920 1 send_count: 4
[17:43:39][VV][scheduler:226]: Running interval ‘update’ with interval=10000 last_execution=33425 (now=43425)
[17:43:39][V][modbus_controller:230]: 2 modbus commands already in queue
[17:43:39][VV][modbus_controller:236]: Updating range 0xF920
[17:43:39][V][modbus_controller:199]: Range : F920 Size: 1 (3) skip: 0
[17:43:39][W][modbus_controller:186]: Duplicate modbus command found: type=0x3 address=63776 count=1
[17:43:40][V][modbus:042]: Stop waiting for response from 1
[17:43:40][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:40][VV][uart.arduino_esp32:194]: Flushing…
[17:43:40][V][modbus:223]: Modbus write: 01.06.F9.20.00.03.F8.9D (8)
[17:43:40][V][modbus_controller:569]: Command sent 6 0xF920 1 send_count: 5
[17:43:41][VV][modbus:053]: Modbus received Byte 255 (0Xff)
[17:43:41][V][modbus:035]: Clearing buffer of 1 bytes - timeout
[17:43:43][V][modbus:042]: Stop waiting for response from 1
[17:43:43][W][modbus_controller:027]: Modbus device=1 set offline
[17:43:43][D][modbus_controller:040]: Modbus command to device=1 register=0xF920 no response received - removed from send queue
[17:43:43][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:43][VV][uart.arduino_esp32:194]: Flushing…
[17:43:43][V][modbus:223]: Modbus write: 01.03.F9.20.00.01.B5.5C (8)
[17:43:43][V][modbus_controller:569]: Command sent 3 0xF920 1 send_count: 1
[17:43:46][V][modbus:042]: Stop waiting for response from 1
[17:43:46][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:46][VV][uart.arduino_esp32:194]: Flushing…
[17:43:46][V][modbus:223]: Modbus write: 01.03.F9.20.00.01.B5.5C (8)
[17:43:46][V][modbus_controller:569]: Command sent 3 0xF920 1 send_count: 2
[17:43:49][V][modbus:042]: Stop waiting for response from 1
[17:43:49][V][modbus_controller:044]: Sending next modbus command to device 1 register 0xF920 count 1
[17:43:49][VV][uart.arduino_esp32:194]: Flushing…
[17:43:49][V][modbus:223]: Modbus write: 01.03.F9.20.00.01.B5.5C (8)
[17:43:49][V][modbus_controller:569]: Command sent 3 0xF920 1 send_count: 3
[17:43:49][VV][scheduler:226]: Running interval ‘update’ with interval=10000 last_execution=43425 (now=53426)
[17:43:49][V][modbus_controller:230]: 1 modbus commands already in queue
[17:43:49][VV][modbus_controller:236]: Updating range 0xF920
[17:43:49][V][modbus_controller:199]: Range : F920 Size: 1 (3) skip: 0
[17:43:49][W][modbus_controller:186]: Duplicate modbus command found: type=0x3 address=63776 count=1
[17:43:51][VV][api.service:679]: on_disconnect_request: DisconnectRequest {}
[17:43:51][D][api.connection:199]: ESPHome Logs 2024.12.2 (192.168.0.235) requested disconnected
[17:43:51][VV][api.service:031]: send_disconnect_response: DisconnectResponse {}
INFO Processing expected disconnect from ESPHome API for sdmholding @ 192.168.0.9
WARNING Disconnected from API
PS D:\ESPHome>
Karosm
(Karosm)
January 5, 2025, 10:35pm
6
That’s the behavior I wrote in my last post. The number works as write and read.
I’m not a log guru, I see that the write request is done but I see lot of repeats.
You could eliminate the sensor component for the same address leaving just the number, to make log more readable.
You could also enable debug on uart component to see pure uart responses.