I need to create a sensor to computing the latest change in value of another source sensor.
The source sensor may update once a day few minutes after 6:00 AM, but doesn’t update necessarly every day.
Basically I want the sensor return the height of the step in the following plot in the last 24 hours, if any, or zero otherwise.
Yes, I want the change in value, the height of the step in the plot in the last 24h, if any.
The issue come from the fact the source sensor maybe doesn’t change the value every day, so maybe there are not 2 sample in the past 24 hours.
Yes, then the derivative sensor is exactly what you want. Your other option is to built an automation that takes the state change so you can plop the number into a sensor.
For piecewise constant function like the one plotted, the derivative (or “rate of change”) is zero almost everywhere. At the steps you can’t even compute derivative (in classical way, without resorting to distributions and Dirac’s Delta).
I understand now you are not referring to a statistics platform sensor with change_second as state_characteristic and not even to a derivative in a mathematical meaning but to another derivative platform. I’ll have a look.
It’s definitely not a mathematical derivative and not even an approximation of a mathematical derivative if the “time window” is big.
It’s something we can maybe call the difference quotient. The derivative would be the limit of the this difference quotient when the increment goes to zero.
But a picewise constant function as in my plot, as a discontinuous function, is not differentiable in classical mode, and if it were (in the meaning of generalized function aka distributions), its derivative will be zero almost everywhere.
Anyway, thanks for pointing me in the direction of this “derivative” sensor.
Change the unit of measurement. If you’re using d then it divides it by the number of hours minutes and seconds in the day. This is why I’ve been trying to get you to read the docs on this sensor. It has many config option, all spelled out to get the results in the units you want.
Edit, not unit of measurement, unit time iirc. I don’t have the docs in front of me atm
I read the documentation 4d ago when I understood you were referring to a derivative platform/sensor.
My understanding was that this sensor computed or estimated the derivative of source sensor, so useless for my needs, because the derivative is exactly zero a.e. or undefined, definitely not what I was looking for.
You pointed out that with a “big” time_window this derivative sensor can behave differently and I gave it a try.
After testing, I’m always convinced this platform try estimate the derivative with some interpolation of the actual data, using maybe more than two data point, that’s way I get a non integer result.
I don’t see any way of changing the settings to get what I need from this platform. Basically we come back to what I wrote 4d ago:
Ok, you can try a template sensor based on a state trigger. Subtract the difference between the to and from state. But the value won’t persist over restart. Or do the same thing in an automation that sets an input number that will persist over shutdown.
The state trigger doesn’t add so much to current incomplete implementation. The idea of input_number and automation was my first idea but it’s not concise or elegant.
Really there is no other way to do and no one else has ever done something similar?