hunl1986 发表于 2023-7-3 01:13:05

记录南方电网集成UI界面使用(sensor和apexcharts-card卡片)

本帖最后由 hunl1986 于 2024-1-5 11:19 编辑

因cubicpil大大的南方电网电费数据HA集成(https://bbs.hassbian.com/thread-18578-1-1.html),免除我原来的电费接入的麻烦,但使用下来和自己习惯还是有点差别,所以自己微微优化了一下。

更改了一下传感器的代码,让每月1号不会显示错误


一、增加“上月电费”和"用电历史记录"两个传感器
**** Hidden Message *****

"用电历史记录"增加history_day_value属性,为上月的用电记录和本月用电记录合并(最主要用来查看最近30天用电记录,原集成的sensor.XXXXXXXXXXXX_latest_day_kwh用apexcharts-card卡片显示时不好用,sensor.XXXXXXXXXXXX_this_month_total_usage又只能看到当月,如果是在月初,只能看到几天的,不习惯)

二、UI界面显示


type: vertical-stack
cards:
- type: horizontal-stack
    title: 用电状态
    cards:
      - type: sensor
      entity: sensor.XXXXXXXXXXXX_this_month_total_usage
      name: 本月用电
      icon: mdi:home-lightning-bolt-outline
      - hours_to_show: 24
      graph: none
      type: sensor
      entity: sensor.XXXXXXXXXXXX_latest_day_kwh
      name: 昨天用电
      icon: mdi:home-lightning-bolt-outline
      detail: 1
      - hours_to_show: 24
      graph: none
      type: sensor
      entity: sensor.XXXXXXXXXXXX_arrears
      detail: 1
      icon: mdi:currency-jpy
      unit: 元
      name: 应交电费
- type: horizontal-stack
    cards:
      - type: sensor
      entity: sensor.XXXXXXXXXXXX_last_month_total_usage
      name: 上月用电
      icon: mdi:home-lightning-bolt-outline
      - hours_to_show: 24
      graph: none
      type: sensor
      entity: sensor.airpowerheatertemperature
      name: 上月电费
      detail: 1
      icon: mdi:currency-jpy
      unit: 元
- type: horizontal-stack
    cards:
      - type: sensor
      entity: sensor.XXXXXXXXXXXX_this_year_total_usage
      name: 本年用电
      icon: mdi:home-lightning-bolt-outline
      - hours_to_show: 24
      graph: none
      type: sensor
      entity: sensor.XXXXXXXXXXXX_this_year_total_cost
      name: 本年电费
      detail: 1
      icon: mdi:currency-jpy
      unit: 元
- type: horizontal-stack
    cards:
      - type: sensor
      entity: sensor.XXXXXXXXXXXX_last_year_total_usage
      icon: mdi:home-lightning-bolt-outline
      name: 上年用电
      - hours_to_show: 24
      graph: none
      type: sensor
      entity: sensor.XXXXXXXXXXXX_last_year_total_cost
      name: 上年电费
      detail: 1
      icon: mdi:currency-jpy
      unit: 元
- type: horizontal-stack
    cards:
      - type: custom:apexcharts-card
      header:
          show: true
          title: 30天用电与费用趋势图
      graph_span: 30d
      span:
          start: day
          offset: '-30d'
      series:
          - entity: sensor.history_day
            type: column
            name: 用电功率
            color: rgb(51,153,255)
            attribute: history_day_value
            data_generator: |
            return entity.attributes.history_day_value.map(entry => {
                return {
                  x: entry.date,
                  y: entry.kwh
                };
            });
          - entity: sensor.history_day
            name: 用电费用
            color: rgb(255,153,0)
            attribute: history_day_value
            data_generator: |
            return entity.attributes.history_day_value.map(entry => {
                return {
                  x: entry.date,
                  y: entry.kwh*0.65886875
                };
            });





wangmucha 发表于 2023-7-3 01:49:13

高手啊,膜拜下

kkk123 发表于 2023-7-3 08:04:58

本帖最后由 kkk123 于 2023-7-3 09:07 编辑

我添加后怎么出错呢

jasonkiddy2k 发表于 2023-7-3 09:34:54

感谢分享,学习一下

Ari 发表于 2023-7-3 09:36:51

老哥,这卡牌很好看,国网的能搞个吗

stlyt 发表于 2023-7-3 09:39:24

非常好,学习了

hdz 发表于 2023-7-3 10:21:37

感谢分享,学习一下

love2328 发表于 2023-7-3 11:34:58

我的还是登录了没内容

zone777777 发表于 2023-7-3 12:32:29

强大,学习,谢谢

jooney3123 发表于 2023-7-3 12:54:06

感谢分享,学习一下
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 记录南方电网集成UI界面使用(sensor和apexcharts-card卡片)