谢谢,我用这个弄培正的阶梯,检查了好几遍不知道哪里的问题,ha重启没提示错误,但是实体出不来。用老的写法没问题。
template:
- sensor:
- name: "dqjt"
unique_id: "dqjt"
friendly_name: '当前阶梯'
unit_of_measurement: "级"
state: >
{% if states("sensor.monthly_energy") | float <= 230 %}
1
{% elif states("sensor.monthly_energy") | float >230 and states("sensor.monthly_energy") | float <= 420 %}
2
{% elif states("sensor.monthly_energy") | float > 420 %}
3
{% else %}
4
{% endif %}
- name: "ssdj"
unique_id: "ssdj" #UID(必须)
friendly_name: '实时电价' #在前端显示的传感器昵称(可选)
unit_of_measurement: "元/kWh" #传感器数值的单位(可选)
icon_template: mdi:currency-jpy #默认图标
state: >
{% if now().strftime("%H")| int >= 8 and now().strftime("%H")|int < 22 and states("sensor.dqjt")=="1" %}
0.5283
{%elif now().strftime("%H")| int >= 8 and now().strftime("%H")|int < 22 and states("sensor.dqjt")=="2" %}
0.5783
{%elif now().strftime("%H")| int >= 8 and now().strftime("%H")|int < 22 and states("sensor.dqjt")=="3" %}
0.8283
{% elif states("sensor.dqjt")=="1"%}
0.2983
{% elif states("sensor.dqjt")=="2" %}
0.3483
{% elif states("sensor.dqjt")=="3" %}
0.5983
{% endif %}
|