Energy Dashboard - Calculating Return to Grid and Grid Consumption with only Home Energy and Solar Energy data. HELP!

I am losing my mind on getting the Energy screen to work properly. This seems so easy, yet…

In the US, we can measure how much energy the house uses and how much solar produces but we just don’t have a way to measure data from the actual meter(s), that I can find. I don’t want to create a Raspberry Pi camera that “watches” the numbers on the meters and waterproofing, etc. Besides, I have, what should be, enough data to figure this out, right?!

Home Usage Tracking:
In my case, I use the Emporia Vue to read kWh from my home usage. I was going to use the Shelly EM, but I found out about the Emporia Vue and how it can track individual circuits AND whole home energy usage. (Thanks for the advice Rob from the Hook Up!) This has worked for months now, verified by matching my bills usage, all from the energy section in HA. THIS is part of the reason I’m going crazy, this has worked perfectly since I got the Emporia Vue this summer. But!, we just added Solar to our home.

Solar Production Tracking:
I have just had solar installed and the inverter can read and report to HA the instant power (kW) and can track energy (kWh). I have SolarEdge (SE) and the SE modbus integration from HACS gives me the kWh from sensor: sensor.solaredge_ac_energy_kwh, works great.

The Problem, CREATING Good Data:
The 1st problem is this SE sensor is lifetime production and not reset daily for energy. This works fine for the Solar section of the Energy screen and will reset the shown data properly every day but I haven’t been able to figure out how to use this data to reliably figure out how to create template sensors (or meters or whatever) to provide the “Return to Grid” and “Grid Consumption” to the energy. I’ve created so many template sensors and helper utility meters trying to get these to work but I can’t seem to get it to work.

I need a clean slate, has anyone solved this? Thank you, and sorry for the detail.
Does anyone know how to get the “Return to Grid” and “Grid Consumption” to calculate in a way the displays properly on the Energy tab of HA with just Home usage and Solar production? If you only add Emporia Vue to Grid Consumption, it will show the house used 100% of that as used from the home. This is great until I added solar. It then showed that my home used ALL of the Grid Consumption AND ALL of the Solar Production. That’s when this journey turned into a frustration-fest!!

I have created template sensors in the configuration.yaml, but I can’t for the life of me figure out how to get the energy section to work properly:

  • platform: template
    sensors:
    exported_energy:
    friendly_name: Exported Energy
    unit_of_measurement: “kWh”
    device_class: energy
    value_template: >
    {% if ((states(‘sensor.daily_solar_production’)|float - states(‘sensor.red_oak_123_1d’)|float)) | int >= 0 %}
    {{ (states(‘sensor.daily_solar_production’)|float - states(‘sensor.red_oak_123_1d’)|float)|round(3) }}
    {% else %}
    0.0
    {% endif %}

  • platform: template
    sensors:
    imported_energy:
    friendly_name: Imported Energy
    unit_of_measurement: “kWh”
    device_class: energy
    value_template: >
    {% if ((states(‘sensor.red_oak_123_1d’)|float - states(‘sensor.daily_solar_production’)|float)) | int >= 0 %}
    {{ (states(‘sensor.red_oak_123_1d’)|float - states(‘sensor.daily_solar_production’)|float)|round(3) }}
    {% else %}
    0.0
    {% endif %}

I had the same problem. I live in California and have PG&E. I have solar panels and Enphase Energy provides solar generation info. I recently bought an Emporia Vue.

The problem is that the Emporia Vue provides a single sensor that represents the raw power being either consumed or return to the grid from the PG&E meter. However, the energy tab wants it broken down by consumed from the grid versus returned to the grid.

So the first step is to derive this data and create 2 synthetic power sensors (not energy sensors yet). I use the Emporia Vue’s 1min power sensor to give me the most granular level of information possible. Then I use the “Riemann sum integral” integration (the Integration integration :grinning: ) to compute the amount of energy consumed/returned over 1 hour.

- platform: template
  sensors:
    power_consumed_from_grid:
      value_template: >
        {{ max(states.sensor.power_1min.state | int, 0) | default(0)}}
      friendly_name: Power Consumed from Grid
      device_class: power
      unit_of_measurement: "W"
    power_return_to_grid_instant:
      value_template: >
        {{ min(states.sensor.power_1min.state | int, 0) | abs | default(0)}}
      friendly_name: Power Returning to Grid
      device_class: power
      unit_of_measurement: "W"

- platform: integration
  source: sensor.power_consumed_from_grid
  name: energy_consumed_from_grid
  unit_prefix: k
  unit_time: h
  method: left
  round: 2

- platform: integration
  source: sensor.power_return_to_grid_instant
  name: energy_returned_to_grid
  unit_prefix: k
  unit_time: h
  method: left
  round: 2
3 Likes

Very interesting, mine is similar but the solaredge connects directly to the meter outside (through a separate net meter, of course. The solar never enters my electrical panel, nor my home (wire-wise), it’s entirely outside. So my emporia reads consumption in the panel of the home from both sources at the same time (grid and solar).

I appreciate the yaml ! I think what you said about creating the synth power sources is exactly what I was getting confused over. There’s only a few things in HA that I’ve given up on and this one I fought for about a week. I’ve was so frustrated that I haven’t looked at it since this post. It’s time to dig back into it! Thank you thank you thank you!!!

1 Like

I think we may have the same setup (but maybe I’m misunderstanding your setup). Emporia Vue is only getting data from the PG&E Smart Meter. The reading is the aggregate of grid + solar (that’s why the reading can go negative).

any update… I’m also having the same issue, Please share the final yaml

These sensors must have been added to the Emporia Vue 2 or in the integration, because I have sensors for MainsFromGrid and MainsToGrid. This is working as expected with the Solar sensors and appears to be providing correct data to the Energy Dashboard right out of the box - no YAML required.


Hi there,

I’m quite new to HA, so apologies if I didn’t understand the issue correctly or my answer is quite obvious.

My solar system is completely different than yours, but it the energy dashboard is working for you, HA should create a hidden sensor called “sensor compensation”. You can find it in entities after ticking “show hidden entities”.

Hoping it helps,

@jmwhite5 or anyone else reading for that matter.

I have one of these utility connect sensors. For the most part it works well. When retrieving my log files I have updates on the minute every minute for the 1 min sensor.

In HA I notice I do not get updates at exact 1 minute intervals. Some times itll not show two or three minutes worth of data points. They come time on the second nearly perfectly, I am just wondering what happened to the minutes in between? I rarely ever see 2 numbers exact when I download the logs from emporia, so they should be showing no?

Are you getting regular one minute updates? or do you see gaps in the data as well?

What will this do to the Riemann sum integral? Will the missing data mean inaccurate end numbers?

I would think HA would get a new data point every minute.