I have experienced this problem with “blips” on a HA restart (my sensor is a NodeMCU with a Tasmota Counter linked to an optical sensor reading electricity meter LED pulses). The graphs and data below show how my daily usage surged from 55.3 to 77283.3 during an update of HA to version 104.1 earlier today.
I have attempted to work around the problem with the following sensor template config which only accepts a new meter reading if it is greater then the previous reading (this should hopefully prevent the meter from going to zero momentarily and then returning to normal which causes the spike):
meter_reading:
friendly_name: Electricity Meter Reading
unit_of_measurement: kWh
value_template: >
{% set current = states('sensor.meter_reading') | float | round(1) %}
{% set new = (states('sensor.nodemcu01_counter_c1') | float / 1000.0) | round(1) %}
{% macro max(X, Y) -%} {{X|float if X|float > Y|float else Y|float }} {%- endmacro %}
{{ max(current, new) }}
The reason for the divide by 1000 on the counter is to convert the pulses into units (i.e. kWh).
My Utility Meter config is:
utility_meter:
energy_usage_hour:
source: sensor.meter_reading
cycle: hourly
tariffs:
- std
energy_usage_day:
source: sensor.meter_reading
cycle: daily
tariffs:
- std
energy_usage_month:
source: sensor.meter_reading
cycle: monthly
tariffs:
- std