|
############
mqtt:
#电压传感器
sensor:
- name: "jiadianya"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "V"
value_template: "{{ value_json['ENERGY'].Voltage }}"
#电流传感器
- name: "jiadianliu"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "A"
value_template: "{{ value_json['ENERGY'].Current }}"
#功率传感器
- name: "jiagonglv"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "W"
value_template: "{{ value_json['ENERGY'].Power }}"
#功率因数传感器
- name: "jiagonglvyinshu"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "cosΦ"
value_template: "{{ value_json['ENERGY'].Factor }}"
#今天用电量
- name: "jiajinri_dianliang"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Today }}"
#昨天用电量
- name: "jiazuori_dianliang"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Yesterday }}"
#总用电量
- name: "jiaelectric"
state_topic: "tele/sonoff/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Total }}"
#今日电费
- platform: template
sensors:
jiajinri_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.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
{{(states("sensor.jiajinri_dianliang") | float * 0.9629) | round(2)}}
{% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
{{(states("sensor.jiajinri_dianliang") | float * 0.7129) | round(2)}}
{% else %}
{{(states("sensor.jiajinri_dianliang") | float * 0.6629) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
#昨日电费
- platform: template
sensors:
jiazuori_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.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
{{(states("sensor.jiazuori_dianliang") | float * 0.9629) | round(2)}}
{% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
{{(states("sensor.jiazuori_dianliang") | float * 0.7129) | round(2)}}
{% else %}
{{(states("sensor.jiazuori_dianliang") | float * 0.6629) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
#总电费
- platform: template
sensors:
jiazongdianfei:
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.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
{{(states("sensor.jiaelectric") | float * 0.9629) | round(2)}}
{% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
{{(states("sensor.jiaelectric") | float * 0.7129) | round(2)}}
{% else %}
{{(states("sensor.jiaelectric") | float * 0.6629) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
#计量清零
automation:
- id: 'monitor_clear'
alias: monitor_clear
initial_state: true
hide_entity: false
trigger:
- platform: template
value_template: '{{ states("sensor.jiajinri_dianliang") | round(3) == 0.000 }}'
condition:
- condition: template
value_template: '{{ (now().strftime("%d") | int) == 1 }}'
action:
- service: mqtt.publish
data:
topic: 'cmnd/sonoff/EnergyReset2'
payload: '0'
- service: mqtt.publish
data:
topic: 'cmnd/sonoff/EnergyReset3'
payload: '0'
#计量清零
# 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.jiajinri_dianliang") | round(3) == 0.000 }}'
# condition:
# - condition: template
# value_template: '{{ (now().strftime("%d") | int) == 1 }}'
# action:
# - service: mqtt.publish
# data:
# topic: 'cmnd/sonoff/EnergyReset2'
# payload: '0'
# - service: mqtt.publish
# data:
# topic: 'cmnd/sonoff/EnergyReset3'
# payload: '0'
# group:
# electric:
# name: 总电量
# view: no
# entities:
# - sensor.jiadianya
# - sensor.jiadianliu
# - sensor.jiagonglv
# - sensor.jiagonglvyinshu
# - sensor.jiajinri_dianliang
# - sensor.jiajinri_dianfei
# - sensor.jiazuori_dianliang
# - sensor.jiazuori_dianfei
# - sensor.jiaelectric
# - sensor.jiazongdianfei
# - automation.monitor_clear
homeassistant:
customize:
sensor.jiadianya:
friendly_name: 电压
icon: mdi:flash
# homebridge_name: 机柜电压
# homebridge_hidden: false
sensor.jiadianliu:
friendly_name: 电流
icon: mdi:flash-auto
# homebridge_name: 机柜电流
# homebridge_hidden: false
sensor.jiagonglv:
friendly_name: 功率
icon: mdi:wikipedia
# homebridge_name: 功率
# homebridge_hidden: false
sensor.jiagonglvyinshu:
friendly_name: 功率因数
icon: mdi:flash-red-eye
# homebridge_name: 功率因数
# homebridge_hidden: false
sensor.jiajinri_dianliang:
friendly_name: 今日电量
icon: mdi:flash
# homebridge_name: 今日电量
# homebridge_hidden: false
sensor.jiajinri_dianfei:
friendly_name: 今日电费
icon: mdi:currency-cny
# homebridge_name: 今日电费
# homebridge_hidden: false
sensor.jiazuori_dianliang:
friendly_name: 昨日电量
icon: mdi:flash
# homebridge_name: 昨日电量
# homebridge_hidden: false
sensor.jiazuori_dianfei:
friendly_name: 昨日电费
icon: mdi:currency-cny
# homebridge_name: 昨日电费
# homebridge_hidden: false
sensor.jiaelectric:
friendly_name: 总电量
icon: mdi:flash
# homebridge_name: 总电量
# homebridge_hidden: false
sensor.jiazongdianfei:
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
|
|