The time entity is as far as I understand it supposed to create these spikes. But sometimes the time stops counting but also does not reset to 0.
Wednesday - Thursday.
I can see the same pattern on my usage graph.
It is the toothbrush that does not send the data.
I think it happens when I miss the turn off when cycling the states on the brush and then linger a bit on the state selected instead before trying to find the off state again.
This happened to me yesterday and that resulted in the stuck time.
The correct solution would probably be to cycle the toothbrush again, but that requires a manual intervention.
In HA you are up against one of the basic designs, which is a state is kept until a new one is reported.
Restarting the integration will not help, because it just picks up the old value again.
My guess is that in your stuck periods there are in reality no sensors values at all, so if you use a statistic sensor on a range in that stuck time, then you will not get a result and that might be something you can use to make a template sensor that act as you want.
I don’t actually believe that is true.
The 0-ing of the value happens long after the toothbrush goes to sleep (as far as I can see), something in the integration says to keep the value or drop it to 0.
Long time ago the integration always did as we see here, retain the value and then quickly drop it to 0 when a new session started.
Some change has been made in the integration to make it do as it does.
I think the 0-ing happens when the next data is actually received from the toothbrush, which could be a regular update or maybe a battery update, like when the toothbrush is again fully charged.