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

 找回密码
 立即注册
查看: 1422|回复: 1

[求助] 关于获取传感器属性值的问题求教大神

[复制链接]

7

主题

87

帖子

525

积分

高级会员

Rank: 4

积分
525
金钱
438
HASS币
0
发表于 2023-2-7 15:59:40 | 显示全部楼层 |阅读模式
本帖最后由 pomans 于 2023-2-7 16:03 编辑

自己用的hacs安装了china southern power grid statistics获取南网电费
这个集成获取的上月电费数据属性如下格式:

state_class: total
last_month_by_day:
  - date: '2023-01-01'
    kwh: 15.63
  - date: '2023-01-02'
    kwh: 17.61
  - date: '2023-01-03'
    kwh: 21.64
  - date: '2023-01-04'
    kwh: 17.93
  - date: '2023-01-05'
    kwh: 17.1
  - date: '2023-01-06'
    kwh: 17.82
  - date: '2023-01-07'
    kwh: 20.11
  - date: '2023-01-08'
    kwh: 19.13
  - date: '2023-01-09'
    kwh: 17.93
  - date: '2023-01-10'
    kwh: 25.16
  - date: '2023-01-11'
    kwh: 17.56
  - date: '2023-01-12'
    kwh: 16.91
  - date: '2023-01-13'
    kwh: 22.52
  - date: '2023-01-14'
    kwh: 33.11
  - date: '2023-01-15'
    kwh: 24.08
  - date: '2023-01-16'
    kwh: 22.72
  - date: '2023-01-17'
    kwh: 19.13
  - date: '2023-01-18'
    kwh: 22.55
  - date: '2023-01-19'
    kwh: 21.61
  - date: '2023-01-20'
    kwh: 21.08
  - date: '2023-01-21'
    kwh: 23.1
  - date: '2023-01-22'
    kwh: 22.73
  - date: '2023-01-23'
    kwh: 21.58
  - date: '2023-01-24'
    kwh: 21.38
  - date: '2023-01-25'
    kwh: 18.29
  - date: '2023-01-26'
    kwh: 19.9
  - date: '2023-01-27'
    kwh: 20.92
  - date: '2023-01-28'
    kwh: 22.07
  - date: '2023-01-29'
    kwh: 21.88
  - date: '2023-01-30'
    kwh: 21.01
  - date: '2023-01-31'
    kwh: 22.98
unit_of_measurement: kWh
device_class: energy
icon: mdi:lightning-bolt
friendly_name: 上月用电量
求教大神怎么提取属性last_month_by_day里datekwh的值想做成图表卡片的形式显示出来。

想过用Apexcharts-card显示本月每天的电费使用情况
参考了帖子https://bbs.hassbian.com/forum.p ... =%E7%94%B5%E8%B4%B9
想使用这部分代码显示:

type: vertical-stack
cards:
  - type: custom:apexcharts-card
    header:
      show: true
      title: 当月用电趋势图
    graph_span: 35d
    span:
      start: month
      offset: '-30d'
    series:
      - entity: sensor.everyday_power2
        data_generator: |
          return entity.attributes.date.map((item, index) => {
           return [new Date(item).getTime(), entity.attributes.power[index]];
          });
        extend_to: false
        float_precision: 2
        name: 每日电量(kWh)
实在不懂JS,data_generator部分怎么改都出不来数据,请求大神指点迷津

回复

使用道具 举报

0

主题

45

帖子

192

积分

注册会员

Rank: 2

积分
192
金钱
147
HASS币
0
发表于 2023-2-9 16:05:29 | 显示全部楼层
检查下entity.attributes.date的数据类型是不是Array
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-25 01:29 , Processed in 0.083311 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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