本帖最后由 FrankLv 于 2019-2-24 22:18 编辑
前篇 :
long long ago,白老板 jlxwkj 建议我上个电量计量的设备来监测下家里的用电量和计算电费,但是一直搁置未做,主要原因之一是比较懒没去折腾,另外还要动强电 。
但最近白老板给我做了两个电量计量设备,既然做好了那就用吧,所以索性就直接给弄上了,由于安装过程没有拍照,所以没法放了,就放白老板做好的设备吧。这货体积比较小(还有外壳哦),我家强电箱可利用空间非常非常小的情况下都可以安装上,绝对的赞。
这玩意怎么弄的我是不清楚,我也不懂,有意可以咨询白老板或者搞他现成的
说了那么多,其实我是来分享配置的。
统一回复下:我是来分享配置的,我是来分享配置的,我是来分享配置的。设备我真的不知道,这个需要问白老板,也就是群里面的懵懂的小白
配置分享:
白老板一直想让我帮忙搞定阶梯电价,由于没有设备一直就没弄,既然设备有了那就需要做配置了 ,配置文件可能有考虑不周全的地方,或者有更好的建议,希望大家留言回复。
分享的配置如果你要使用的话需要修改两大部分,第一个是MQTT主题,第二个是阶梯电价部分,配置中使用的是北京的阶梯电价,需要修改为您所在区域的电价。
此配置可以实现电费的阶梯计算和每月统计数据自动清零。其中电费计算值,在每个月的最后一天才用总电量判断来获取阶梯电价计算得出,其他天数利用昨日电量结合总电量和今日电量判断来获取阶梯电价计算得出。这是我目前考虑到的最完美的解决方法;自动清零功能是在每个月的1号自动运行,实现昨日电量和总电量的置0。
sensor:
#电压传感器
- platform: mqtt
name: "dianya"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "V"
value_template: "{{ value_json['ENERGY'].Voltage }}"
#value_template: "{{ value_json.Voltage }}"
#电流传感器
- platform: mqtt
name: "dianliu"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "A"
value_template: "{{ value_json['ENERGY'].Current }}"
#value_template: "{{ value_json.Current }}"
#功率传感器
- platform: mqtt
name: "gonglv"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "W"
value_template: "{{ value_json['ENERGY'].Power }}"
#value_template: "{{ value_json.Power }}"
#功率因数传感器
- platform: mqtt
name: "gonglvyinshu"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "cosΦ"
value_template: "{{ value_json['ENERGY'].Factor }}"
#value_template: "{{ value_json.Factor }}"
#今天用电量
- platform: mqtt
name: "jinri_dianliang"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Today }}"
#value_template: "{{ value_json.Today }}"
#今日电费
- platform: template
sensors:
jinri_dianfei:
value_template: >
{% if now().month in [1,3,5,7,8,10,12] %}
{% set date = (31 - now().day) %}
{% elif now().month in [4,6,9,11] %}
{% set date = (30 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
{% set date = (28 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
{% set date = (29 - now().day) %}
{% endif %}
{% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
{{(states("sensor.jinri_dianliang") | float * 0.7783) | round(2)}}
{% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
{{(states("sensor.jinri_dianliang") | float * 0.5283) | round(2)}}
{% else %}
{{(states("sensor.jinri_dianliang") | float * 0.4783) | round(2)}}
{% endif %}
friendly_name: 'jinri_dianfei'
unit_of_measurement: "RMB"
#昨天用电量
- platform: mqtt
name: "zuori_dianliang"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Yesterday }}"
#value_template: "{{ value_json.Yesterday }}"
#昨日电费
- platform: template
sensors:
zuori_dianfei:
value_template: >
{% if now().month in [1,3,5,7,8,10,12] %}
{% set date = (31 - now().day) %}
{% elif now().month in [4,6,9,11] %}
{% set date = (30 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
{% set date = (28 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
{% set date = (29 - now().day) %}
{% endif %}
{% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
{{(states("sensor.zuori_dianliang") | float * 0.7783) | round(2)}}
{% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
{{(states("sensor.zuori_dianliang") | float * 0.5283) | round(2)}}
{% else %}
{{(states("sensor.zuori_dianliang") | float * 0.4783) | round(2)}}
{% endif %}
friendly_name: 'zuori_dianfei'
unit_of_measurement: "RMB"
#总用电量
- platform: mqtt
name: "electric"
state_topic: "tele/electric/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Total }}"
#value_template: "{{ value_json.Total }}"
#总电费
- platform: template
sensors:
zongdianfei:
value_template: >
{% if now().month in [1,3,5,7,8,10,12] %}
{% set date = (31 - now().day) %}
{% elif now().month in [4,6,9,11] %}
{% set date = (30 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
{% set date = (28 - now().day) %}
{% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
{% set date = (29 - now().day) %}
{% endif %}
{% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
{{(states("sensor.electric") | float * 0.7783) | round(2)}}
{% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
{{(states("sensor.electric") | float * 0.5283) | round(2)}}
{% else %}
{{(states("sensor.electric") | float * 0.4783) | round(2)}}
{% endif %}
friendly_name: 'zongdianfei'
unit_of_measurement: "RMB"
#计量清零
automation:
- id: 'monitor_clear'
alias: monitor_clear
initial_state: true
hide_entity: false
trigger:
# - platform: time
# at: '00:00:00'
- platform: template
value_template: '{{ states("sensor.jinri_dianliang") | round(3) == 0.000 }}'
condition:
- condition: template
value_template: '{{ (now().strftime("%d") | int) == 1 }}'
action:
- service: mqtt.publish
data:
topic: 'cmnd/electric/EnergyReset2'
payload: '0'
- service: mqtt.publish
data:
topic: 'cmnd/electric/EnergyReset3'
payload: '0'
group:
electric:
name: 总电量
view: no
entities:
- sensor.dianya
- sensor.dianliu
- sensor.gonglv
- sensor.gonglvyinshu
- sensor.jinri_dianliang
- sensor.jinri_dianfei
- sensor.zuori_dianliang
- sensor.zuori_dianfei
- sensor.electric
- sensor.zongdianfei
- automation.monitor_clear
homeassistant:
customize:
sensor.dianya:
friendly_name: 电压
icon: mdi:flash
homebridge_name: 机柜电压
homebridge_hidden: false
sensor.dianliu:
friendly_name: 电流
icon: mdi:flash-auto
homebridge_name: 机柜电流
homebridge_hidden: false
sensor.gonglv:
friendly_name: 功率
icon: mdi:wikipedia
homebridge_name: 功率
homebridge_hidden: false
sensor.gonglvyinshu:
friendly_name: 功率因数
icon: mdi:flash-red-eye
homebridge_name: 功率因数
homebridge_hidden: false
sensor.jinri_dianliang:
friendly_name: 今日电量
icon: mdi:flash
homebridge_name: 今日电量
homebridge_hidden: false
sensor.jinri_dianfei:
friendly_name: 今日电费
icon: mdi:currency-cny
homebridge_name: 今日电费
homebridge_hidden: false
sensor.zuori_dianliang:
friendly_name: 昨日电量
icon: mdi:flash
homebridge_name: 昨日电量
homebridge_hidden: false
sensor.zuori_dianfei:
friendly_name: 昨日电费
icon: mdi:currency-cny
homebridge_name: 昨日电费
homebridge_hidden: false
sensor.electric:
friendly_name: 总电量
icon: mdi:flash
homebridge_name: 总电量
homebridge_hidden: false
sensor.zongdianfei:
friendly_name: 总电费
icon: mdi:currency-cny
homebridge_name: 总电费
homebridge_hidden: false
automation.monitor_clear:
friendly_name: 计量清零
homebridge_name: 计量清零
homebridge_hidden: false
group.electric:
homebridge_hidden: false
复制代码
效果展示:
使用后的效果如下:
完结!