找回密码
 立即注册

微信扫码登录

搜索
查看: 113|回复: 0

[基础教程] 关于河南地区实时电价计量实体创建的方法

[复制链接]

7

主题

134

回帖

839

积分

高级会员

积分
839
金钱
698
HASS币
0
发表于 3 天前 | 显示全部楼层 |阅读模式
由于我家属于电采暖的用户,每年分为两个计价周期,每个一二三阶。在论坛翻阅了一波都是以月份为周期的,我写了一个以某月某天为周期的,供大家参阅,借花献佛,应该是拿来可以直接用的。参考了dscao的文章:https://bbs.hassbian.com/forum.php?mod=viewthread&tid=13796&highlight=%E5%AE%9E%E6%97%B6%E7%94%B5%E4%BB%B7

- platform: template
    sensors:
      dang_qian_jie_ti:
        value_template: 
          {% set now_dt = now() %}
          {% set warm_season_start = now_dt.replace(month=3, day=15, hour=0, minute=0, second=0, microsecond=0) %}
          {% set warm_season_end = now_dt.replace(month=11, day=15, hour=0, minute=0, second=0, microsecond=0) %}

          {% set is_warm_season = (now_dt >= warm_season_start and now_dt < warm_season_end) %}
          {% set total_energy = states("sensor.dian_biao_energy") | float(0) %}

          {% if is_warm_season %}
            {% if total_energy <= 1440 %}
              1
            {% elif total_energy <= 2080 %}
              2
            {% else %}
              3
            {% endif %}
          {% else %}
            {% if total_energy <= 720 %}
              4
            {% elif total_energy <= 1040 %}
              5
            {% else %}
              6
            {% endif %}
          {% endif %}
        friendly_name: '当前阶梯'
        unit_of_measurement: "L"
month=3, day=15,是你周期开始的月份和天,input_number.chu_shi_dian_jie_xiao_zhun,增加了个首次添加传感器校验前期用电量的数值辅助,可以自己手动在辅助元素里添加一个,更换成自己的。
template:
  - sensor:
      - name: "家庭实时电价"
        unique_id: home_realtime_electricity_price
        state: >
          {% set now_dt = now() %}
          {% set warm_start = now_dt.replace(month=3, day=15) %}
          {% set warm_end = now_dt.replace(month=11, day=15) %}
          
          {% set manual_offset = states('input_number.chu_shi_dian_jie_xiao_zhun') | float(0) %}
          
          {% if now_dt >= warm_start and now_dt < warm_end %}
            {% set total_energy = (states('sensor.seasonal_energy_warm') | float(0)) + manual_offset %}
            {% if total_energy <= 1440 %}
              0.56
            {% elif total_energy <= 2080 %}
              0.61
            {% else %}
              0.86
            {% endif %}
          {% else %}
            {% set total_energy = (states('sensor.seasonal_energy_cold') | float(0)) + manual_offset %}
            {% if total_energy <= 720 %}
              0.56
            {% elif total_energy <= 1040 %}
              0.61
            {% else %}
              0.86
            {% endif %}
          {% endif %}
        unit_of_measurement: "元/kWh"
        device_class: monetary
        icon: mdi:currency-cny






回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-10-29 03:46 , Processed in 0.230419 second(s), 5 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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