It was not exactly what i was looking for, as I wanted the chart to have limits at 25-17 °C and if these limits are exceeded than I wanted to expand the range just enough so that all the data-points fit, but I managed to do it with your help!
range: |
$fn ({ getFromConfig }) => {
const trackedEntities = getFromConfig("entities").filter(({ entity }) =>
entity.startsWith("sensor.pokoj_teplota") || entity.startsWith("sensor.loznice_teplota")
);
const all = trackedEntities.flatMap(({ y }) => y.filter(val => !isNaN(val) && val !== null));
return [
Math.min(17, Math.min(...all)), // cap to 17 but if the value is lover cap to that
Math.max(25, Math.max(...all)), // cap to 25 but if the value is higher cap to that
]
}
Also an added benefit of my approach is that it filters all non-number or null values so that if the sensor was offline or something (In my case I monitor temperature through ESP32 and my router restarts every night, because of reasons) it will ignore them and will adjust by the real values.
I’m attempting to migrate away from ApexCharts but I’m having trouble with one aspect.
In ApexCharts I can easily group by a time interval, then chart the difference between the first and last value in that group.
group_by:
func: diff
duration: 30min
I can almost replicate this in Plotly by using the below:
filters:
- resample: 30m
- delta
My issue is that I’d like to see the bar for the current 30 minute period updating live, whereas it doesn’t get displayed until the next 30 minute period starts.
Is there an easy approach I’m missing here?
The idea is to duplicate the last poit and move it 30 minutes into the future, so it falls in the next bar.
The minus 1 is there so that you don’t get a fake value if the plot is rendered on exactly the last millisecond of a 30 minutes block. It will be very funny if the whole thing doesn’t work but I was worried about something that has a 1 in 2 million chance of happening:
v3.3.3 Released with a couple of minor corrections and a fix to the yaxis grouping reported by @DarthSebulba04 (thank you!).
Next a fun statistic. I’m tracking downloads of this card via a Github integration in Home Assistant and plotting it with… you guessed it! this very card!
v3.3.1 Was downloaded 6907 times.
After two months, there were still an average of ~10 downloads/h.
2^7 stars ini total, but no new stars in the last month.
Is there anyway to autorange the y-axis to the data in the current view? I have a years worth of data but only show 1 week on load. I want the y-axis max to be the max of the data in view, not the whole data series.
edit:
Looks like I need to be using the “autorange_after_scroll: true” parameter however it doesn’t seem to adjust the max y axis for only data in view. I have a years worth of stacked bar charts and some data very far out pushes the max y axis high, then when I zoom into more recent data the max y axis doesn’t come down. Is this expected behavior?
Yes that’s the right thing to use. I think the issue is that you have an error in your filter: the block inside the if is missing the curly braces (probably because you’ve been doing a lot of python lately )
Wrong:
if (d > 0)
xx.push(d);
yy.push(value);
Right:
if (d > 0) {
xx.push(d);
yy.push(value);
}
What may be happening is that plotly is getting confused because the length of xx and yy differs.
Thanks for the help. It is true I have been using python a lot lately lol. I think my problem is between home and work I have to use too many different languages so I know just enough to be dangerous in all of them but it is hard to keep the syntaxs straight…
I fixed that and it doesn’t look like it solved the problem. Seems like maybe there is an issue with how I am using the filter block as when I remove the filter block and use another sensor it seems to work well.
Then I suggest you add another filter at the end - fn: console.log # open the devtools console to see the data
maybe there is something wrong with the xs an ys arrays?
These tips on debugging may be of use too