3D graph for sensor per day #391
Replies: 10 comments 14 replies
-
Yes it should be possible. Good luck! |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you for the reply. |
Beta Was this translation helpful? Give feedback.
-
type: custom:plotly-graph
entities:
- entity: sensor.electricity_usage
period: hour
statistic: max
fn: |
$fn ({ xs, ys, vars }) => {
const hours = Array.from({ length: 24 }, (_, i) => `${i}:00`);
const days = Array.from({ length: 365 }, (_, i) => i + 1);
const maxValues = Array.from({ length: 366 }, () => Array(24).fill(null));
for (let i = 0; i < xs.length; i++) {
const date = new Date(xs[i]);
const hour = date.getHours();
const dayOfYear = Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 86400000)-1;
const currentValue = +ys[i];
if (maxValues[dayOfYear][hour] === null || currentValue > maxValues[dayOfYear][hour]) {
maxValues[dayOfYear][hour] = currentValue;
}
}
vars.x = hours;
vars.y = days;
vars.z = maxValues;
}
x: $fn ({ vars }) => vars.x
'y': $fn ({ vars }) => vars.y
z: $fn ({ vars }) => vars.z
type: surface
raw_plotly_config: true
hours_to_show: 1y
title: Solar Energy Output Over the Year
layout:
height: 600
margin:
t: 50
l: 50
r: 50
b: 50
scene:
xaxis:
title: Hour of Day
yaxis:
title: Day of Year
zaxis:
title: Max Energy Output (kWh)
let me suggest you to do some iterations with chatGPT, it should be able to explain you what all the gibberish means :) |
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply and code. |
Beta Was this translation helpful? Give feedback.
-
Oke, that makes sort of sense... |
Beta Was this translation helpful? Give feedback.
-
Thank you for the help! |
Beta Was this translation helpful? Give feedback.
-
Kept open so it's easier to find |
Beta Was this translation helpful? Give feedback.
-
@dbuezas "Maybe this gets you started" Sure these examples do work with the current version? I tried a couple of the examples recently and failed by 100% when trying to turn a lambda into a filter. So I felt dead lucky to see an example without lamba, but the result makes not much of a differnce at all. It does print the titlebar, that's it. |
Beta Was this translation helpful? Give feedback.
-
Very great, thanks for your work, @dbuezas ! the working one and the other one:
BTW: There's no such thing like putting large images into spoilers here, isn't it?! |
Beta Was this translation helpful? Give feedback.
-
Got an idea, since when reading this it's very identical to what I run into with something completely differnt. And the issue I got with these is that by chance 50:50 the card content remains blank. So I gave it a try with the code from @michas79de and well ..... it works as expteced. And I bet google can't do much about that since they didn't invent the lovelace view styles. And for reference .... the problem does exist here since perhaps 3-4 months ... looks to me as if being driven to migrate to the unbeloved new Sections views. :-) Perhaps @dbuezas could check that? Till now I still thought it might be my fancy custom button card problem but now I found a second way to validate my own issue. |
Beta Was this translation helpful? Give feedback.
-
Hi,
First of all this add-on looks very promising! The amount of options is huge, giving us a lot to play with. However I do have troubles starting with a graph I would love to create. The idea is as the image below. I have the amount of energy generated with my solar panels and i would like to be able to plot them per day over time. So the X-axis should be the days, the Y-axis the years and the Z-axis should be the amount of energy. The data is stored in a MariaDB (SQL) with one value per hour, so two columns: date (YYMMDD hh:mm:ss) and the recorded amount of energy.
Is it possible to create such a graph?
With many thanks,
Jeroen
Beta Was this translation helpful? Give feedback.
All reactions