本帖最后由 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里date和kwh的值想做成图表卡片的形式显示出来。
想过用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部分怎么改都出不来数据,请求大神指点迷津
|