看了论坛几位大佬写的PZEM-004T 电表,自己也尝试的做了一个,自己写了点简单的配置,希望有用,有不足的请更正请教。
具体制作就不说了,论坛上有非常非常详细的攻略,我也时按攻略制作。
攻略参照:
https://bbs.hassbian.com/thread-5634-1-1.html
https://bbs.hassbian.com/thread-6081-1-1.html
主要注意的地方,刷好tasmota 固件,设置完后,再控制台里输入 timezone 8 同步时区。这样模块读取的发给HA为实时的时间,也为后面统计数据做准备
本篇主要为配置上海区的峰谷时电价配置,主要看到F大也写过配置,但看过配置和北京地区的电价资费时,发现和上海完全不同。
北京电价为每月阶梯电价,每月归零,而且居民用电没有峰谷时,而上海电价为全年阶梯电价,居民用电含峰谷电价。
和北京阶梯电价规则的可以参考F大的帖子:
https://bbs.hassbian.com/thread-6435-1-1.html
上海阶梯电价目前还没发完毕,已过了几个月,无法得知用了多少电,只能知道目前处于第几档的电价。
代码部分如下
sensor:
#电表-第一相
#总电量
- platform: mqtt
name: "electric_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Total }}"
unit_of_measurement: "KWH"
#昨日电量
- platform: mqtt
name: "zuori_dianliang_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Yesterday }}"
unit_of_measurement: "KWH"
#今日电量
- platform: mqtt
name: "jinri_dianliang_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Today }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "gonglv_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Power }}"
unit_of_measurement: "W"
- platform: mqtt
name: "yinshu_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Factor }}"
unit_of_measurement: " "
- platform: mqtt
name: "dianya_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Voltage }}"
unit_of_measurement: "V"
- platform: mqtt
name: "dianliu_1"
state_topic: "tele/S8/SENSOR"
value_template: "{{value_json['ENERGY'].Current }}"
unit_of_measurement: "A"
#电表-第二相
#总电量
- platform: mqtt
name: "electric_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Total }}"
unit_of_measurement: "KWH"
#昨日电量
- platform: mqtt
name: "zuori_dianliang_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Yesterday }}"
unit_of_measurement: "KWH"
#今日电量
- platform: mqtt
name: "jinri_dianliang_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Today }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "gonglv_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Power }}"
unit_of_measurement: "W"
- platform: mqtt
name: "yinshu_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Factor }}"
unit_of_measurement: " "
- platform: mqtt
name: "dianya_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Voltage }}"
unit_of_measurement: "V"
- platform: mqtt
name: "dianliu_2"
state_topic: "tele/S9/SENSOR"
value_template: "{{value_json['ENERGY'].Current }}"
unit_of_measurement: "A"
#电表-第三相
#总电量
- platform: mqtt
name: "electric_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Total }}"
unit_of_measurement: "KWH"
#昨日电量
- platform: mqtt
name: "zuori_dianliang_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Yesterday }}"
unit_of_measurement: "KWH"
#今日电量
- platform: mqtt
name: "jinri_dianliang_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Today }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "gonglv_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Power }}"
unit_of_measurement: "W"
- platform: mqtt
name: "yinshu_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Factor }}"
unit_of_measurement: " "
- platform: mqtt
name: "dianya_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Voltage }}"
unit_of_measurement: "V"
- platform: mqtt
name: "dianliu_3"
state_topic: "tele/S10/SENSOR"
value_template: "{{value_json['ENERGY'].Current }}"
unit_of_measurement: "A"
#总电量
- platform: template
sensors:
zong_dianliang:
value_template: >
{{states("sensor.electric_1")|float + states("sensor.electric_2")|float + states("sensor.electric_3")|float | round(2)}}
unit_of_measurement: "KWH"
#今日总电量
- platform: template
sensors:
jinri_zong_dianliang:
value_template: >
{{states("sensor.jinri_dianliang_1")|float + states("sensor.jinri_dianliang_2")|float + states("sensor.jinri_dianliang_3")|float | round(2)}}
unit_of_measurement: "KWH"
#昨日总电量
- platform: template
sensors:
zuori_zong_dianliang:
value_template: >
{{states("sensor.zuori_dianliang_1")|float + states("sensor.zuori_dianliang_2")|float + states("sensor.zuori_dianliang_3")|float | round(2)}}
unit_of_measurement: "KWH"
#总功率
- platform: template
sensors:
zong_gonglv:
value_template: >
{{states("sensor.gonglv_1")|float + states("sensor.gonglv_2")|float + states("sensor.gonglv_3")|float | round(2)}}
unit_of_measurement: "W"
#每天峰谷电费
- platform: template
sensors:
dianfei_daily_feng: #峰时
value_template: >
{{(states("sensor.daily_energy_peak") | float * 0.677) | round(2)}}
unit_of_measurement: "RMB"
- platform: template
sensors:
dianfei_daily_gu: #谷时
value_template: >
{{(states("sensor.daily_energy_offpeak") | float * 0.337) | round(2)}}
unit_of_measurement: "RMB"
#每月峰谷电费
- platform: template
sensors:
dianfei_monthly_feng: #峰时
value_template: >
{{(states("sensor.monthly_energy_peak") | float * 0.677) | round(2)}}
unit_of_measurement: "RMB"
- platform: template
sensors:
dianfei_monthly_gu: #谷时
value_template: >
{{(states("sensor.monthly_energy_offpeak") | float * 0.337) | round(2)}}
unit_of_measurement: "RMB"
#今日总电费
- platform: template
sensors:
daily_zong_dianfei:
value_template: >
{{states("sensor.dianfei_daily_feng")|float + states("sensor.dianfei_daily_gu")|float | round(2)}}
unit_of_measurement: "RMB"
#本月总电费
- platform: template
sensors:
monthly_zong_dianfei:
value_template: >
{{states("sensor.dianfei_monthly_feng")|float + states("sensor.dianfei_monthly_gu")|float | round(2)}}
unit_of_measurement: "RMB"
#峰谷电价-------------------------------------------------------------------------------------------------------------------------
utility_meter:
energy:
source: sensor.zong_dianliang
cycle: monthly
daily_energy:
source: sensor.energy
cycle: daily
tariffs:
- peak
- offpeak
monthly_energy:
source: sensor.energy
cycle: monthly
tariffs:
- peak
- offpeak
#自动化区分峰谷时----------6点~22点(峰时),22点~6点(第二天)(谷时)-------------------------------------------------------------------------------------------------------------
- alias: fengshidianjia
trigger:
- platform: time
at: '06:00:00'
- platform: time
at: '22:00:00'
action:
- service: utility_meter.next_tariff
entity_id: utility_meter.daily_energy
- service: utility_meter.next_tariff
entity_id: utility_meter.monthly_energy
由于我家时三相四线进户,所以由3个模块检测3路,单相的自行去除相加的 总数配置。0.677/0.337为上海的第二档峰谷电价。
目前不完美,全年的自动阶梯价格,只能等明年元旦重置数据。坑挖的比较大。
目前还不知道怎么写,也请教大佬们怎么写剩下的。
|