Energy Management in Home Assistant

this is my full code in configuration.yaml, maybe I have bad formatting?

template:

  - sensor:
      name: Grid Export Energy
      state_class: measurement
      icon: mdi:solar-panel
      unit_of_measurement: W
      device_class: power
      state: >
        {{ [0, states('sensor.envoy_serialnumber_current_power_production') | int - states('sensor.envoy_serialnumber_current_power_consumption') | int ] | max }}

  - sensor:
      name: Grid Import Energy
      state_class: measurement
      icon: mdi:transmission-tower
      unit_of_measurement: W
      device_class: power
      state: >
        {{ [0, states('sensor.envoy_serialnumber_current_power_consumption') | int - states('sensor.envoy_serialnumber_current_power_production') | int ] | max }}

sensor:
  - platform: integration
    name: Grid Export Energy
    source: sensor.grid_export_power
    unit_prefix: k
    unit_time: h

  - platform: integration
    name: Grid Import Energy
    source: sensor.grid_import_power
    unit_prefix: k
    unit_time: h

I can see the cost is actually recording but not represented in the energy table

Aha, you need to find/replace serialnumber in all 4 strings that contain sensor.envoy_SERIALNUMBER_current_power_production
and
sensor.envoy_SERIALNUMBER_current_power_consumption
with your envoy serial number.

Maybe just list your sensors and do a search for _production

Ive blocked out my serial number in red

Should be

template:

  - sensor:
      - name: Grid Export Energy
        state_class: measurement

etc

1 Like

Sorry I just did a find replace on that before posting. The serial numbers are correct in my real code in yaml

I am aware that around 2 weeks ago, the naming changed
from
_current_energy_production
to
_current_power_production
and
_current_energy_consumption
to
_current_power_consumption

i had to remove my enphase integration and re-add it for the names to update.

Please see this for more detail

Ive just noticed a small bug in my energy dashboard.

My Energy Dependency card says
“Netto consumed from the grid”

image

Hi Frenck:
This is really a cool feature.
We really want to upgrade our integration to adapt to the more and more functions provided by ha.

Whether there is any method that can push our PR forward?

Thanks

Still the same for me

the same on another gauge shows 5.616kWh export

A summary View of the data of the same data on a entity group card on my main dashboard

Summary Power Data

yep, that all looks good.
Now you have to wait 2 hours for the data to populate as per this message

After setting up a new device, it can take up to 2 hours for new data to arrive in your energy dashboard.

The reason why you can see solar lifetime production is because that has been recording for a lot longer than your newly created sensors.

1 Like

last_reset is not there

in my case would I just add that in to customize yaml file?

"sensor.*current_power*":
  last_reset: '1970-01-01T00:00:00.000000+00:00'
  state_class: measurement
1 Like

I put this in

For those wanting to dig a little further into their Energy visualisation not working, you can use the “SQLite Web” addon to look under the covers at the statistics and how it works. It appears some entities from plugins will have all the appropriate attributes to appear in here, if yours aren’t, check the posts above that mention last_reset:

        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'

To get started, you will need to install the SQLite Web addon and open it, you should see something like the following after choosing statistics_meta, then content.

statistics_meta appears to be a master lookup table of all your entities that statistics are being collected on, in my case I am interested in #8:

If you then choose statistics - content you will probably see lots of entries however, I have used the query function command: SELECT * FROM "statistics" where metadata_id = 8 to pull up all entries associated with my solar feed in - there is only one because I have been trying to get my OpenEnergyMonitor configuration working despite the lack of documentation.

If you want to reset the statistics of an entity, you can do it here also, because I have been using a “smart plug” in a variety of places I wanted to reset it so it has clean data for the energy integration.

First: I manually locate it’s ID via statistics_meta and find out it is #2.

Then go to the “Query” tab and to make sure I have everything as correct as possible, I type in:
SELECT * FROM "statistics" where metadata_id = 2 and click execute.

DANGER
If that shows the results that I am expecting, to deleted it, I slightly change the command to:
DELETE FROM "statistics" where metadata_id = 2 and click execute.

It then appears that statistics are generated hourly so that is why you need to wait 2 hours for the visualisation to show any information, but if you go in via the SQLite Web addon you should be able to see some sort of value after 1 hours (on my system it shows as on the hour)

To make this slightly more discoverable, this post is about:
OpenEnergyMonitor (emoncms), EnergyManagement, Statistics, SQLite Web, database cleaning

27 Likes

I see what you have done differently.

You have named the first 2 power sensors as energy.

I am just going to highlight the lines that do not match each other in the config you posted here today.

template:
  - sensor:
      name: Grid Export Energy
  - sensor:
      name: Grid Import Energy

sensor:

    source: sensor.grid_export_power

    source: sensor.grid_import_power

This had made your source in the bottom 2 integration sensors invalid as they dont match the sensor names in the top 2 sensors.

You just need to update the first 2 sensors to these names to get this working properly.

  - sensor:
      name: Grid Export Power

  - sensor:
      name: Grid Import Power

Please revisit my original post which has the correct configuration.yaml lines Energy Management in Home Assistant - #309 by del13r

Thank you, it wil, just have to modify it so that I also have low tariffs during the weekend.

Hello,

I have Toon Zon and it not delivering a total amount kWh, only what I produce daily.

So this is my graph, it there a way to work around this issue.

Peter

So I went back and scrapped everything and copied in your code mentioned in your link. Updated the SR which I have changed to dummy for this forum.

template:
  - sensor:
        name: Grid Export Power
        state_class: measurement
        icon: mdi:solar-panel
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0, states('sensor.envoy_dummySR_current_power_production') | int - states('sensor.envoy_dummySR_current_power_consumption') | int ] | max }}

  - sensor:
        name: Grid Import Power
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0, states('sensor.envoy_dummySR_current_power_consumption') | int - states('sensor.envoy_dummySR_current_power_production') | int ] | max }}

sensor:
  - platform: integration
    name: Grid Export Energy
    source: sensor.grid_export_power
    unit_prefix: k
    unit_time: h

  - platform: integration
    name: Grid Import Energy
    source: sensor.grid_import_power
    unit_prefix: k
    unit_time: h

I then went to developer screen and filter for grid and got the following output.

I am not sure how the last_reset got in there currently as I only have the code as above added. If it is required can someone advise where exactly it should be placed?

I’m unsure if this has been answered further down the post (I’m still reading it) but I believe you must add the _cost sensors in your recorder, that’s what seemed to work for me, I had a couple of days of no cost, then I added the sensors to my recorder and they showed up.

1 Like