科陆 DDSD720-L 电表应用

ha电表

由于机缘巧合之下,我获得了一块科陆的轨道式 485 电表 DDSD720-L ,参考鬼总的教程,使用 485-RS232-USB 摸块接入到 node-red 主机内。

科陆说明文件

科陆DDSD720-L电表使用教程 by 小鬼

Node-red

导入文件:电表.zip (2.8 KB)

注意事项

阶梯电价代码需要修改自己的

我这里中山的阶梯电价第一阶梯阈值是分月份的,5~10月份第一阶梯阈值是不一样,所以需要得到当前月份计算获得阈值。

// 通过当月月份判断阶梯一的阈值
function Get_level_One_threshold(){
    var Month = new Date().getMonth() + 1
    if (Month >= 5 && Month <= 10) {
        return 260
    } else {
        return 200
    }
}

阶梯电价的电费

// 阶梯一电费单价
var Level_One_univalent=0.61886875
// 阶梯二电费单价
var Level_Two_univalent=0.66886875
// 阶梯三电费单价
var Level_Three_univalent=0.91886875
// 获取阶梯一阈值
var Level_One_threshold = Get_level_One_threshold()
// 获取阶梯二阈值
var Level_Two_threshold = 600

HomeAssistant 配置

sensor:
  # 实时电压
  - platform: mqtt
    name: "ddsd720_l_voltage"
    unit_of_measurement: 'V'
    state_topic: "DDSD720-L/data"
    value_template: "{{ value_json.Voltage }}"
  # 实时功率
  - platform: mqtt
    name: "ddsd720_l_power"
    unit_of_measurement: 'KW'
    state_topic: "DDSD720-L/data"
    value_template: "{{ value_json.Power }}"
  # 实时电流
  - platform: mqtt
    name: "ddsd720_l_electric_current"
    unit_of_measurement: 'A'
    state_topic: "DDSD720-L/data"
    value_template: "{{ value_json.Electric_current }}"
  # 月用电量
  - platform: mqtt
    name: "ddsd720_l_energy_used"
    unit_of_measurement: 'kW·h'
    state_topic: "DDSD720-L/data"
    value_template: "{{ value_json.Energy_used }}"
  # # 当月实时电费
  - platform: mqtt
    name: "ddsd720_l_total_cost"
    unit_of_measurement: '元'
    state_topic: "DDSD720-L/cost"
    value_template: "{{ value_json.Total_cost }}"
  # 当天实时用电量
  - platform: mqtt
    name: "ddsd720_l_today_energy_used"
    unit_of_measurement: 'kW·h'
    state_topic: "DDSD720-L/data"
    value_template: "{{ value_json.Today_Energy_Used }}"

switch:
  # 刷新
  - platform: mqtt
    name: "ddsd720_l_refresh"
    command_topic: "DDSD720-L/Refresh"
    state_topic: "DDSD720-L/state"

homeassistant:
  customize:
    sensor.ddsd720_l_voltage:
      friendly_name: 实时电压
      icon:  mdi:mdi-flash-red-eye
    sensor.ddsd720_l_power:
      friendly_name: 实时功率
      icon:  mdi:mdi-flash-outline
    sensor.ddsd720_l_electric_current:
      friendly_name: 实时电流
      icon:  mdi:mdi-flash-auto
    sensor.ddsd720_l_energy_used:
      friendly_name: 月用电量
      icon:  mdi:mdi-flash-circle
    sensor.ddsd720_l_total_cost:
      friendly_name: 当月电费
      icon:  mdi:mdi-cash-usd
    sensor.ddsd720_l_today_energy_used:
      friendly_name: 当天电量
      icon: mdi:mdi-chart-bar

Lovelace

依赖插件:

  • mini-graph-card
  • button-card
cards:
  - entity: sensor.ddsd720_l_total_cost
    max: 500
    min: 0
    severity:
      green: 200
      red: 400
      yellow: 250
    type: gauge
  - cards:
      - aggregate_func: max
        animate: true
        entities:
          - entity: sensor.ddsd720_l_today_energy_used
        group_by: date
        hour24: true
        hours_to_show: 168
        name: 近七天用电量
        show:
          graph: bar
        type: 'custom:mini-graph-card'
      - entities:
          - sensor.ddsd720_l_power
        hours_to_show: 24
        line_width: 1
        points_per_hour: 24
        smoothing: false
        type: 'custom:mini-graph-card'
    type: horizontal-stack
  - entity: switch.ddsd720_l_refresh
    hold_action:
      action: more-info
    icon_height: 25px
    name: 刷新信息
    show_icon: true
    show_name: true
    tap_action:
      action: toggle
    type: button
title: 能源
type: vertical-stack

十分感谢大神的教程。

大神你好,我按照你教程出现以下问题,电表是派诺的导轨表。
请帮忙看看是那个数据不对。
image

[{“id”:“81e76ded.e0413”,“type”:“tab”,“label”:“流程 1”,“disabled”:false,“info”:""},{“id”:“53f713aa.02331c”,“type”:“comment”,“z”:“81e76ded.e0413”,“name”:“电表”,“info”:"",“x”:50,“y”:300,“wires”:[]},{“id”:“b2364e74.d1caf”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L电压”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“2”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:360,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“6b28b516.68074c”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L电流”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“3”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:400,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“bb4c64c4.ea99f8”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L功率”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“5”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:440,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“5fc3ed1f.eee5b4”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L度数”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“0”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:360,“y”:500,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“7d244333.da4d2c”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“数据转换”,“func”:“var data_hex1 = ‘0000’+msg.payload[0].toString(16);\nvar data_hex2 = ‘0000’+msg.payload[1].toString(16);\nvar value\nvar data_hex = data_hex1.substr(-4) + data_hex2.substr(-4);\n\nvar name\nswitch(msg.modbusRequest.address)\n{\n case “2”:\n name = “Voltage”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE().toFixed(2)*1\n break;\n case “3”:\n name = “Electric_current”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE().toFixed(2)*1\n break;\n case “5”:\n name = “Power”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE()/1000\n value = value.toFixed(2)*1\n break;\n case “0”:\n name = “Energy_used”\n value = Buffer.from(data_hex, ‘hex’).readUInt32BE().toFixed(2)/10\n break;\n case “12”:\n name = “Power_factor”\n value = Buffer.from(data_hex, ‘hex’).readUInt32BE()\n}\n\nvar data={}\ndata[${name}]=value\nmsg.payload = data;\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:570,“y”:360,“wires”:[[“eba64408.074a58”]]},{“id”:“957b0b6f.a3ed48”,“type”:“json”,“z”:“81e76ded.e0413”,“name”:"",“property”:“payload”,“action”:“str”,“pretty”:false,“x”:970,“y”:380,“wires”:[[“f91ba44a.58eff8”]]},{“id”:“eba64408.074a58”,“type”:“join”,“z”:“81e76ded.e0413”,“name”:"",“mode”:“custom”,“build”:“merged”,“property”:“payload”,“propertyType”:“msg”,“key”:“topic”,“joiner”:"\n",“joinerType”:“str”,“accumulate”:false,“timeout”:"",“count”:“5”,“reduceRight”:false,“reduceExp”:"",“reduceInit”:"",“reduceInitType”:"",“reduceFixup”:"",“x”:590,“y”:460,“wires”:[[“d722f760.e15338”,“5894f214.8dd50c”]]},{“id”:“d722f760.e15338”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“阶梯电价”,“func”:"// 通过当月月份判断阶梯一的阈值\nfunction Get_level_One_threshold(){\n var Month = new Date().getMonth() + 1\n if (Month >= 5 && Month <= 10) {\n return 260\n } else {\n return 200\n }\n}\n// 返回计算结果函数\nfunction Result_obj(){\n Total_cost = Level_One_cost + Level_Two_cost + Level_Three_cost\n return {\n “Level_One”:{\n “used”:Level_One_used,\n “univalent”:Level_One_univalent,\n “cost”:Level_One_cost.toFixed(2)*1\n },\n “Level_Two”:{\n “used”:Level_Two_used,\n “univalent”:Level_Two_univalent,\n “cost”:Level_Two_cost.toFixed(2)*1\n },\n “Level_Three”:{\n “used”:Level_Three_used,\n “univalent”:Level_Three_univalent,\n “cost”:Level_Three_cost.toFixed(2)*1\n },\n “Total_cost”: Total_cost.toFixed(2)*1\n }\n}\n\nvar energy_used = msg.payload.Energy_used\n\nvar Level_Two = false\nvar Level_Three = false\n\nvar Level_One_cost = 0\nvar Level_Two_cost = 0\nvar Level_Three_cost = 0\nvar Total_cost = 0\n\nvar Level_One_used = 0\nvar Level_Two_used = 0\nvar Level_Three_used = 0\n\n// 阶梯一电费单价\nvar Level_One_univalent=0.61886875\n// 阶梯二电费单价\nvar Level_Two_univalent=0.66886875\n// 阶梯三电费单价\nvar Level_Three_univalent=0.91886875\n// 获取阶梯一阈值\nvar Level_One_threshold = Get_level_One_threshold()\n// 获取阶梯二阈值\nvar Level_Two_threshold = 600\n\n// 阶梯一\nif (energy_used > Level_One_threshold ) {\n Level_One_used = Level_One_threshold\n Level_One_cost = Level_One_used * Level_One_univalent\n}\nelse {\n Level_One_used = energy_used\n Level_One_cost = Level_One_used * Level_One_univalent\n msg.payload = Result_obj()\n return msg;\n}\n\n// 阶梯二和三\nif (energy_used > Level_Two_threshold ) {\n Level_Two_used = Level_Two_threshold\n Level_Two_cost = Level_Two_threshold * Level_Two_univalent\n Level_Three_used = energy_used - Level_One_threshold - Level_Two_threshold\n Level_Three_cost = Level_Three_used * Level_Three_univalent\n}\nelse {\n Level_Two_used = energy_used - Level_One_threshold\n Level_Two_cost = Level_Two_used * Level_Two_univalent\n}\n\n\nmsg.payload = Result_obj()\nreturn msg",“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:760,“y”:500,“wires”:[[“55a05fc8.7e3f7”,“c7e70174.ed65d”]]},{“id”:“616b1c75.c18f54”,“type”:“mqtt in”,“z”:“81e76ded.e0413”,“name”:“刷新”,“topic”:“DDSD720-L/Refresh”,“qos”:“2”,“datatype”:“auto”,“broker”:“db831950.868148”,“x”:110,“y”:500,“wires”:[[“b2364e74.d1caf”,“6b28b516.68074c”,“5fc3ed1f.eee5b4”,“bb4c64c4.ea99f8”,“84a63db2.65fdb”]]},{“id”:“55a05fc8.7e3f7”,“type”:“json”,“z”:“81e76ded.e0413”,“name”:"",“property”:“payload”,“action”:“str”,“pretty”:false,“x”:910,“y”:460,“wires”:[[“4c7b061.150b8f8”]]},{“id”:“4c7b061.150b8f8”,“type”:“mqtt out”,“z”:“81e76ded.e0413”,“name”:"",“topic”:“DDSD720-L/cost”,“qos”:“0”,“retain”:“true”,“broker”:“db831950.868148”,“x”:1070,“y”:460,“wires”:[]},{“id”:“5894f214.8dd50c”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“计算当天用电量”,“func”:"\nvar zeroTime_Energy_used = context.get(‘zeroTime_Energy_used’);\nvar date = context.get(‘zeroTime_Energy_date’);\n// 如果当前触发时间是0点,并且存储在节点变量日期不是当前日期,则记录下当前的度数\n// 作为当日初始度数。\nif ( new Date().getHours() == 0 && date != new Date().getDate() ){\n zeroTime_Energy_used = msg.payload.Energy_used;\n context.set(‘zeroTime_Energy_used’,zeroTime_Energy_used)\n context.set(‘zeroTime_Energy_date’,new Date().getDate())\n}\n// 当前用电量-今日用电量=今日用电量\nvar Today_Energy_Used = (msg.payload.Energy_used - zeroTime_Energy_used).toFixed(2)*1;\nmsg.payload.Today_Energy_Used = Today_Energy_Used;\nreturn msg;",“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:810,“y”:380,“wires”:[[“957b0b6f.a3ed48”]]},{“id”:“84a63db2.65fdb”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L功率因数”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“12”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:380,“y”:540,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“f91ba44a.58eff8”,“type”:“mqtt out”,“z”:“81e76ded.e0413”,“name”:"",“topic”:“DDSD720-L/data”,“qos”:“0”,“retain”:“true”,“broker”:“db831950.868148”,“x”:1150,“y”:360,“wires”:[]},{“id”:“c7e70174.ed65d”,“type”:“debug”,“z”:“81e76ded.e0413”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:990,“y”:560,“wires”:[]},{“id”:“8cd8bbe4.7ebef8”,“type”:“cronplus”,“z”:“81e76ded.e0413”,“name”:“每10分钟执行一次”,“outputField”:“payload”,“timeZone”:"",“persistDynamic”:false,“commandResponseMsgOutput”:“output1”,“outputs”:1,“options”:[{“name”:“每10分钟执行一次”,“topic”:“每10分钟执行一次”,“payloadType”:“str”,“payload”:"",“expressionType”:“cron”,“expression”:“0 0/10 * * * ? “,“location”:””,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”}],“x”:110,“y”:360,“wires”:[[“b2364e74.d1caf”,“6b28b516.68074c”,“bb4c64c4.ea99f8”,“5fc3ed1f.eee5b4”,“84a63db2.65fdb”]]},{“id”:“26fd2f5d.e1cab”,“type”:“modbus-client”,“z”:"",“name”:"",“clienttype”:“tcp”,“bufferCommands”:true,“stateLogEnabled”:false,“queueLogEnabled”:false,“tcpHost”:“192.168.31.38”,“tcpPort”:“2020”,“tcpType”:“DEFAULT”,“serialPort”:"/dev/ttyUSB",“serialType”:“RTU-BUFFERD”,“serialBaudrate”:“9600”,“serialDatabits”:“8”,“serialStopbits”:“1”,“serialParity”:“none”,“serialConnectionDelay”:“100”,“unit_id”:“1”,“commandDelay”:“1”,“clientTimeout”:“1000”,“reconnectOnTimeout”:true,“reconnectTimeout”:“2000”,“parallelUnitIdsAllowed”:true},{“id”:“db831950.868148”,“type”:“mqtt-broker”,“z”:"",“name”:“hassio-mqtt-HA”,“broker”:“127.0.0.1”,“port”:“1883”,“clientid”:“nodered-client”,“usetls”:false,“compatmode”:true,“keepalive”:“60”,“cleansession”:true,“birthTopic”:"",“birthQos”:“0”,“birthPayload”:"",“closeTopic”:"",“closeQos”:“0”,“closePayload”:"",“willTopic”:"",“willQos”:“0”,“willPayload”:""}]

N大给力,我刚改好水电装上,白嫖美滋滋。 :star_struck:

流导入不了,另我没有你的电表 没法调试。

flows.json (9.7 KB)
感谢大神的回复,文件我上传你看看,如果可以我去找你,我应该离你很近。

居然是转Ha的。。。。

依然坚持使用 HA, :stuck_out_tongue:

N大,流里没有图片上的月初清零,能给一下么,谢谢 :pray: