Skip to content

Instantly share code, notes, and snippets.

@Elwell
Created July 16, 2023 11:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elwell/2bd1751469a578d96ad56a86616c6113 to your computer and use it in GitHub Desktop.
Save Elwell/2bd1751469a578d96ad56a86616c6113 to your computer and use it in GitHub Desktop.
ESPHome modbus configuration to read a Hiking DDS238-2 ZN/S Energy meter

ESPHome modbus polling of a single phase energy meter

This is my working configuration to poll a http://www.chinaenergymeter.com/1-1-15-dds238-2-zn-s-single-phase-din-rail-type-watt-hour-meter.html (I have the 65A hard wired variant - I've seen postings that the CT clamp version may not be as responsive

I'm using a wemos D1 mini (ESP8266) with a RS485 toTTL module (that's OK at 3.3v). This seems fine using software serial on D1/D2 at a polling rate of every 5s

GOTCHAS

  • If the wemos stays connected to home assistant but CAN'T talk to the meter, HA will re-use the last value rather than marking it offline/NaN/unavailable
# esphome config for D1 mini + rs485 modbus
# Andrew Elwell, 2023 with thanks to all those who've posted the modbus registers online
esphome:
name: modbus-meter1
comment: Modbus testing
esp8266:
board: d1_mini
framework:
version: recommended
logger:
level: INFO
status_led:
pin:
number: D4
inverted: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
uart:
tx_pin: 5
rx_pin: 4
baud_rate: 9600
modbus:
# send_wait_time: 500ms
# flow_control_pin: 5
id: modbus1
modbus_controller:
- id: meter
address: 0x1
modbus_id: modbus1
setup_priority: -10
update_interval: 5s
sensor:
- platform: modbus_controller
modbus_controller_id: meter
name: Total Energy
device_class: energy
state_class: total
unit_of_measurement: kWh
register_type: holding
address: 0x0000
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.01 # 1/100
- platform: modbus_controller
modbus_controller_id: meter
name: Export Energy
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
register_type: holding
address: 0x0008
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.01 # 1/100
- platform: modbus_controller
modbus_controller_id: meter
name: Import Energy
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
register_type: holding
address: 0x00A
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.01 # 1/100
- platform: modbus_controller
modbus_controller_id: meter
name: "Voltage"
register_type: holding
address: 0x000C
unit_of_measurement: "V"
device_class: voltage
value_type: U_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1 # 1/10
- platform: modbus_controller
modbus_controller_id: meter
name: "Current"
device_class: current
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: meter
name: "Active Power"
device_class: power
register_type: holding
address: 0x000E
unit_of_measurement: "W"
value_type: S_WORD
- platform: modbus_controller
modbus_controller_id: meter
name: "Reactive Power"
device_class: reactive_power
register_type: holding
address: 0x000F
unit_of_measurement: "VAr"
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: meter
name: "Power Factor"
device_class: power_factor
register_type: holding
address: 0x0010
value_type: U_WORD
accuracy_decimals: 3
filters:
- multiply: 0.001 # 1/1000
- platform: modbus_controller
modbus_controller_id: meter
name: "Frequency"
device_class: frequency
register_type: holding
address: 0x0011
unit_of_measurement: "Hz"
value_type: U_WORD
accuracy_decimals: 2
filters:
- multiply: 0.01 # 1/100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment