Energy Management in Home Assistant

Well i don’t even know why this is happening,
So what i did was a clean install and manually put every config for config back and see if it works.
I got it working, but sadly im still having issue’s with the graps…
My database works normal now as i use the default one for now with no other configs setup in the yaml…

I have nearly the same configuration, but it still doesn’t appear. The sensors are in the dashboard but not available in the energy configuration.

sensor:
  - platform: fronius
    resource: http://192.168.1.20
    monitored_conditions:
      - sensor_type: inverter
        device: 1
      - sensor_type: meter
        device: 3
      - sensor_type: storage
        device: 0
      - sensor_type: power_flow

did u make a template from it or just added reset line ?
if i make a template from it, i can select it for solar, but it won’t graph…
i can’t make it to work, can u show me what u did ?

regards

Thanks for that example code. I have a Sense meter which operates similarly to your setup (2 CT clamp pairs; 1 pair around the main service wires, 1 pair around the solar wires).

For other who may be looking for how to make this work with a Sense meter’s sensor.energy_production and sensor.energy_usage sensors, here’s my sensor template configs:

    grid_export: # Instant power export for energy dashboard - goes 0 if currently importing (uses Sense)
      friendly_name: "Grid Export"
      unit_of_measurement: 'W'
      value_template: >
        {% if (states('sensor.energy_usage') | int - states('sensor.energy_production') | int) > 0 %}
          0
        {% else -%}
          {{ (states('sensor.energy_usage') | int - states('sensor.energy_production') | int) | abs }} 
        {% endif %}      
    grid_import: # Instant power import for energy dashboard - goes 0 if currently exporting (uses Sense)
      friendly_name: "Grid Import"
      unit_of_measurement: 'W'
      value_template: >
        {% if (states('sensor.energy_usage') | int - states('sensor.energy_production') | int) > 0 %}
          {{ (states('sensor.energy_usage') | int - states('sensor.energy_production') | int) }}
        {% else -%}
          0
        {% endif %}

Then convert those grid_import/export power sensors into long term energy sensors with:

- platform: integration # Grid energy import for Energy dashboard - from forum
  source: sensor.grid_import
  name: grid_import_kwh
  unit_prefix: k
  unit: kWh
  round: 2
- platform: integration # Grid energy export for Energy dashboard - from forum
  source: sensor.grid_export
  name: grid_export_kwh
  unit_prefix: k
  unit: kWh
  round: 2

Then go into Customization, set the device_class for grid_export_kwh and grid_import_kwh to ‘energy’, and you should be able to load grid_export_kwh and grid_import_kwh into the Energy dashboard.

Sense doesn’t have a ‘lifetime production’ sensor, but my Enphase Envoy does, so I use that as my ‘solar production’ input in the Energy Dashboard.

If you want to get your individual devices that Sense has found into the Energy dashboard, you can use the following code as template. You’ll need this code repeated for each device you want HA to track in Energy Dashboard:

- platform: integration # experimental energy build up for AC costs
  source: sensor.ac_usage
  name: ac_usage_kwh
  unit_prefix: k
  unit: kWh
  round: 2
- platform: integration # experimental energy build up for hot water heater costs
  source: sensor.water_heater_usage
  name: water_heater_usage_kwh
  unit_prefix: k
  unit: kWh
  round: 2

Hopefully a future version of the Energy dashboard allows for native input of ‘house usage’ and ‘solar production’ and does the required math and logging on the internally. Took me a lot of guesswork (and ultimately finding Ross_McCarthy’s code) to understand that I needed to have separate sensors that only show import and export (and don’t go negative if my house flips from net importing to net exporting).

If you want to see your instantaneous import/export situation, I recommend the custom card “power wheel card” in HACS: GitHub - gurbyz/power-wheel-card: An intuitive way to represent the power and energy that your home is

2 Likes

+2 or +n for integration the pw2 integration with the new energy feature. The pw2 already has all the ct clamps you could want, and is measuring all the right things, just need some was to get that into the energy feature. Some easy way.

The energy feature also needs to learn about battery storage, i guess.

Sounds like you just need to create the Integration sensors to convert Power to Energy.

1 Like

Just added the reset line.
Homeassistant > Configuration > Customizations

Here i selected my entity and made the required changes.

Using integration sensors would work, but the Tesla pw2 is already integrating, so it would be duplicate effort, it requires unpicking positive and negative values (power to/from grid is the same ct clamp, different sign), and you’d lose information whenever HA was not running (the pw2 runs 24/7, ‘or else’).

All the required energy numbers are there as attributes of the pw2 entities, just needs to be easier to get at them. And in the case of battery usage, add some place to put them.

Ok, so if the data is already there as attributes you can create new template sensors using those attributes, then use the new template sensors in the Energy Management GUI.

I am running HA 2021.8 but am struggling to find the energy integration. I have been using Ha since 2017 and my configuration.yaml has been on the go since then. I just looked at someone else setting up energy monitoring and there is an energy button on the side menu in configuration. What have I done wrng not to see the integration. I have my location details n my configuration.yaml, is this the problem?

add energy: to your config.yaml

1 Like

You need the newest release too.

They stated that in the first few words…

2 Likes

Yes, I could create the required sensors from pw2 attributes. Heck I could drop into python and code whatever I liked… However for prime time, Joe public, usage the pw2 integration (and others) need to be EASILY integrated into the energy feature.


Where is the mistake? What am I doing wrong? Why does not consider the cost?

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.

4 Likes

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