『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1629|回复: 4

[技术探讨] 分享一个简单的实时电价实体(小白专用)。

[复制链接]

11

主题

77

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
684
HASS币
20
发表于 2022-11-11 17:05:14 | 显示全部楼层 |阅读模式
template:
  - sensor:

      - name: "feng_gu_dian_jia"
        state: >
           {% set L1 = 0.261 %}
           {% set L2 = 0.51 %}
           {% set L3 = 0.51 %}
           {% set L4 = 0.56 %}
           {% set L5 = 0.81 %}
           {% set d_l = states('sensor.sanxiang_dianbiao_energy_fan')  | float %}
           {% if 19<= now().strftime("%H") | int <24  or 7<= now().strftime("%H") | int <12 and now().strftime("%m")| int ==3 and now().strftime("%d")| int <=15 %}
             {{ L1 | float }}
           {% elif 19<= now().strftime("%H") | int <24  or 7<= now().strftime("%H") | int <12 and now().strftime("%m")| int ==11 and now().strftime("%d")| int >=15 %}
             {{ L1 | float }}
           {% elif 0<= now().strftime("%H") | int <7  or 12<= now().strftime("%H") | int <19 and now().strftime("%m")| int ==11 and now().strftime("%d")| int <15 %}
             {{ L5 | float }}
           {% elif 0<= now().strftime("%H") | int <7  or 12<= now().strftime("%H") | int <19 and now().strftime("%m")| int ==3 and now().strftime("%d")| int >15 %}
             {{ L5 | float }}
           {% elif 19<= now().strftime("%H") | int <24  or 7<= now().strftime("%H") | int <12 and  now().strftime("%m")| int in [12,1,2]  %}
             {{ L1 | float }}
           {% elif 0<= now().strftime("%H") | int <7  or 12<= now().strftime("%H") | int <19 and  3< now().strftime("%m")| int in [12,1,2]  %}
             {{ L2 | float }}
           {% elif d_l | float <= 166 %} 
             {{ L3 | float }}
           {% elif 166< d_l | float <= 240 %} 
             {{ L4 | float }}
           {% elif d_l | float > 240 %} 
             {{ L5 | float }}
           {% endif %}       
        unit_of_measurement: "元/kWh"
主要参考了:https://bbs.hassbian.com/forum.p ... =1&extra=#pid396177着篇帖子
j简单的解释下代码的含义方便大家修改。
其中实体头部定义了了L1-L5 5个常数分别代表了5个档位的阶梯电价,定义了一个变量d_l载入电量实体的值,我这里阶梯是按月算的所以我载入的是月电量。

{% if 19<= now().strftime("%H") | int <24 or 7<= now().strftime("%H") | int <12 and now().strftime("%m")| int ==3 and now().strftime("%d")| int <=15 %}
着一句判断了以下当前电量处于那个阶梯比如我这里采暖季没有峰谷电价,19点至24点,7至12点19是谷电价“<= now().strftime("%H") | int <24 or 7<= now().strftime("%H") | int <12”修改这个部分就可以,谷电价是从11月15日以后开始3月15日结束修改以下五处
1: now().strftime("%m")| int ==3 and now().strftime("%d")| int <=15     #3月15日以前
2: now().strftime("%m")| int ==11 and now().strftime("%d")| int >=15   # 11月15日以前
3: now().strftime("%m")| int ==11 and now().strftime("%d")| int <15     # 11月15日以后
4: now().strftime("%m")| int ==3 and now().strftime("%d")| int >15       #3月15日以后
5: now().strftime("%m")| int in [12,1,2]  #采暖季月份不含开始月和结束月因为开始和结束都不是整月开始的,开始和结束月通过上面4处定义。


然后是不同阶梯的用电量d_l | float <= 166 表示小于166度剩余的就是类推。
{{ L4 | float }} 返回了阶梯4的电价。


if语句请自行参阅论坛翻译的模板实体介绍。
回复

使用道具 举报

0

主题

562

帖子

2200

积分

金牌会员

Rank: 6Rank: 6

积分
2200
金钱
1638
HASS币
0
发表于 2022-11-11 20:27:14 | 显示全部楼层
点赞,这是最简单的实时电价了,再也不需要什么自动转换峰谷电
回复

使用道具 举报

1

主题

44

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
198
HASS币
0
发表于 2022-12-5 14:33:15 | 显示全部楼层
sensor.sanxiang_dianbiao_energy_fan这个传感器是哪儿来的啊,萌新不懂
回复

使用道具 举报

11

主题

77

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
684
HASS币
20
 楼主| 发表于 2022-12-10 10:22:15 | 显示全部楼层
zebradam 发表于 2022-12-5 14:33
sensor.sanxiang_dianbiao_energy_fan这个传感器是哪儿来的啊,萌新不懂

这个是你电表接入后生成的实体
回复

使用道具 举报

0

主题

18

帖子

128

积分

注册会员

Rank: 2

积分
128
金钱
110
HASS币
0
发表于 2023-9-12 13:06:53 | 显示全部楼层
感谢知识分享  对我们这些小白非常有用   谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-10 04:23 , Processed in 0.083790 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表