Derivative sensor doesnt update when no value change

Hi,
I created a derivative sensor which derives my water counter sensor to see immediate water consumption in m3/hour.

It works,except one significant detail. Derivative sensor doesnt update when there is no update in the source sensor (which is expected behavior).
The result is the derivative never shows zero value. And this is a problem.

So my problem is that I need to update the source sensor periodically to trigger derivative sensor recalculation. I tried the trick with adding an attribute to the source/template sensor, but it does not trigger update.

Any suggestions appreciated, David


Your attribute template only generates values between 0 and 5 so might this be the problem? I do know this works as I’m using this successfully in several places (not with derivative but with integration though).

Why not just use “{{ now() }}”?

Edit: wait! Do you have a trigger on your template-sensor? Won’t update otherwise. You should be able to see the result of you efforts in the “last_updated” attribute of your template-sensor in devtools.

I am having a similar issue with the derivative sensor that i have for my gas meter. Keen to know how to resolve this.

There has been a change to this. I’ve had my gas consumption meter set up like this for a few years and it broke some time ago:

- platform: derivative
  name: Hourly Gas Consumption
  source: sensor.gas_consumption
  time_window: '1:00:00'

This is either a known issue or an intended behavior, depending on your perspective.

There was a PR that looks like it would resolve this issue, but was closed as stale for sitting too long without attention: Fix derivative integration sample leave time window by FlorianOosterhof · Pull Request #110689 · home-assistant/core · GitHub

of course…

Hello, I’m also having this issue and it is really annoying to have a false instant consumption value when the indexes from which this is calculated do not increase (which means instant consumption should be 0)

FlorianOosterhof apparently you made some work on this in your commit that was closed, could you resubmit it if it works ?

Or if it works we could use it as a custom integration to replace the faulty built-in integration.

I’m amazed that this is still an issue after all this time. And apparently if someone submitted a fix for it.

There was an architecture change to add a last_reported property and state_reported event, and so the devs are likely waiting for a PR which utilizes that property. It would be essentially identical to the PR that was just merged in 2024.7 to do the same thing for the Riemann Sum integration.

I think Florian’s PR may have addressed some other issues also, so he’d have to modify that PR to utilize the new event while keeping his other improvements.

Edit: there was also another PR merged in 2024.7 for the Riemann sum integration to add the max_sub_interval configuration option. We need that change as well for the derivative integration.