If you change the time scale you will see the steps again. The beauty of a spline is that it connects the dots without having to over sample which makes the database larger than necessary.
Personally, I don’t mind the temperature steps.
@tom_l graham is right - try to delete the DB and when you have a few readings, you’ll see the steps, but it’ll become smoother as instead of say, 1 hour your graph will show you 1 day so because of that stretch/compress you see/don’t see fine details.
My sensor sends readings every 50s
And yes, I know why it’s staircase style and it doesn’t really bother me but I presume for displaying in frontend some would prefer something nicer
You missed the point.
Ok, I don’t mind asking - could you explain what I missed?
With a lot of temperature sensors, you don’t get to choose update frequency, they send a value when there’s a significant difference, in order to save battery.
For under $10 you can build an ESPHome temperature and humidity sensor you can put anywhere in the house that has a power point and get updates every second if you wish.
This is not relevant to this topic. I have provided a workaround to produce a spline plot for slow changing data. You may not appreciate it but others do. Please do not claim that oversampling is a solution.
Hey man if you want to plot fake data knock yourself out.
What you call "fake’ is better known as interpolation. I did some research and ran a Python program
to show you different types of interpolation used when plotting graphs.
On this graph, the orange dots are the real data points from the sensor.
The blue is the HA staircase. An interpolation between the data points consisting of a horizontal followed by a vertical line.
The green is the linear interpolation drawn when HA plots an input_number.
The dashed orange line is a cubic interpolation. It connects the points in an even smoother way but would probably be a challenge to implement running code on a Raspberry PI.
Here is the code used to produce the above plot:
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
x = np.array([0,1,2,2,3,3,4,4,5,5,6,7])
y = np.array([0,0,0,1,1,2,2,1,1,0,0,0])
xs = np.array([0,1,2,3,4,5,6,7])
ys = np.array([0,0,1,2,1,0,0,0])
f = interp1d(xs, ys)
f2 = interp1d(xs, ys, kind='cubic')
xnew = np.linspace(0, 7, num=41, endpoint=True)
# Staircase
plt.plot(x, y)
# Splines
plt.plot(xs, ys, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')
plt.legend(['stair', 'cubic','linear',], loc='best')
plt.show()
You can use it to see interpolation for other data points.
I have created a new post in “Share Your Project” which is a guide for smoother plots.
linear plots or spline graphs used to be the default for all data plots/graphs back about 50 or so major versions ago.
I actually want the opposite of what is described here. I have an input_number and want to plot it as a staircase instead of a spline. The value it is plotting is the number of people at home, so interpolated values don’t make a lot of sense there and actually make the graph harder to read. Has anyone found a way of setting the chart type for a graph? Or is the only solution to make a template sensor, since those appear to be plotted as a staircase chart.
Make a template sensor.
Hi Graham, thanks! I was thinking the same, but this isn’t making a graph at all:
This is simply a template sensor with value_template set to the input_number state. Can’t imagine what I’m doing wrong here… Might you have an idea?
you need to define a unit of measurement (in customize I think) for the graph to show up.
The graph looks this way because the “unit of measurement” is unknown. Simple to fix using HA frontend. Go to the bottom of the “Configuration” page and then “Customization”. Find your sensor and change the “unit of measurement” to, say “People”.
Or use the older method with this added to your .yaml code:
sensor.people_at_home:
friendly_name: People at Home
icon: mdi:person-supervisor
unit_of_measurement: People
squirtbrnr, Graham, thanks for the explanation. I really did not expect the unit of measurement to have any impact aside from actually denoting it in the UI. Regardless, it’s working perfectly now! Still I think it would be nice to be able to configure how to graph a value in some other way instead of making parallel input_number/template sensors, but for now it definitely gets the job done
I am also missing the step/staircase option a lot.
Templating ist a quirky workaround to generete another sensor with addidtional date I do not need.
In the picture you see the target and the measured temperature. The target ist updated only on rare occasions, which is just fine. With this data the spline interpolation is pretty useless. Steps/staircase representation would reduce the need for redundant data.
cheers
Just a heads up, there is an open feature request (from myself) to at least allow some customizability for display.
Especially since switching from stepped to linear is 1 parameter in chartjs!
I am now at 2022.8.5
Both sensor and input number are plotted as a staircase.
This workaround to plot with spline now longer works.
Hi,
I use some AI on the Edge ESP32-CAM based digitizers for analog water and power meters. These send data points with current value and the rate derived from the change between two previous measurements and the time between them.
The rate data is plotted by HA as a staircase plot with the step drawn as vertical line at the new value’s position (I guess “post” is the drawing style term).
For rate data calculated by the device it would reflect the data visually much better if a the vertical line (the change) would be drawn at the previous data point’s position (“pre”).
I udnerstand, that the ebst “post”/“pre” plot behaviour is dependent on the sensor.
An easy to configure plot style per sensor would be great. Maybe even have line connections instead of staricase plots or only data points?