|
我用的是PZEM-004刷的tasmota固件。当时按照论坛的教程配置的hass,当时一切正常,通过电费模板可以按照用电量自动核算阶梯电费。
后来hass不断的升级新版本,忘了是升级哪个hass版本后,发现计算电费的的模板始终是按照最高的阶梯电价来计算电费的,而且看了的系统日志,也有这方面的警告提示,但无奈水平有限,不知道怎么解决。寻求坛友帮助
提示错误信息的日志:
WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'unknown' when rendering 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.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 250) or (date == 0 and states("sensor.dianbiaoelectric") | int > 250) %} {{(states("sensor.dianbiaoelectric") | float * 0.82) | round(2)}} {% elif (date != 0 and (states("sensor.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 170) or (date == 0 and states("sensor.dianbiaoelectric") | int > 170) %} {{(states("sensor.dianbiaoelectric") | float * 0.57) | round(2)}} {% else %} {{(states("sensor.dianbiaoelectric") | float * 0.52) | round(2)}} {% endif %}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2022.1
现在配置的代码:
sensor:
####电表电量####
#电压传感器
- platform: mqtt
name: "dianbiaodianya"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "V"
value_template: "{{ value_json['ENERGY'].Voltage }}"
#电流传感器
- platform: mqtt
name: "dianbiaodianliu"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "A"
value_template: "{{ value_json['ENERGY'].Current }}"
#功率传感器
- platform: mqtt
name: "dianbiaogonglv"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "W"
value_template: "{{ value_json['ENERGY'].Power }}"
#功率因数传感器
- platform: mqtt
name: "dianbiaogonglvyinshu"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "cosΦ"
value_template: "{{ value_json['ENERGY'].Factor }}"
#电表箱温度
- platform: mqtt
name: "dianbiaowendu"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "℃"
value_template: "{{ value_json['AHT1X-0x38'].Temperature }}"
#电表箱湿度
- platform: mqtt
name: "dianbiaoshidu"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "%"
value_template: "{{ value_json['AHT1X-0x38'].Humidity }}"
#今天用电量
- platform: mqtt
name: "dianbiaojinri_dianliang"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Today }}"
#今日电费
- platform: template
sensors:
dianbiaojinri_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.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 250) or (date == 0 and states("sensor.dianbiaoelectric") | int > 250) %}
{{(states("sensor.dianbiaojinri_dianliang") | float * 0.82) | round(2)}}
{% elif (date != 0 and (states("sensor.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 170) or (date == 0 and states("sensor.dianbiaoelectric") | int > 170) %}
{{(states("sensor.dianbiaojinri_dianliang") | float * 0.57) | round(2)}}
{% else %}
{{(states("sensor.dianbiaojinri_dianliang") | float * 0.52) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
#昨天用电量
- platform: mqtt
name: "dianbiaozuori_dianliang"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Yesterday }}"
#昨日电费
- platform: template
sensors:
dianbiaozuori_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.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 250) or (date == 0 and states("sensor.dianbiaoelectric") | int > 250) %}
{{(states("sensor.dianbiaozuori_dianliang") | float * 0.82) | round(2)}}
{% elif (date != 0 and (states("sensor.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 170) or (date == 0 and states("sensor.dianbiaoelectric") | int > 170) %}
{{(states("sensor.dianbiaozuori_dianliang") | float * 0.57) | round(2)}}
{% else %}
{{(states("sensor.dianbiaozuori_dianliang") | float * 0.52) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
#总用电量
- platform: mqtt
name: "dianbiaoelectric"
state_topic: "tele/dianliang/SENSOR"
qos: 1
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Total }}"
state_class: 'total'
device_class: 'energy'
#总电费
- platform: template
sensors:
dianbiaozongdianfei:
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.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 250) or (date == 0 and states("sensor.dianbiaoelectric") | int > 250) %}
{{(states("sensor.dianbiaoelectric") | float * 0.82) | round(2)}}
{% elif (date != 0 and (states("sensor.dianbiaoelectric") | float - states("sensor.dianbiaojinri_dianliang") | float + (states("sensor.dianbiaozuori_dianliang") | float * (date + 1))) | int > 170) or (date == 0 and states("sensor.dianbiaoelectric") | int > 170) %}
{{(states("sensor.dianbiaoelectric") | float * 0.57) | round(2)}}
{% else %}
{{(states("sensor.dianbiaoelectric") | float * 0.52) | round(2)}}
{% endif %}
unit_of_measurement: "RMB"
|
|