WTH does the cost of electricity reset after a system restart, when the energy sensor it is using to calculate does not?

This is one of my energy sensors (iotawatt on phase 1):
Screenshot 2022-10-04 at 13.04.09
It resets at midnight.

In the energy dashboard it is set to use another sensor (electricity price, that changes hour for hour) to calculate the cost. It then creates a new sensor with the cost by simply multiplying the two. So far so good, all as expected.

But if I restart HA, then the cost for the day is reset. This is the associated (automatically created by Home Assistant) cost sensor:
Screenshot 2022-10-04 at 13.04.31

At around 13:00/1pm I restarted HA, and you can see the cost for the day going to zero. However, as you can see from the energy graph, the energy use is not reset. Only the calculated price is.

WTH does it do that?

Can you share your price sensor config and it’s history over the same restart?

The price sensor is a custom sensor made in AppDaemon (since there is no good way to get the total price I pay, including taxes and the fees that are specific to my plan).

This is how it looks over time (restart of HA was done at ~13:00):

It changes whenever the Nordpool sensor changes, by adding taxes and fees depending on time of day and time of year.

This is the nordpool price sensor (raw price, before added fees etc.)

That looks ok. How about the config for this one:

This was just done via the “Energy Dashboard” UI config. So:

I assumed that HA just multiplies the two to values get the cost, and that the cost sensor (second graph in first post) is just the result of setting this up in the Energy Dashboard UI (HA creating it). It appeared and was named the same as the energy sensor, just suffixed with _cost, and I’m pretty sure iotawatt doesn’t have anything with “cost” natively.

Yes it does multiply the current price by the kWh used, but it does not create a sensor. Not sure where you are getting that from.

In fact the difficulty of getting the the results from the Energy dashboard are the subject of a few WTH posts. People want these results as entities. But they don’t exist now. So you must be creating it some other way.

Is there any way to see where a given entity is created?

A search in the entire HA config directory only shows the sensor name (sensor.iotawatt_input_1_wh_cost) in 3 different files:

  • home-assistant.log (because they showed unknown during the HA restart, and the template sensor shown above could not convet unknown to a float)
  • core.entity_registry
  • sensor.yaml (only in the template sensor shown above).

In sensor.yaml I only create a “total cost” by adding the cost for the three phases, so I don’t create any of the individual ones:

- platform: template
  sensors:
    total_energy_cost:
      unit_of_measurement: "DKK"
      value_template: "{{ (states('sensor.iotawatt_input_1_wh_cost') | float) +
(states('sensor.iotawatt_input_2_wh_cost') | float) + (states('sensor.iotawatt_input_3_wh_cost') | float)}}"

And since I don’t have iotawatt anywhere in any AppDaemon (the other place I sometimes craete sensors), I have no clue where this comes from, if not created by HA itself.

Was it a discovered sensor from you iotawatt?

Nope, it only provides sensor.iotawatt_input_1, sensor.iotawatt_input_1_wh, and sensor.iotawatt_input_1_wh_accumulated (and the same for input 2 and 3).

EDIT: Additionally, the related tab is empty (where it of course says “integration: IotaWatt” and shows other iotawatt entities if I choose the sensor.iotawatt_input_1_wh)

Seems I was wrong, the cost sensors are generated:

Looking closely in my config I found them too.

I don’t actually use them (I track costs outside the energy dashboard).

I just did an update which required a restart and they do reset.

So ignore everything I said.

I’d definitely open an issue about this (if I used it). Issues · home-assistant/core · GitHub

2 Likes

Good to know I’m not going crazy :slight_smile:

Issue created: Energy cost sensors reset during HA restart even though the energy sensor they track do not. ¡ Issue #79638 ¡ home-assistant/core ¡ GitHub

2 Likes

Hi guys,
not sure if this is related, I am using the daily energy sensor that is generated from my tasmota devices, the sensor resets @ 7am every day instead of midnight - see screenshot?
I have checked the HA system time and its set correctly, any ideas would be appreciated.

too bad the issue was closed due to stall :frowning: fortunately there is another one opened… Hopefully it’ll get attention asap

@Vasco what is the other issues that has been opened to track this?

I think I found it: energy dashboard showing incorrect costs for power consumed ¡ Issue #17536 ¡ home-assistant/frontend ¡ GitHub