你好问下:
用你的这个写法已经实现了,昨日电量和上月电量。
还有实现了本月电费:
- name: "benyuedianfei"
unit_of_measurement: Yuan
state: >
{% set onedianjia=0.4983 %}
{% set twodianjia=0.05 %}
{% set threedianjia=0.25 %}
{% set onedianlian=230 %}
{% set twodianlian1=420 %}
{% set twodianlian2=420 %}
{% set two1month=[1,2,3,4,5,6,7,8,9,10,11,12] %}
{% if now().month in two1month %}
{% set twodianlian=twodianlian1 %}
{% else %}
{% set twodianlian=twodianlian2 %}
{% endif %}
{% if states("sensor.ben_yue_yong_dian") | float > twodianlian %}
{% set threedianfei= (states("sensor.ben_yue_yong_dian") | float - twodianlian) * threedianjia %}
{% else %}
{% set threedianfei=0 %}
{% endif %}
{% if states("sensor.ben_yue_yong_dian") | float > onedianlian %}
{% set twodianfei= (states("sensor.ben_yue_yong_dian") | float - onedianlian) * twodianjia %}
{% else %}
{% set twodianfei=0 %}
{% endif %}
{{ (states("sensor.ben_yue_yong_dian") | float * onedianjia + twodianfei + threedianfei) | round(2) }}
但是现在碰到的问题是,上月电费不知道咋弄。。
我按上月电量的逻辑这样写不行:
- name: "shangyuedianfei"
unit_of_measurement: Yuan
state: >
{{(state_attr("sensor.benyuedianfei","last_period") | float)| round(3)}}
很疑惑,求解答!感谢! |