Change price of energy in history

Hi,

I was using the Energy Dashboard with a static price configuration. Unfortunately I forgot to to change the price a few months ago when the price was raised. I’d like to change the price in history so that the Energy Dashboard will display the correct values.

Anyone knows how to accomplish this?

@frenck Maybe please?

Perhaps using sql. However I can’t tell you exatly how. Your question triggers something else though;

With these prices changing every day, isn’t there an online service that we can use as a sensor to set the correct prices every day?

It depends on where you are and which provider you use and also how your subscription is put together.
In northern Europe the price is fixed at noon the day before and nordpool will then list it.
There is a nordpool integration that pull those values into HA.

Yeah it should be somewhere in the DB however I can’t find out where. Hopefully someone knows…

About your question, as WallyR mentioned, prices depend on your contract and can vary per person. If your energy provider provides a REST api, you can of course retrieve these values into a sensor. Otherwise scraping could be an option. Unfortunately my energy provider doesn’t support this, so I change the prices manually (which happens 2 times a year)

Same question, my prices change monthly, and I’d have to time the change exactly at the moment they change IRL if i understand correctly atm. This isnt really doable.

Would be super nice if i can go back and update the prices for those periods.

You lookup the ID of your “cost”-sensor in the table statistics_meta.

Then you edit/recalculate all rows with this metadata_id in the tables “statistics” and “statistics_short_term”

Unfortunately there is no cost sensor in the table statistics_meta. Probably because of using a static price instead of having an entity to track costs

What I just did for future changes is to change it to a entity which holds the current price. Once your net provider announces a price change, you can then create an automation which will be triggered last day of the month at 23:59, to update the new price in the entity

The cost sensor has the same name as your grid-energy-sensor with “_cost” appended.

But you do see your costs in the energy dashboard?

I don’t have that cost sensor:
Screenshot 2022-10-01 at 07.07.42

Cost is available in Energy dashboard
Screenshot 2022-10-01 at 07.09.06

That is weird. Not sure if I can help.
How did you configure your grid-consumption in the energy dashboard?

Up until a few days ago I’ve always used a static price:
Screenshot 2022-10-01 at 08.11.36

My bad! Apparently the sensor is there at id 84. The text search for ‘cost’ apparently didn’t work because of the long name the last characters were being truncated.

Thanks for your help! Now have to figure out how to modify al those entries :wink:

1 Like

Did you figure out how to update all the values? I’ve also been looking at ways to change the historical value.

I’m also interested how to do this.

There is a long post on this
Help needed! Energy database costs calculation wrong, after investigating everything - Energy - Home Assistant Community (home-assistant.io)

the solution for me was to use the db, use the energy sensor statistics, multiplied by value…

Due to a wrong cost of the energy price that I had I have manually deleted the cost data from statistics and statistics_short_term tables using the right metadata_id. Now the it started to populöate the tables with new data and correct cost. But I wonder if it is possible to re-generate the data for the past X number of days? How?

If you have the energy value and use a fixed price then is it is ‘just’ and insert/update of the new cost entity, the trick is to have state and sum line-up correctly.
I also deleted all short_term and used the newest record to align with the last record in statistics
That worked for me

To start off I am wondering if the graph is taking into account the hourly price which is a variable price and calculates it with the consumption. I hope it really does so cause otherwise there is no point in it. Can anyone confirm this?

well as I mentioned I am using an hourly price so in that sense it is not fixed at all. But even if the price is varying it should be possible to recalculate all of them. I guess the is internal routine or service that does that and populates the statistics. It is not so important since I only lost about a month data. But it would be an interesting exercise. :slight_smile: