本帖最后由 zcjschina 于 2024-3-6 12:08 编辑
网上大多教程为ESP32读取正泰单相电能表的教程,未找到读取ESP32读取德力西仪表DT(S)SU6606VCRf型三相电子式电能表数据的教程,在参考了相关教程并结合实际情况研究后,终于成功实现了ESP32与德力西仪表DT(S)SU6606VCRf型三相电子式电能表的数据通讯,并成功在Homeassistant上显示。先附上成果图:
所用的硬件为:esp32-wroom-32e
软件平台:ESPHome+Home Assistant
电能表型号:德力西仪表DT(S)SU6606VCRf型三相电子式电能表
通讯方式:Modbus RTU 485
YAML文件供参考:
substitutions:
device_name: meter-delixi #替换成想要的设备名称
friendly_name: meter_delixi
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
area: Asia/Shanghai
esp32:
board: esp-wrover-kit
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
api:
encryption:
key: !secret api_encryption_key
#Web OTA Update Choose ‘firmware.bin’
ota:
password: !secret ota_password
on_progress:
then:
- logger.log:
format: "OTA progress %0.1f%%"
args: ["x"]
# Example configuration
network:
enable_ipv6: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${friendly_name}_Hotspot
password: !secret ap_wifi_password
captive_portal:
web_server:
port: 80
button:
- platform: restart
name: ${device_name}_reboot
time:
- platform: sntp
id: ${friendly_name}_time
uart:
id: ${friendly_name}_uart
rx_pin: 16
tx_pin: 17
baud_rate: 9600
data_bits: 8
stop_bits: 1
#parity: even
modbus:
id: ${friendly_name}_modbus
send_wait_time: 250ms
uart_id: ${friendly_name}_uart
modbus_controller:
- id: ${friendly_name}_modbus_controller
modbus_id: ${friendly_name}_modbus
address: 0x01 #设备地址码(一般是1根据实际情况填)
command_throttle: 200ms
setup_priority: -10
update_interval: 10s
sensor:
- platform: uptime
id: ${friendly_name}_uptime
name: ${friendly_name}_uptime
- platform: internal_temperature
id: ${friendly_name}_cpu_temprature
name: ${friendly_name}_cpu_temprature
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: ${friendly_name}_WiFi_Signal_dB
id: ${friendly_name}_wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: ${friendly_name}_wifi_signal_db
name: ${friendly_name}_WiFi_Signal_Percent
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "PCT"
entity_category: "diagnostic"
#delixi_dtsu6606vcrf 电表地址
#电压
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_ua
name: ${friendly_name}_ua
address: 0x0300
register_count: 1
unit_of_measurement: "V"
register_type: holding
value_type: S_WORD
accuracy_decimals: 2
device_class: voltage
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_ub
name: ${friendly_name}_ub
address: 0x0301
register_count: 1
unit_of_measurement: "V"
register_type: holding
value_type: S_WORD
accuracy_decimals: 2
device_class: voltage
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_uc
name: ${friendly_name}_uc
address: 0x0302
register_count: 1
unit_of_measurement: "V"
register_type: holding
value_type: S_WORD
accuracy_decimals: 2
device_class: voltage
filters:
- multiply: 0.1
#电流
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_ia
name: ${friendly_name}_ia
address: 0x0303
register_count: 1
unit_of_measurement: "A"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: current
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_ib
name: ${friendly_name}_ib
address: 0x0304
register_count: 1
unit_of_measurement: "A"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: current
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_ic
name: ${friendly_name}_ic
address: 0x0305
register_count: 1
unit_of_measurement: "A"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: current
filters:
- multiply: 0.01
#有功功率
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pa
name: ${friendly_name}_pa
address: 0x0306
register_count: 1
unit_of_measurement: "kW"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pb
name: ${friendly_name}_pb
address: 0x0307
register_count: 1
unit_of_measurement: "kW"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pc
name: ${friendly_name}_pc
address: 0x0308
register_count: 1
unit_of_measurement: "kW"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pabc
name: ${friendly_name}_pabc
address: 0x0309
register_count: 1
unit_of_measurement: "kW"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
#无功功率
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_qa
name: ${friendly_name}_qa
address: 0x030A
register_count: 1
unit_of_measurement: "kVar"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_qb
name: ${friendly_name}_qb
address: 0x030B
register_count: 1
unit_of_measurement: "kVar"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_qc
name: ${friendly_name}_qc
address: 0x030C
register_count: 1
unit_of_measurement: "kVar"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_qabc
name: ${friendly_name}_qabc
address: 0x030D
register_count: 1
unit_of_measurement: "kVar"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
#视在功率
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_Sa
name: ${friendly_name}_Sa
address: 0x030E
register_count: 1
unit_of_measurement: "kVA"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_Sb
name: ${friendly_name}_Sb
address: 0x030F
register_count: 1
unit_of_measurement: "kVA"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_Sc
name: ${friendly_name}_Sc
address: 0x0310
register_count: 1
unit_of_measurement: "kVA"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_Sabc
name: ${friendly_name}_Sabc
address: 0x0311
register_count: 1
unit_of_measurement: "kVA"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power
filters:
- multiply: 0.01
#功率因数
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pfa
name: ${friendly_name}_pfa
address: 0x0312
register_count: 1
unit_of_measurement: "cosphi"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power_factor
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pfb
name: ${friendly_name}_pfb
address: 0x0313
register_count: 1
unit_of_measurement: "cosphi"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power_factor
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pfc
name: ${friendly_name}_pfc
address: 0x0314
register_count: 1
unit_of_measurement: "cosphi"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power_factor
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_pfabc
name: ${friendly_name}_pfabc
address: 0x0315
register_count: 1
unit_of_measurement: "cosphi"
register_type: holding
value_type: S_WORD
accuracy_decimals: 3
device_class: power_factor
filters:
- multiply: 0.001
#频率
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_freq
name: ${friendly_name}_freq
address: 0x0316
register_count: 1
unit_of_measurement: "Hz"
register_type: holding
value_type: S_WORD
accuracy_decimals: 2
device_class: power_factor
filters:
- multiply: 0.01
#电能量
#当前组合有功总电能
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_total_energy
name: ${friendly_name}_total_energy
address: 0x0000
register_count: 2
unit_of_measurement: "kWh"
register_type: holding
value_type: S_DWORD
accuracy_decimals: 2
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.01
- median:
window_size: 3
send_every: 3
#当前正向有功总电能
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_forward_energy
name: ${friendly_name}_forward_energy
address: 0x000A
register_count: 2
unit_of_measurement: "kWh"
register_type: holding
value_type: S_DWORD
accuracy_decimals: 2
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.01
- median:
window_size: 3
send_every: 3
#当前反向有功总电能
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_reversing_energy
name: ${friendly_name}_reversing_energy
address: 0x0014
register_count: 2
unit_of_measurement: "kWh"
register_type: holding
value_type: S_DWORD
accuracy_decimals: 2
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.01
- median:
window_size: 3
send_every: 3
#当前无功总电能
- platform: modbus_controller
modbus_controller_id: ${friendly_name}_modbus_controller
id: ${friendly_name}_reactive_energy
name: ${friendly_name}_reactive_energy
address: 0x0186
register_count: 2
unit_of_measurement: "kWh"
register_type: holding
value_type: S_DWORD
accuracy_decimals: 2
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.01
- median:
window_size: 3
send_every: 3
interval:
- interval: 5min
then:
- if:
condition:
or:
- not: wifi.connected
- lambda: 'return id(${friendly_name}_wifi_signal_db).state < -70;'
then:
- logger.log: WiFi signal is too weak or not connected. Reconnecting...
- wifi.disable
- delay: 5s
- wifi.enable
|