记录一下这几天关于南方电网电价设置的折腾。
南方电网的阶梯峰谷电价逻辑是:
1、先判断是夏季还是非夏季。这两种情况的阶梯度数是不同的。夏季的123阶梯分别是{260,600,600+},非夏季的123阶梯分别是{200,400,600+}
- platform: template
sensors:
current_ladder:
unique_id: "current_ladder"
friendly_name: "当前阶梯"
unit_of_measurement: "级"
icon_template: mdi:elevation-rise
value_template: >
{% if now().month in [5,6,7,8,9,10] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float <= 260 or now().month in [1,2,3,4,11,12] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float <= 200 %}
1
{% elif now().month in [5,6,7,8,9,10] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float > 260 and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float <= 600 or now().month in [1,2,3,4,11,12] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float > 200 and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float <= 400 %}
2
{% elif now().month in [5,6,7,8,9,10] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float > 600 or now().month in [1,2,3,4,11,12] and states('sensor.ju_wei_ben_yue_yong_dian_liang') | float > 400 %}
3
{% endif %}
2、判断当前时间点是峰平谷。南网这边0:00-8:00是谷电,(8:00-10:00,19:00-24:00)是平点,其他的时间是峰电
3、然后设置峰平谷基础电价分别是,峰:1.148,谷:0.2633,平:0.6788。
4、默认基础电价就是第一阶梯,2阶梯就+0.05,3阶梯就+0.3
- platform: template
sensors:
real_time_electricity_price:
unique_id: "real_time_electricity_price"
friendly_name: "实时电价"
unit_of_measurement: "CNY/kWh"
icon_template: mdi:currency-jpy
value_template: >
{% set now_H = now().strftime("%H") | int %}
{% set price1 = 0.2633 %}
{% set price2 = 0.6788 %}
{% set price3 = 1.148 %}
{% if now_H >= 0 and now_H < 8 %}
{% if states("sensor.current_ladder")=="1" %}
{{ price1 }}
{% elif states("sensor.current_ladder")=="2" %}
{{ price1 + 0.05 }}
{% elif states("sensor.current_ladder")=="3" %}
{{ price1 + 0.3 }}
{% endif %}
{% elif now_H >= 8 and now_H < 10 or now_H >= 19 and now_H < 24 %}
{% if states("sensor.current_ladder")=="1" %}
{{ price2 }}
{% elif states("sensor.current_ladder")=="2" %}
{{ price2 + 0.05 }}
{% elif states("sensor.current_ladder")=="3" %}
{{ price2 + 0.3 }}
{% endif %}
{% else %}
{% if states("sensor.current_ladder")=="1" %}
{{ price3 }}
{% elif states("sensor.current_ladder")=="2" %}
{{ price3 + 0.05 }}
{% elif states("sensor.current_ladder")=="3" %}
{{ price3 + 0.3 }}
{% endif %}
{% endif %}
|