Filtering utility meter

I need more details on that statement @tom_l.

Because: well, would the availability template also help in this case which bothers me MASSIVELY:

  1. Smart plug has value 10 kWh
  2. Smart Plug wrongly sends (or the integration reads) 6 kWh when the host restarts (HA OS / ZigBee addon is started)
  3. Smart Plug wrongly sends (or the integration reads) 10 kWh again shortly after
  4. Utility meters count the difference of 4 kWh as consumption → all utility meter based entities, additional cost entities and of course the energy dashboard are broken. I need to hurry and fix that which takes at least one hour per incident

Here is a real-life example from yesterdays latest incident:

Raw

With values

Checking the database (STATES table) via

SELECT *
FROM "states"
WHERE metadata_id=(SELECT metadata_id FROM states_meta WHERE entity_id="sensor.xyz_total_consumption")
AND state_id>=478149319 AND state_id<=480677946
ORDER BY state_id ASC;

gives

So therefore I plan to “copy” the raw/input sensor (the smart plug giving false values on HA OS restarts) via a template sensor and use that “filtered”, “drop-free” template sensor as input sensor for my utility meter sensors (where one of them - the total sensor - is also used in the energy dashboard):

raw input sensor from device --> template sensor --> utility meter based sensors --> energy dashboard

The important question now is:

Would it be enough to filter out for the unavailable “input sensor from device”?

Based on the database query I don’t think so, as the availability template would help filter out the unavailable input sensor state. But my problem here is the next state 47.01 before the correct 50.72 follows next. So I think I would need to filter out the 47.01 (overall: lower values) instead of or additionally to the unavailable state.

The community guide is not a help topic so I have moved your post here.

Your problem isn’t the state transition 50 → unavailable or unavailable → 47. The problem is the transition from 47 → 50.

This is difficult to filter out. See this topic: I cannot for the life of me get the utility meter to reset to zero each day