Energy Management in Home Assistant

How do I configure Home Assistant to never delete the meter readings of my P1 integration (slimme meter). And is there an easy way to export meter readings to CSV?

Long term hourly statistics are kept indefinitely as far as I know.

If you are using the default SQLite database, you could install the SQLite Web add-on. It has the option to export to CSV.

Metadata about the entities that have statistics is in the statistics_meta table, the statistic_id column is the entity name, and the id column is used as a foreign key in the statistics table (column metadata_id). For energy entities the sum is the total sum since creation of the statistic. The actual readings are kept in the state column.

Hello there, I’m writing to you because last night my statistics got messed up… I’ve read several hints from this thread and I think I can pinpoint a moment in time that my database went wrong. But it doesn’t look like there’s one wrong value / row that I could delete to fix it, because the error is in the sum column… Could you please point me in the right direction to fix it?

This is my database content where you can see the sum went wrong even though the readout from entity was right…

In Developer Tools > Statistics you can see each entity, and then delete or correct rows for a specific time where the error occurred. You need to click on the icon showing an arrow pointing up a slope which should be visible for the entity you are having issues with.

Thanks for brilliant advice, didn’t know there’s a tool already to do that :slight_smile:

All’s fine now. Thanks again.

Hi all,

For starters, I’d like to say that having recently added by PV batteries to the Energy management, it all was working apparently well during the short time I was feeding the batteries directly from DC with the hybrid inverters.

However it all went “wrong” when the weather got worse this month, the energy sale value went up, and it became more interesting to charge the batteries at night during off-peak hours from the grid, use them to satisfy the loads at peak hours during the day, and keep all PV production with feed-in priority, i.e. sell it all.

Now, in this use case, although the intra-day solar production appears correctly, the graph on the right with the total values for the day appears to be wrong, as it does when we try to see any of week/month/year when the manager sums it all up:

It seems Energy management is assuming the battery was charged from solar as far as daily totals go, because I see no orange arc on the “Home” total, and there is a pink dot descending from “Solar” into “Battery” which was not supposed to be there, as the battery was fully charged from the grid.

If I go to the weekly agregation, all the self-consumption is missing from that day’s bar (Dec 5th):

Is there any configuration I might be missing?
Or is this a unforeseen use case that was not programmed in the first place?

Thanks in advance,
-jprates

1 Like

Just noticed the values for the 4th of December, that seem to corroborate my initial impression that the energy distribution card values are assuming the battery was charged from solar:

For this day alone (this month so far) there is a 2 kWh self-use showing up, and if we do the math, we see why for this day alone there is self-consumption:

Solar = 34,7
Exported (grid feed-in) = 13,4
Battery charge = 19,3
Self-Consumption = 34,7 - 13,4 - 19,3 = 2 (this is wrong)

In order for the card to show self-consumption we have to generate more solar energy than the sum of export and battery charge, even though the battery was charged at night at an hour there was no solar production at all, and that is easy to check on the solar production attribute.

The truth however is shown by the self-consumed solar energy below, which correctly states there was 61% solar self-consumed, i.e. 34,7 x 0,61 = 21 kWh:

As it stands both cards contradict each other. The Energy Distribution is being incorrectly calculated.

I have reported this issue in GitHub:

You will see from my examples that when battery exports exceed household consumption.

Please feel free to add your examples to the issue and hopefully we can get someone assigned to look at resolution.

This issue also appears to be relevant;

1 Like

Hi @markpurcell , thanks for the feedback.

I had already opened an issue given the lack of response here, so now have yet another one.

It’s obvious now that the battery part is not working properly, and wrong assumptions are being made in the aggregation calculation for week/month/year.

I’m sadden to see these issues go back to 2021 and still have no one working on them :worried:

I’ll try to assist getting someone to look at this by posting on those still opened.

1 Like

Hi, are you also able to check if you put energy to the grid or consume? so left to right and right to left?

Is it possible to have two different energy dashboard that monitor different meters and PV plants and keeping statistics separate? It is necessary to install another instance of HA, or is there another way?

At present it’s not possible.

There are several features requests like this one:

You can vote there if you want.

3 Likes

Of course you can, at the very least take a look at the dashboard config screen and it’s there obvious to see.

Go to settings > dashboards > energy

I understand this is no what you want/need, the granularity is not the same, but you can create “virtual” sensors that you use to add all systems individual values via template.yaml, and then use this virtual sensors to feed the energy dashboard.

Some of my sensors in my dashboard are fed this way, since I have some multiple instances of the same device, like for example multiple batteries.

Again, I know this is not what you’re asking for, but at least might be a workaround for some basic funcionality while your request is not implemented.

I think @demetrius is asking for two different energy dashboards. Not more sensors in the unique energy dashboard.

You of course can create a new energy dashboard, but you have to create all the utility_meters, graphs, and so on.

Yes, I was referring to different energy dashboard, each one with different meters.
Creating something similar manually does not give the same features and statistics.

Question:
I would like to play around with dynamic electricity prices. Awattar offers a free API that could provide the data, but I have no clue how to call that data in HA and create an entity that I can work with…

Ok, I can sort of answer my own question here…

With a lot of Copy and Paste work I managed to get the Awattar thingy working. I had to do it in NodeRED though which I had never used before…still have no clue how it works, but found some working setups I could copy.

Two questions though…the value I get from Awattar is not tied to a location as far as I can tell, so I am not sure the price I get is the correct one for my part of Germany. I can’t find any way to specify a location via the Awattar API unfortunately. If anyone knows, please helpt me out.

The second one is how to calculate the actual price. Awattar API give me the barebones price. That means I have to add VAT and other fees. I used the values I got from Tibber for this, so I add 19% VAT and 13ct/kWh on top of the price to get the (hopefully) accurate final price.

My Template to get the total price is as follows:

- name: "Epex_Brutto"
        unit_of_measurement: "Cent"
        device_class: "monetary"
        state_class: "measurement"
        state: >- 
          {{states("sensor.epex_spot_price")|float(0)+13 + states("sensor.epex_spot_price")|float(0) *0.19 |float(0)}}

I hope this isn’t complete nonsense…I have little experience with writing code in HA, am bad at Math in general and am working with some assumptions… :wink:

Really keen for some insights into how I might be able to get this integration working with my current situation.

I am calling through to my electricity supplier’s API which gives a delayed (as in, the most up-to-date information is 2 days prior) feed of the kWh used in half-hour increments. I can also get it daily or weekly I think.

I’ve had to use Node-RED to get this and will be running it daily to get the previous previous day’s data. I have options with what I do with the data once I have it. I figured the best thing was to pump it into InfluxDB, but toyed with maybe MQTT as well.

The issue, I guess, is the delay. How do I put this information into a sensor so that the HASS integration shows it correctly? I read a couple of posts about just putting in the overall grand total out of InfluxDB, but won’t that get confused given my feed is a couple of days delayed?

Should I just publish the daily data to MQTT and leave it to HASS to sort things out? But, if so, how do I deal with the delay?

Any help is greatly appreciated.

Is anyone experiencing random spikes?
I had 2 devices today which shot up, using way more than they are even capable of.
Apparently, my home network switch consumed 73kWh of electricity today!?
How should I deal with this as it’s throwing off my energy calculations.