本帖最后由 dscao 于 2023-2-6 22:30 编辑
这个思路也很好,对于年用电量统计不太准确的时候比较好用。另外可以简化成一个input,简化选择的人工操作。
input_select:
electric_price:
name: 'Electric Price'
options: #用电的3档价格,峰谷价用逗号分隔,第三部分可以当备注方便选择)
- 0.617,0.307
- 0.623,0.31,(第二档电价)
- 0.977,0.487,(第三档电价)
icon: mdi:currency-cny
template:
- sensor:
- name: "Electric Price"
unique_id: sensor_electric_price
icon: mdi:home-lightning-bolt
unit_of_measurement: 'CNY/kWh'
state: >
{% set current_hour = strptime(states('sensor.time'), "%H:%M").hour %} #获取当前时间
{% if current_hour > 6 and current_hour < 22 %} #如果是在6点后, 22点前
{{ states('input_select.electric_price') .split(",")[0]|float}} #使用峰用电价格
{% else %}
{{ states('input_select.electric_price') .split(",")[1]|float}} #使用谷用电价格
{% endif %}
|