我们是上海浦东,用的商业电,所以电费1元多/度,按峰谷两种电价计算
峰谷计费的代码昨天测试出来能读到数据,但是电量比实际仪表的总电量大出来很多
不知道是什么情况
另外,白天时间计的是谷电,晚上时间是峰电。正好相反了。
上面是读数据的界面
configuration.yaml 相关代码
sensor:
- platform: mqtt
name: "zong"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Total }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "zuotian"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Yesterday }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "jintian"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Today }}"
unit_of_measurement: "KWH"
- platform: mqtt
name: "gonglv"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Power }}"
unit_of_measurement: "W"
#功率因数传感器
- platform: mqtt
name: "yinshu"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Factor }}"
qos: 1
unit_of_measurement: "cosΦ"
- platform: mqtt
name: "dianya"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Voltage }}"
unit_of_measurement: "V"
- platform: mqtt
name: "dianliu"
state_topic: "tele/sonoff/SENSOR"
value_template: "{{value_json['ENERGY'].Current }}"
unit_of_measurement: "A"
#分时电费
- platform: template
sensors:
dianfei_daily_feng: #峰时
value_template: >
{{(states("sensor.daily_energy_peak") | float * 1.054) | round(2)}}
unit_of_measurement: "RMB"
- platform: template
sensors:
dianfei_daily_gu: #谷时
value_template: >
{{(states("sensor.daily_energy_offpeak") | float * 0.524) | round(2)}}
unit_of_measurement: "RMB"
#每月峰谷电费
- platform: template
sensors:
dianfei_monthly_feng: #峰时
value_template: >
{{(states("sensor.monthly_energy_peak") | float * 1.054) | round(2)}}
unit_of_measurement: "RMB"
- platform: template
sensors:
dianfei_monthly_gu: #谷时
value_template: >
{{(states("sensor.monthly_energy_offpeak") | float * 0.524) | 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:
zong_dianliang:
value_template: >
{{states("sensor.zong")|float | round(2)}}
unit_of_measurement: "KWH"
#今日总电量
- platform: template
sensors:
jinri_zong_dianliang:
value_template: >
{{states("sensor.jintian")|float | round(2)}}
unit_of_measurement: "KWH"
#本月总电费
- 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.jinri_zong_dianliang
source: sensor.energy
cycle: daily
tariffs:
- peak
- offpeak
monthly_energy:
source: sensor.energy
cycle: monthly
tariffs:
- peak
- offpeak
automations.yaml相关代码
- 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
|