core: Energy cost sensors reset during HA restart even though the energy sensor they track do not.

The problem

In the energy dashboard, when adding a “price per kWh” sensor to an energy sensor, HA automatically creates a new costsensor. They both reset at midnight, which is fine.

However, if you restart Home Assistant, the cost resets to zero, even if the energy sensor does not. Below, I have restarted HA at ~13:00

Energy sensor (keeps increasing): energy

Cost sensor (has been reset): cost

What version of Home Assistant Core has the issue?

core-2022.9.7

What was the last working version of Home Assistant Core?

NA

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Energy

Link to integration documentation on our website

https://www.home-assistant.io/docs/energy

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

A link to the community post discussing this.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 15
  • Comments: 23 (1 by maintainers)

Most upvoted comments

This issue is unresolved as at 2023.12.2 Cost sensor resets to zero on system restart.

@hajo62 :

State_class of the monetary sensor is total while the sensor for the energy measurement is total_increasing

While the sensors with state class total should have a reset timestamp, the total_increasing sensors don’t have.

It needs to be discussed, if it is supposed that the monetary sensor is total - compared to the energy measurement sensor. Here, some explanation might be usefull why it is set to the state_class…

Workaround: Creating a Utility_Meter with the source of the monetary sensor could be used to create a sensor that never resets (or on a specified value (weekly, monthly, quarterly, yearly, etc.)

[EDIT] - wrongly mentioned the utility_meter would need a state_class: total_increasing here, which was wrong.