Hiking DDS238-2 ZN/S energy meter RESET ModBus

Hello everyone,

my energy meter is running very well with ESPHome and the modbus configuration.
but one thing is an impossible challenge for me. How can I reset the meter value?

The adress which I have to reset is:
Adress:
0008h-0009h | export energy
000Ah-000Bh | import energy

And the value to write is 0

function code 16 (0x10)

here my code which is not working:

esphome:
  name: esp32
  friendly_name: ESP32testMB

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "blalvlvl"

ota:
  password: "blabla"

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

# If you use Home Assistant please remove this `mqtt` section and uncomment the native `api` component!
mqtt:
  broker: 192.168.1.3
  #username: !secret mqtt_username
  #password: !secret mqtt_password
  id: mqtt_client

uart:
  id: mod_bus
  tx_pin: 16
  rx_pin: 17
  baud_rate: 9600
  stop_bits: 1

modbus:
  #send_wait_time: 500ms
  #flow_control_pin: 5
  id: modbus1

modbus_controller:
  - id: epever
    ## the Modbus device addr
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10
    update_interval: 5s

sensor:
  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Spannung"
    id: Spannung
    register_type: holding
    address: 0x000C
    unit_of_measurement: "V"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1 #1/10

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Strom"
    id: Strom
    register_type: holding
    address: 0x000D
    unit_of_measurement: "A"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Leistung"
    id: Leistung
    register_type: holding
    address: 0x000E
    unit_of_measurement: "W"
    value_type: S_WORD
    #accuracy_decimals: 2
    #filters:
    #- multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Blindleistung"
    id: Blindleistung
    register_type: holding
    address: 0x000F
    unit_of_measurement: "var"
    value_type: U_WORD
    #accuracy_decimals: 2
    #filters:
    #- multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Leistungsfaktor"
    id: Leistungsfaktor
    register_type: holding
    address: 0x0010
    #unit_of_measurement: "var"
    value_type: U_WORD
    #accuracy_decimals: 2
    filters:
    - multiply: 0.001 #1/1000

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Frequenz"
    id: Frequenz
    register_type: holding
    address: 0x0011
    unit_of_measurement: "Hz"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "GesamtZaehler"
    id: GesamtZaehler
    register_type: holding
    address: 0x0000
    unit_of_measurement: "kWh"
    value_type: U_DWORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "exportZaehler"
    id: exportZaehler
    register_type: holding
    address: 0x0008
    unit_of_measurement: "kWh"
    value_type: U_DWORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01 #1/100

  - platform: modbus_controller
    modbus_controller_id: epever
    name: "importZaehler"
    id: importZaehler
    register_type: holding
    address: 0x000A
    unit_of_measurement: "kWh"
    value_type: U_DWORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01 #1/100    

switch:
  #https://community.home-assistant.io/t/schneider-iem3155-energy-meter-sending-modbus-custom-command/444952/4
  - platform: modbus_controller
    modbus_controller_id: epever
    name: "Reset command"
    id: reset_partial
    custom_command: [ 0x01, 0x10, 0x00, 0x0a, 0x00, 0x02, 0x04, 0x00, 0x00 ]

#text_sensor:
#  - name: "rtc_clock"
#    platform: modbus_controller
#    modbus_controller_id: epever
#    id: rtc_clock
#    internal: true
#    register_type: holding
#    address: 0x000c
#    register_count: 3
#    raw_encode: HEXBYTES
#    response_size: 6

#switch:
#  - platform: modbus_controller
#    modbus_controller_id: epever
#    id: reset_to_fabric_default
#    name: "Reset to Factory Default"
#    register_type: coil
#    address: 0x15
#    bitmask: 1

regards and thanks
Martin

Has no one an idea?

Hi, you may want to take a look at the great work @rodgon81 has done (esphome/esphome/components/dxs238xw at dev · rodgon81/esphome · GitHub). His integration has an action to reset the total energy. I have used it and it has reset the meter counter on my DDS238-4 W.
Commands passed by built in ESP8266 may be similar.

Regards

Done with this code for my DDS238-2 ZN/S:

switch:
  - platform: modbus_controller
    modbus_controller_id: rs485
    name: "Reset command"
    id: reset_partial
    register_type: holding
    address: 0
    write_lambda: |-
      ESP_LOGD("main","Modbus Switch incoming state = %f",x);
      // return false ; // use this to just change the value
      payload.push_back(0x04);  // device address!
      payload.push_back(0x10);  
      payload.push_back(0x00); 
      payload.push_back(0x00);  
      payload.push_back(0x00); 
      payload.push_back(0x02);
      payload.push_back(0x04);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0xe2);
      payload.push_back(0x63);

      return true;

Thank you for this hack.
It works for a DDS238-1 ZN. I took some register address from @martin8310

esphome:
  name: esp-energymeter
  friendly_name: ESP-EnergyMeter

esp32:
  board: esp32dev
  # board: wemos_d1_mini32
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "ABC"

ota:
  password: "ABC"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Energymeter Fallback Hotspot"
    password: "ABC"

captive_portal:

web_server:
  port: 80

uart:
  id: mod_uart
  tx_pin: GPIO16
  rx_pin: GPIO17
  baud_rate: 9600
  stop_bits: 1
  data_bits: 8
  parity: NONE

modbus:
  send_wait_time: 250ms
  disable_crc: False
  uart_id: mod_uart
  id: mod_bus
  flow_control_pin: GPIO25

modbus_controller:
- id: modbus_device
  address: 0x01   
  modbus_id: mod_bus
  setup_priority: -10
  update_interval: 30s
  command_throttle: 0ms
  
sensor:
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Energy_Low
    name: "Total Energy Low"
    register_type: holding
    address: 0x000    
    register_count: 0 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1
  
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Energy_High
    name: "Total Energy High"
    register_type: holding
    address: 0x001    
    register_count: 1 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1

  - platform: template
    name: "Current Total Energy"
    unit_of_measurement: "KW"
    lambda: |-
      return (id(Energy_Low).state + id(Energy_High).state);

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Export_Energy_Low
    name: "Current Export Energy Low"
    register_type: holding
    address: 0x008    
    register_count: 8 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1
  
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Export_Energy_High
    name: "Current Export Energy High"
    register_type: holding
    address: 0x009    
    register_count: 9 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1

  - platform: template
    name: "Current Total Export Energy"
    unit_of_measurement: "KW"
    lambda: |-
      return (id(Export_Energy_Low).state + id(Export_Energy_High).state);

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Import_Energy_Low
    name: "Current Import Energy Low"
    register_type: holding
    address: 0x00A    
    register_count: 10 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1
  
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    id: Import_Energy_High
    name: "Current Import Energy High"
    register_type: holding
    address: 0x00B    
    register_count: 11 #Much faster & stable readings
    unit_of_measurement: "KW"
    internal: true
    accuracy_decimals: 2
    filters:
      - multiply: 0.1

  - platform: template
    name: "Current Total Import Energy"
    unit_of_measurement: "KW"
    lambda: |-
      return (id(Import_Energy_Low).state + id(Import_Energy_High).state);

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Voltage"
    register_type: holding
    address: 0x00C    
    register_count: 12 #Much faster & stable readings
    unit_of_measurement: "V"
    accuracy_decimals: 2
    filters:
      - multiply: 0.1

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Current"
    register_type: holding
    address: 0x00D    
    register_count: 13 #Much faster & stable readings
    unit_of_measurement: "A"
    accuracy_decimals: 3
    filters:
    - multiply: 0.001

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Active Power"
    register_type: holding
    address: 0x00E    
    register_count: 14 #Much faster & stable readings
    unit_of_measurement: "KW"
    accuracy_decimals: 2
    filters:
    - multiply: 0.01
  
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Reactive Power"
    register_type: holding
    address: 0x00F    
    register_count: 15 #Much faster & stable readings
    unit_of_measurement: "KVAR"
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Power Factor"
    register_type: holding
    address: 0x010    
    register_count: 16 #Much faster & stable readings
    unit_of_measurement: "kVA"
    accuracy_decimals: 3
    filters:
    - multiply: 0.001

  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Frequency"
    register_type: holding
    address: 0x011    
    register_count: 17 #Much faster & stable readings
    unit_of_measurement: "Hz"
    accuracy_decimals: 2
    filters:
    - multiply: 0.01
  
  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 120s
    entity_category: "diagnostic"
    device_class: signal_strength

  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "%"
    entity_category: "diagnostic"
    device_class: ""

binary_sensor:
  - platform: status 
    name: "Device status"
    id: Status

text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
    ssid:
      name: Connected SSID
    bssid:
      name: Connected BSSID
    mac_address:
      name: Mac Wifi Address
    scan_results:
      name: Latest Scan Results
    dns_address:
      name: DNS Address

switch:
  - platform: safe_mode
    name: "Restart (Safe Mode)"
  - platform: restart
    name: "Restart"   
  - platform: modbus_controller
    modbus_controller_id: modbus_device
    name: "Reset command"
    id: reset_partial
    register_type: holding
    address: 0x01
    write_lambda: |-
      ESP_LOGD("main","Modbus Switch incoming state = %f",x);
      // return false ; // use this to just change the value
      payload.push_back(0x01);  // device address!
      payload.push_back(0x10);  
      payload.push_back(0x00); 
      payload.push_back(0x00);  
      payload.push_back(0x00); 
      payload.push_back(0x02);
      payload.push_back(0x04);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);
      payload.push_back(0x00);

      return true;

How do you handle Low and High registers for calculations. For example: In many GitHub examples, Total Current Energy = Current Enery Low + Current Energy High. I don’t know if I’m adding them correctly

  - platform: template
    name: "Current Total Energy"
    unit_of_measurement: "KW"
    lambda: |-
      return (id(Energy_Low).state + id(Energy_High).state);

Thank you all