Energy meter counts backwards

I am using a utility meter (daily) to register my PV-energy. Sometimes, this daily meter counts backwards:

I figured out, this happens during restarts, when the source of the utility meter is not available. The utility_meter has the attribute “net_consumption” set to false → I expect it to count up only.

Is there a best practice pattern to handle this? Any hint welcome.

Show us the source sensor configuration. That’s where the issue is.

This are the entities involved:

template:
  - sensor:
      - name: pv_ed_ref_produce
        unique_id: pv_ed_ref_produce
        unit_of_measurement: kWh
        device_class: energy
        state_class:  total_increasing
        state: "{{ states ('sensor.pvse_ac_energy_kwh') }}"

utility_meter:
  pv_energy_daily:
    source: sensor.pv_ed_ref_produce
    cycle: daily
  • “pvse_ac_energy_kwh” is the energy value from the external integration (volatile during restart)
  • “pv_ed_ref_produce” is a local copy under history recording

I’m surprised this works at all. states(...) is a function but if you put a space before the brackets like this states (...) it is no longer a function.

Assuming this was a typo, your template sensor is just a copy of sensor.pvse_ac_energy_kwh, why?

What are you hoping to accomplish?

If it was just to add a state and or device class they can be added using customize. No need for a template sensor.

What does the history of sensor.pvse_ac_energy_kwh look like?

ok - good points!

Cleaned up the system to the simplest possible form:

  pv_energy_daily:
    source: sensor.pvse_ac_energy_kwh
    cycle: daily

Issue with utility_meter (count-down after restart) still the same: