Replies: 3 comments 5 replies
-
If I understood everything correctly, statistics would be a perfect fit (because of the aligned timestamps that will allow you to stack them). Except that you want to have the highest resolution possible, and also the last known value should be used for as long as there is no new value available. |
Beta Was this translation helpful? Give feedback.
2 replies
-
I underestimated your request a bit, but I think this is what you want: type: custom:plotly-graph-dev
entities:
- entity: sensor.temperature_humidity_sensor_9c2e0c_temperature
- entity: sensor.teich_temperature
- entity: sensor.temperature_humidity_sensor_9c2e0c_temperature
lambda: (ys)=>ys
type: line
- entity: sensor.teich_temperature
type: line
lambda: (ys)=>ys
layout:
barmode: stack
hours_to_show: 0.1
defaults:
entity:
type: bar
lambda: |-
(ys, xs, entities) => {
const second = 1000;
const minute = second * 60;
const hour = minute * 60;
const day = hour * 24;
const deltas = [
// using discrete steps to minimize the chance
// that the traces missalign
// [max total span in ms, resolution],
[Number.POSITIVE_INFINITY, 1*day],
[1*day, 1*hour],
[1*hour, 1*minute],
[10*minute, 1*second],
]
const from_ms = +xs[0];
const to_ms = +xs[xs.length-1];
const span = to_ms - from_ms;
let delta_t;
for (const [max_span, resolution] of deltas){
if (span < max_span) delta_t = resolution;
}
console.log(span, delta_t)
const aligned = { x:[], y:[] };
// rounding to force alignment
let t = Math.floor(from_ms/delta_t)*delta_t;
console.log({entity: entities[0].entity_id, span, from_ms, to_ms, delta_t, start_t: t});
let last_y;
let i = 0;
while (t < to_ms){
let acc = 0;
let count = 0;
while (i<xs.length && t >= xs[i]) {
if (ys[i]!== null){
acc += ys[i];
count++;
}
i++;
}
if (count > 0 ) last_y = acc/count;
aligned.x.push(new Date(t))
aligned.y.push(last_y)
t += delta_t;
}
return aligned;
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Since the readme is not 100% specific:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, so I've been pestering maintainer on HA forums, and I though I will take this discussion here for posterity.
I would like to create a graph where certain power consumption figures are stacked on top of each other.
However trying to use some of examples of lambdas bares no good results :( Issues for me are three fold:
Stuff that I would like to achieve in lambda is:
Beta Was this translation helpful? Give feedback.
All reactions