Binary sensor bar chart "on" duration #286
Chavife
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Something like this; type: custom:plotly-graph
hours_to_show: 10d
entities:
- entity: switch.teich_pumpe_switch
unit_of_measurement: hours
filters:
- resample: 1m
- fn: |
({xs, ys}) => {
const result = {
xs: [],
ys: [],
};
let last = new Date(xs[0]);
last.setHours(0,0,0,0);
let hours = 0
for (let i = 0; i < xs.length+1; i++){
let curr = new Date(xs[i]);
curr.setHours(0,0,0,0);
if (+last !== +curr) {
result.xs.push(last);
result.ys.push(hours);
last = curr;
hours = 0;
}
if (ys[i] === "on") hours += 1/60;
}
return result;
} It resamples to every minute so we can count instead of subtracting timestamps (lazy but it works), then just count how many datapoints are "on", and add them all up by day. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to create a bar chart from my binary sensor which would show the duration of
on
time in bar charts.The use case is to track the "Do not disturb" sensor from my phone which I turn on/off when going to sleep and I wake up.
I want to see how much I slept each day.
The sensor is changing from
off
topriority_only
I cant figure out how to show the durations of the
priority_only
durations in bar chart.Beta Was this translation helpful? Give feedback.
All reactions