i’ve tried the ‘easy’ way using derivative, but that doesn’t work correctly.
There is more to the problem…
the sensor is updated every ~10 sec but the value actually only changes every 5 minutes.
using derivative and setting the time_window option to 5 minutes makes it sometime miss the actual change because its not synced to the update frequency of the source sensor.
So actually i’m trying:
(gas meter reading.current - gas meter reading.“last changed value”) * 12 = m3/hour
@mafradon the algorithm you give would fail if there is no gas consumed in the 5 minute interval, it would then skip that value and read the next change, so the interval between reading.current and reading.“last changed value” would be 10 minutes in this case.
I’m struggling with the same issue. I have a smart utility meter reader (this one), which reports every 10 sec or so, but the utility meter only reports a new value every 5 minutes (which may be the same as the previous value when no gas is consumed in that interval)
The derivative integration is not the best approach I think, as setting a longer time_window smooths everything out, which is not what I am looking for. I actually want the difference between two consecutive reports of the original utility meter, which may be 0.
What I can think of is the following:
wait for a change in value, save the value
wait for a new change, for at most 5.5 minutes
if changed, report the change and wait again for a change for at most 5.5 minutes
if not changed within that 5.5 minutes, report 0 change at the 5 minute mark and wait again for at most 5.5 minutes since that mark
Some questions I have
is it possible to report a value for half a minute in the past at all?
I had the same issue, my workaround was to create a template sensor from the DSMR gas sensor. Because the template sensor only updates on a change in the source sensor the derivative from it can actually see 2 consecutive changing readings.
I’ve only been using HomeAssistant for a few weeks, so I’m certainly no expert. But what I understood during my InfluxDB integration is that HomeAssistant might only sends data when the value change. So I assumed it also only writes values to it’s internal sqlite database when the data is changed and therefor the template sensor only sees a change when the value from the source is actually different that the previous reading.
But I’ve not looked at the code yet. But when I attached the derivative sensor to the gas_consumption (DSMR integration) the graph looked strange and continuously went back to 0 since the gas sensor was updated once every 5min instead of the DSMR 10sec read interval I suppose.