找回密码
 立即注册

微信扫码登录

搜索
查看: 280|回复: 5

[插件集成] 分享一个30日用电折线图卡片

[复制链接]

2

主题

16

回帖

98

积分

注册会员

积分
98
金钱
80
HASS币
0
发表于 3 天前 | 显示全部楼层 |阅读模式
用了cubicpil大大的南方电网电费数据HA集成(https://bbs.hassbian.com/thread-18578-1-1.html)和hunl1986大大的[UI界面] 记录南方电网集成UI界面使用(sensor和apexcharts-card卡片)(https://bbs.hassbian.com/forum.php?mod=viewthread&tid=21834&page=1&authorid=62030

image.png

具体代码:
type: grid
columns: 2
square: false
cards:
  - type: vertical-stack
    cards:
      - type: gauge
        entity: sensor.lastdate_power_2
        name: 昨日用电
        unit: kWh
        min: 0
        max: 1000
        severity:
          green: 0
          yellow: 300
          red: 600
        needle: true
  - type: vertical-stack
    cards:
      - type: gauge
        entity: sensor.curmonth_power_2
        name: 当月电量
        unit: kWh
        min: 0
        max: 1000
        severity:
          green: 0
          yellow: 300
          red: 600
        needle: true
type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.lastmonth_fee_2
        name: 上月电费
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.0800150051235490_arrears
        name: 欠缴电费
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.year_power_2
        name: 今年用电
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.year_fee_2
        name: 今年电费
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.lastyear_power_2
        name: 去年用电
      - hours_to_show: 24
        graph: none
        type: sensor
        detail: 1
        entity: sensor.lastyear_fee_2
        name: 去年电费
type: vertical-stack
cards:
  - type: grid
    columns: 3
    cards:
      - type: markdown
        content: >
          **📈 最高用电**

          <h3 style="color: #EF4444; margin: 5px 0;">{{
          (state_attr('sensor.history_day', 'history_day_value')[-30:] |
          map(attribute='kwh') | max) }} kWh</h3>

          <small style="color: #666;">

          {% set max_kwh = state_attr('sensor.history_day',
          'history_day_value')[-30:] | map(attribute='kwh') | max %}

          {% set max_date = state_attr('sensor.history_day',
          'history_day_value')[-30:] | selectattr('kwh', 'equalto', max_kwh) |
          map(attribute='date') | first %}

          {{ max_date[5:7] }}/{{ max_date[8:10] }}

          </small>
      - type: markdown
        content: >
          **📉 最低用电**

          <h3 style="color: #3B82F6; margin: 5px 0;">{{
          (state_attr('sensor.history_day', 'history_day_value')[-30:] |
          map(attribute='kwh') | min) }} kWh</h3>

          <small style="color: #666;">

          {% set min_kwh = state_attr('sensor.history_day',
          'history_day_value')[-30:] | map(attribute='kwh') | min %}

          {% set min_date = state_attr('sensor.history_day',
          'history_day_value')[-30:] | selectattr('kwh', 'equalto', min_kwh) |
          map(attribute='date') | first %}

          {{ min_date[5:7] }}/{{ min_date[8:10] }}

          </small>
      - type: markdown
        content: >
          **🎯 平均用电**

          <h3 style="color: #10B981; margin: 5px 0;">{{
          ((state_attr('sensor.history_day', 'history_day_value')[-30:] |
          map(attribute='kwh') | sum) / (state_attr('sensor.history_day',
          'history_day_value')[-30:] | length)) | round(1) }} kWh</h3>

          <small style="color: #666;">近30日平均</small>
  - type: custom:apexcharts-card
    header:
      show: true
      title: 📊 近30日用电趋势
    graph_span: 30d
    series:
      - entity: sensor.history_day
        type: line
        name: 日用电量
        color: "#8B5CF6"
        stroke_width: 3
        unit: kWh
        curve: smooth
        data_generator: |
          const dailyData = entity.attributes.history_day_value || [];
          const recentData = dailyData.slice(-30);
          return recentData.map(item => {
            const date = new Date(item.date);
            return [date.getTime(), parseFloat(item.kwh) || 0];
          });
    yaxis:
      - min: 0
        decimals: 1



评分

参与人数 2金钱 +15 收起 理由
Tamaki + 5 膜拜大神!
xiongmx + 10 感谢楼主分享!

查看全部评分

回复

使用道具 举报

2

主题

16

回帖

98

积分

注册会员

积分
98
金钱
80
HASS币
0
 楼主| 发表于 3 天前 | 显示全部楼层
再分享一个电价计算卡片
回复

使用道具 举报

2

主题

16

回帖

98

积分

注册会员

积分
98
金钱
80
HASS币
0
 楼主| 发表于 3 天前 | 显示全部楼层
Unripe3336 发表于 2025-10-16 11:40
再分享一个电价计算卡片
## 💰 本月电费分析
**{{ now().strftime('%Y年%m月') }}** · {{ (now().month in [5,6,7,8,9,10]) | iif('夏季', '冬季') }}电价

{% set daily_data = state_attr('sensor.0800150051235490_this_month_total_usage', 'this_month_by_day') %}
{% if daily_data is defined and daily_data %}
  {% set total_kwh = daily_data | map(attribute='kwh') | map('float') | sum %}
  {% set month = now().month %}
  {% set is_summer = month in [5,6,7,8,9,10] %}
  {% set phase1_price = 0.58886875 %}
  {% set phase2_price = 0.63886875 %}
  {% set phase3_price = 0.88886875 %}
  {% set phase1_power = 260 if is_summer else 200 %}
  {% set phase2_power = 600 if is_summer else 400 %}
  
  {% set phase1_fee = phase1_power * phase1_price %}
  {% set phase2_fee = phase1_fee + (phase2_power - phase1_power) * phase2_price %}
  
  {% if total_kwh <= phase1_power %}
    {% set total_fee = total_kwh * phase1_price %}
    {% set current_tier = 1 %}
  {% elif total_kwh <= phase2_power %}
    {% set total_fee = phase1_fee + (total_kwh - phase1_power) * phase2_price %}
    {% set current_tier = 2 %}
  {% else %}
    {% set total_fee = phase2_fee + (total_kwh - phase2_power) * phase3_price %}
    {% set current_tier = 3 %}
  {% endif %}
  
### 📊 核心指标
`{{ total_kwh | round(2) }}` **kWh** · `¥{{ total_fee | round(2) }}` **元** · 第{{ current_tier }}档 · {{ daily_data | length }}天数据

### ⚡ 电价阶梯 ({{ '夏季' if is_summer else '冬季' }})
| 档位 | 电量范围 | 单价 |
|------|----------|------|
| 第一档 | {{ phase1_power }} kWh以内 | {{ phase1_price }} 元/kWh |
| 第二档 | {{ phase1_power }}-{{ phase2_power }} kWh | {{ phase2_price }} 元/kWh |
| 第三档 | {{ phase2_power }} kWh以上 | {{ phase3_price }} 元/kWh |

### 📅 最近用电记录
{% for day in daily_data[-3:] %}
- **{{ day.date[-5:] }}**: `{{ day.kwh }}` kWh
{% endfor %}

{% else %}
### ❌ 数据暂不可用
请检查传感器数据更新
{% endif %}
image.png
image.png
回复

使用道具 举报

innx 手机认证

28

主题

237

回帖

2988

积分

论坛DIY达人

积分
2988
金钱
2718
HASS币
30
发表于 3 天前 | 显示全部楼层
好评
黑名单 icstow昵称朝廷心腹
回复

使用道具 举报

3

主题

82

回帖

442

积分

中级会员

积分
442
金钱
357
HASS币
0
发表于 3 天前 来自手机 | 显示全部楼层
如何显示是哪一天的电量
回复

使用道具 举报

1

主题

93

回帖

890

积分

高级会员

积分
890
金钱
791
HASS币
20
发表于 前天 01:53 | 显示全部楼层
感谢分享
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-19 19:08 , Processed in 0.055997 second(s), 10 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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