我是照着这个 大神帖子里面的代码复制的 家庭用电量及电费统计模块 (Home Assistant 、Node-RED、MQTT综合应_NAS存储_什么值得买 (smzdm.com)复制后我重启就报错了 这个是哪里有问题啊?
sensor:
#本月电费
- platform: template
sensors:
zong_dianfei:
value_template: >
{% set dianlian=states("sensor.tasmota_energy_total") | float %}
{% set onedianjia=0.588 %}
{% set twodianjia=0.05 %}
{% set threedianjia=0.25 %}
{% set onedianlian=200 %}
{% set twodianlian1=350 %}
{% set twodianlian2=450 %}
{% set two1month=[4,5,6,10,11,12] %}
{% if now().month in two1month %}
{% set twodianlian=twodianlian1 %}
{% else %}
{% set twodianlian=twodianlian2 %}
{% endif %}
{% if dianlian > twodianlian %}
{% set threedianfei= (dianlian - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if dianlian > onedianlian %}
{% set twodianfei= (dianlian - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{% set zong_dianfei=dianlian * onedianjia + twodianfei + threedianfei %}
{% if(zong_dianfei>0) %}
{{ zong_dianfei | round(2) }}
{% endif %}
friendly_name: 'zong_dianfei'
unit_of_measurement: "RMB"
#今日电费,本月电费-本月今天以前的电费
- platform: template
sensors:
jintian_dianfei:
value_template: >
{% set dianlian=states("sensor.tasmota_energy_total") | float %}
{% set jintiandianlian=states("sensor.tasmota_energy_today") | float %}
{% set onedianjia=0.588 %}
{% set twodianjia=0.05 %}
{% set threedianjia=0.25 %}
{% set onedianlian=200 %}
{% set twodianlian1=350 %}
{% set twodianlian2=450 %}
{% set two1month=[4,5,6,10,11,12] %}
{% if now().month in two1month %}
{% set twodianlian=twodianlian1 %}
{% else %}
{% set twodianlian=twodianlian2 %}
{% endif %}
{% if dianlian > twodianlian %}
{% set threedianfei= (dianlian - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if dianlian > onedianlian %}
{% set twodianfei= (dianlian - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{% set zongdianfei= dianlian * onedianjia + twodianfei + threedianfei %}
{% set before_dianliang= dianlian - jintiandianlian %}
{% if before_dianliang > twodianlian %}
{% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if before_dianliang > onedianlian %}
{% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{% set before_dianfei= before_dianliang * onedianjia + twodianfei + threedianfei %}
{% set jintian_dianfei=zongdianfei - before_dianfei %}
{% if(jintian_dianfei>0) %}
{{ jintian_dianfei | round(2) }}
{% endif %}
friendly_name: 'jintian_dianfei'
unit_of_measurement: "RMB"
#昨日电费,本月今天以前的电费-本月昨天以前的电费
- platform: template
sensors:
zuotian_dianfei:
value_template: >
{% set dianlian=states("sensor.tasmota_energy_total") | float %}
{% set jintiandianlian=states("sensor.tasmota_energy_today") | float %}
{% set zuotiandianlian=states("sensor.tasmota_energy_yesterday") | float %}
{% set onedianjia=0.588 %}
{% set twodianjia=0.05 %}
{% set threedianjia=0.25 %}
{% set onedianlian=200 %}
{% set twodianlian1=350 %}
{% set twodianlian2=450 %}
{% set two1month=[4,5,6,10,11,12] %}
{% if now().month in two1month %}
{% set twodianlian=twodianlian1 %}
{% else %}
{% set twodianlian=twodianlian2 %}
{% endif %}
{% set before_dianliang= dianlian - jintiandianlian %}
{% if before_dianliang > twodianlian %}
{% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if before_dianliang > onedianlian %}
{% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{% set before_dianfei= before_dianliang * onedianjia + twodianfei + threedianfei %}
{% set zuotian_before_dianliang= dianlian - jintiandianlian - zuotiandianlian %}
{% if zuotian_before_dianliang > twodianlian %}
{% set threedianfei= (zuotian_before_dianliang - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if zuotian_before_dianliang > onedianlian %}
{% set twodianfei= (zuotian_before_dianliang - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{% set zuotian_before_dianfei= zuotian_before_dianliang * onedianjia + twodianfei + threedianfei %}
{% set zuotian_dianfei = before_dianfei - zuotian_before_dianfei %}
{% if zuotian_dianfei>0 %}
{{ zuotian_dianfei | round(2) }}
{% endif %}
friendly_name: 'zuotian_dianfei'
unit_of_measurement: "RMB"
#计量清零
automation:
- id: 'monitor_clear'
alias: 月初清零电表
initial_state: true
hide_entity: false
trigger:
- platform: template
value_template: '{{ states("sensor.tasmota_energy_today") | 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'
这个是帖子里面的代码
这是我 这里现在的阶梯价格表
|