larsen
(Lars)
August 19, 2024, 5:31pm
1
I want to create a bar chart on total_consumed from sensor attrubutes for each day.
I don’t understand how to code the filter.
The date attribute seems to have no name? The state indicate number of attributes (dates)
I made some templating to try to understand the data:
{% for d in states.sensor.ev9_daily_driving_stats.attributes %}
{% set e = state_attr('sensor.ev9_daily_driving_stats',d).total_consumed%}
Thanks!
larsen
(Lars)
October 26, 2024, 7:55am
2
Finally got something to work. I guess it can be beautified, but it works.
The data format is meta[date][‘climate’].
type: custom:plotly-graph
layout:
xaxis:
type: text
autorange: true
fixedrange: false
yaxis:
rangemode: tozero
fixedrange: true
entities:
- entity: sensor.ev9_daily_driving_stats
unit_of_measurement: Wh
name: Climate
type: bar
filters:
- fn: "({xs, ys, meta}) => {\n const r={ xs: [], ys: []}; for (let i=0; i < Object.keys(meta).length; i++) { r.ys.push(meta[Object.keys(meta)[i]]['climate_consumption']); r.xs.push(Object.keys(meta).slice(0,-2)[i]); } return \_r }"
title: Climate
A tip to get a quick overview of the Hass attributes in JS:
type: custom:plotly-graph
entities:
- entity: sensor.ev9_daily_driving_stats
filters:
- store_var: myvar
- fn: console.log
Press F12 / Console / Last entry / vars / myvar / meta