Energy Management in Home Assistant

Hi all, I searched inside this topic about Shelly with no results, anyway I made correction to the integration sensor I already have because I used to record kWh of 1 Shelly EM, now I wait maybe a day to see data in Energy dashboard, my question is: someone here has added a Shelly EM as source of the Energy dashboard and can confirm it works?

Hi @nickrout I found rhis cose:

state_class: measurement
last_reset: '1970-01-01T00:00:00+00:00'
unit_of_measurement: kWh # or Wh
device_class: energy

it is not clear to me where it should be added…can you kindly explain it to me?


I succeeded, I had to add everything in the customize.yaml file.
I have several photovoltaic production sensors,
I have an immediate power sensor and a daily production sensor, in order to be able to configure the HA energy module well, do I have to use the immediate power sensor that measures the live preview or the daily reduction sensor that adds up the total energy produced?

Now no data found:

below my sensor:

Grid consumption sensor:

Return to grid sensor:

Solar production sensor:

do you think everything is ok?
maybe i have to wait two hours before seeing something or should the chart animation already work?

Your states aren’t numbers. You need to get rid of the k.

1 Like

I am having a hard time figuring out, what the output of my sensors should be, in order to make the Energy dashboard work…

Could someone please tell me, what kind of values the dashboard expects ?

Grid consumption:
Should this value represent all consumption, without any subtraction of solar?
Or is this consumption - solar production
AND is this value allowed to be negative or just zero.

Right now, i have this sensor:

{{ [0, states('sensor.smappee_1107000583_local_total_consumption_active_power') | int - states('sensor.smappee_current_solar_production_corrected') | int ] | max }}

This gives the value of the current consumption, but subtracted with the solar production. So if the solar can keep up, the consumption is zero. Not sure if this is right?

Return to grid
Kinda the same question like above here.
What kind of values should be the input here.
Currently, I have this sensor setup.

{{ [0, states('sensor.Smappee_Current_Solar_production_corrected') | int - states('sensor.smappee_1107000583_local_total_consumption_active_power') | int ] | max }}

This gives the value of the current solar output, subtracted by the consumption.
I only sell the power, which I cannot consume myself.
My setup does not have a sensor, that tells the amount of power returned. So the calculation must be done using sensors.

Solar production
And finally, what should this value represent?

This is my sensor right now.

{{ [0, states('sensor.smappee_1107000583_local_total_production_active_power') |int ] | max }}

I have set this sensor to not go below zero, due to the fact that at night time, it shows negative 8 watts.

Grid consumption is what you actually take from the grid, I. E. House use minus solar. If it is negative, that is grid export, return, whatever.

Solar is what the solar pv system makes, and yes at night it needs to use a few w to stay alive. My solaredge records 2w usage when off, iirc.

It is much easier if you have a ct clamp metering the meter tails (feed from and to the grid).

I do have clamps on both the solar production side, and the consumption side.

But these are just “current values”, and will just show the actual output. Not an accumulated number. (If that is what is needed)

And what about the “grid return” ? I have no clamps to measure that directly. So how do I calculate that?

You use the integration platform to turn the instant values into accumulated kWh, but you will have to calculate the grid use / return if you are not measuring it, since that’s what the energy item needs. Do the calculation (consumption minus solar) and have the integration platform turn that into kWh for the energy dashboard. Solar you can integrate directly.

Okay, so let me try to understand this.

Solar Production = Does not need any calculations. Just need to be directly feeded. (Positive value only, never negativ, and aggregating all time)

Grid Consumption = Does not need to be calculated. Just the raw total consumption (which is a mix of solar and grid power in reality) and (Positive value only, never negative values, and aggregating all time)

Grid return = Consumption minus solar. (cannot be negative values, and only positive??)


Grid consumption is total consumption MINUS solar generation, can’t be negative. Grid return is solar minus total consumption. I. E. Whenever Negative value of grid consumption. Both need integrating to get kWhrs from watts or kW.

I have searched but I am still new to HA, is there a way to pull the values used by these energy cards without recalculating them ourselves from the sensors? I am wanting to track my daily solar production but I was hoping to not have to recalculate the work already done by the energy page. Can we call the values directly? Maybe if this is trivial can someone point me in the direction for newbs? BCHydro my energy provider charges one rate for the first 22.1918kWh consumed per day and a higher rate for anything after that. Nothing seems pre-setup to handle this scenario. I just want to build something that tracks the value of the solar I am producing if I didn’t already have it that was I know when it’s paid for itself.

All the values you put into the input on these charts are home assistant sensors, so you can access them in any template, automation, script or lovelace card.

That part I understand. The energy card tracks everything by day and stores it in some database as I understand it it also pre-does all the math. What I am trying to avoid is creating my own database of all the same data that home assistant is already handling. So for example I would like to directly reference how much energy was produced by solar on a particular day so that I can apply the two tariff rates.

I am not sure that it is all recorded in the database. The daily figure I think is established by taking the reading now and subtracting the data at midnight.

If you get a chance you can look at the statistics table in the database. It seems to create a reading at 12 minutes past every hour. The daily amount is not recorded, just the total to date.

PS: The times are in UTC I think.

1 Like

The first smart meters rolled out here in Oz used a private WiMAX network, but then that was migrated over to 3G. Depending on the provider, they may also provide access via zigbee to enable the consumer to see real time data.

Personally I use a (now end of life) zigbee ‘Raven’ usb dongle from a company called Rainforest Automation to read the data and pump that out via mqtt to HA. They still have a device called the Eagle 200 that can be used and avoids the need to use mqtt - if your electricity supplier supports it (you will need to contact them), then you can buy one from the USA (it will come with a 120V power supply, but apparently the Eagle just uses a standard USB cable for power so an old 'phone charger will do the job). The integration is here: Rainforest Eagle-200 - Home Assistant


last_reset: ‘1970-01-01T00:00:00+00:00’
state_class: measurement

This worked for me as well. No doubt eventually we will be able to directly add “last_reset” etc in directly, but doing this instantly enabled my energy sensors to appear without mucking around with creating extra sensors. I might make a comment in my yaml file to remind me why it’s there though! :wink:

At first it did work, but suddenly it stopped working.
I will try to figure it out

last_reset is taken out in 2021.9 because there were to many misunderstandings and failures on how this worked. the new state_class: total_increasing which will be introduced takes care of that automatically, so when a meter gets reset somehow, HA will be able to handle that.

this is the actual PR Add support for total and total_increasing sensor state classes by emontnemery · Pull Request #54523 · home-assistan

Thanks - yep had worked out that total_increasing was missing on the stable release after trying that first! :slight_smile: Cheers.