Energy Management in Home Assistant

The missing link: thanks so much :smiley: I am completely off grid and this is what I have currently. So I am looking forwards to see what is achievable.


Yeah, I’m seeing individual device consumption, but not grid consumption. My grid energy device is sensor.home_energy_meter_electric_kwh :

It needs to be a non-resetting energy meter, correct?

I have in energy: in configuration.yaml.

I’m running HA 2021.8.6. I configured the Energy dashboard a few days ago. This is what I’m seeing:

I’m not sure what I’m missing.

This is great work, I’ve got it up and running really easily, so thank you. A couple of questions:

  1. Where is the ‘long term storage’ data stored - is it in the home_assistant_v2.db or elsewhere. I’d like to know how I can purge the data if I need to ?
  2. Is there any way to access the data via lovelace templates (other than the standard energy ones referenced) ? If so, any documents anywhere ?

Finally, a feature request - getting a monthly aggregation (rather than by 24h) would be really helpful as I’m billed monthly by my supplier so being able to compare that energy usage to what’s in HA would be great.

1 Like
1 Like

Would be happy if anyone could suggest on how to integrate the Energy Management when you only have separate sensors for consumed energy and produced solar energy ie I’m missing the Imported and Exported sensors. If I use my sensors as they are I miss out the solar part that I consume myself.

I do not want to calculate or estimate the energy consumed/produced since that would require that I have connection to my sensors 100% of the time and that is not the case. Both my energy monitor and solar inverter do also store the energy consumed/produced persistently so it would be redundant work to.

It would have been so much easier if the handling used daily values instead and I can’t really see how it will work in the long run if you for example need to reset one of the sensors but maybe it magically does…

1 Like

I am doing this with a long floating point number.

See this post

i Also second that, I have good Energy Management utlising the Tesla Powerwall intergration already in Home assistant, however i’m loving the idea’s behind this new Energy Management solution, will migrate to this if and when it can use the Powerwall intergration, otherwise great job Home Assistant team.

When you say the energy monitor and solar inverter already store the energy consumed/produced persistently - is it a figure in kWh that steadily rises throughout the day or does it just update once a day?

If you try using the daily figure that only updates once a day, then you might only see 1 bar for the whole day instead of 24 bars for 24 hours.

Unfortunately, if you want home assistant to calculate grid import and grid export using only the production and consumption figures from your solar inverter, home assistant will need connection to the inverter sensors to perform these real time calculations that the energy dashboard will ultimately consume hourly and chart hourly.

Depending on which SMA inverter you have, different things are possible.

Start here GitHub - SBFspot/SBFspot: Yet another tool to read power production of SMA® solar/battery inverters</ but know which inverter you have!

The sensors are in kWh:s and updated constantly, ie every 30s or less, so it is possible to get a reasonably good graph over the energy flow with current handling. Unfortunately it does not take into account when you both produce and consume at the same time. I think my setup is quite common to, an Energy Monitor for what the house consumes and a Solar Inverter that outputs what it produces. To have a meter showing both production/consumption is luxury :wink:

The reason why I don’t want to use power (house consumption - solar production in watts) and calculate the imported/exported energy using integration ”integration” myself is that sometimes, irregulary, my Energy Monitor loses its WIFI connection…however the EM continues to count kWh so as soon as the connection is there I get the latest value.

BTW, I do not think current energy implementation is very realtime but I guess it is a good start, I do not think that a year from now that we will have to wait for up to 2 hours to get a proper value out of it…or even know if it works or not.

With your Solar inverter, it is possible to be doing 3 things all at the same time:
Solar panels producing power. (measured as production)
House consuming generated solar power from the solar panels. (measured as consumption)
House either consuming grid power or exporting grid power (never both at the same time) (measured as consumption)

The inverter adds both solar consumption and grid consumption together into 1 number.

The grid is only involved in 1 of these 3 above activities.

The reason why we have to use power sensors is because when it comes to the grid, you will never be importing from grid and exporting to the grid at the same time.

This fundamental difference is what lets us calculate grid import and grid export based on inverter power figures.

When you take inverter production in Watts and subtract the inverter consumption in Watts, this will give you either a negative, 0 or positive value. I can manipulate that figure so that home assistant only records positive figures, sort of like a counter. This is how I calculate grid export.

When you take an inverter power consumption in W and subtract inverter power production in W, this will give you either a negative, 0 or positive value. I can manipulate that figure so that home assistant only records positive figures, sort of like a counter. This is how I calculate grid import.

When you do the same with accumulated energy in Wh it does not work the same way due to the negative, 0, positive logic no longer having a meaningful effect.

The only solution I can see is perhaps the Home Assistant Devs improving future versions of the energy dashboard so that it can ingest solar inverter production and consumption figures and do the calculation for us. That will remove the need for sensors. At the moment that is not an option.


You must use the energy_total attribute from the Fronius meter not the power_flow one, as the power_flow one does not have the correct attributes for the energy dashboard in the 2021.8 release.

Check in developer tools to see that all the sensor entities you have picked have a last_reset attribute and a device_class and a unit_of_measurement. Those are all required to be present and correct before the sensors appear in the energy configuration.

what part of the manual did I miss reading

why they neg

What are you using to measure your fridge? Plug(Tasmota?)

so it only works with the supported devices? I have different sensors for production and use. How do I get them in to the graphs?

There is being worked on see Growatt - Add support for Energy Integration · Issue #53963 · home-assistant/core · GitHub

very nice dashboard !

here is my setup
yes tasmota


- platform: mqtt
  name: "Fridge Energy Today"
  state_topic: "tele/SONOFF-POW4/SENSOR"
  value_template: "{{value_json['ENERGY'].Today }}"
  qos: 1
  device_class: energy
  state_class: measurement
  unit_of_measurement: "kWh"

then customize.yaml

    last_reset: "2021-07-30T00:00:00+00:00"

and the states says

what am doing wrong ???

my tplink shows negative kwh in the monitored devices. You dont have that?

Thank you for your well explained answer and I guess it is as I thought but not hoped…there is no way in current implementation I can avoid creating the sensors using the current powers from the Energy Monitor and the Solar Inverter.

Just to clarify, my inverter only outputs produced solar energy (or current power).

1 Like