Home Energy graphs don't seem to work with net metering

I’m having a hard time understanding how to get my energy graphs to display correctly. My home energy usage is monitored via ct clamps. I have a solar panel system with net metering. I also am able to get my solar energy output from the envoy API. I put it through the energy template to calculate hour by hour energy consumption (in Wh) for the hourly solar output, hourly house energy usage and the difference between the solar outpt and my house usage to calculate the exported power back to the grid.

The data over 24 hours looks like the following:

Pretty straight forward with home energy going up throughout the day and the solar energy only being added during the daylight hours. Everything makes sense.

In the energy configuration, it has 3 fields:
-Grid consumption
-Return to Grid
-Solar Panels

it looks like the following:

There is some funny business at 8 am and at 6 pm when I switch between net exporting to net importing.

My question is that I don’t think the energy graphs are correct as i have consumed much more than 2% of my solar energy. What did i do wrong?

Aside from that, I also feel that with net metering, the self-consumed and self-sufficient numbers should be calculated over the course of a day rather than an hourly basis. But even with that, the number should be higher than the reported 2% and 5% values.

Yes there is definitely some strangeness with your sensors.

Your “daily” solar energy sensor is resetting every hour for a start.

Also your energy exported sensor should equal the positive value of your solar production minus your house use, but it does not.

That is on purpose.

In order to get a hour by hour total import/export of energy, my utility meter looks like this:
utility_meter:

template:
  - sensor:
      - name: total_energy_exported
        unit_of_measurement: kWh
        device_class: energy
        unique_id: total_energy_exported
        state_class: total_increasing
        state: "{{[(states('sensor.daily_solar_energy')| float  - (states('sensor.daily_home_energy') | float)/1000),0]| max }}"
      - name: total_energy_imported
        unique_id: total_energy_imported
        unit_of_measurement: kWh
        device_class: energy       
        state_class: total_increasing
        state: "{{[((states('sensor.daily_home_energy') | float)/1000)- states('sensor.daily_solar_energy')| float,0]| max }}"
utility_meter:
  energy_solar:
    source: sensor.total_solar_energy
    name: Hourly Solar Energy
    unique_id: daily_solar_energy
    cycle: hourly
#    always_available: true
  energy_home:
    source: sensor.total_home_energy
    name: Hourly Home Energy
    unique_id: daily_home_energy
    cycle: hourly
  energy_import_hourly:
    source: senor.total_energy_imported
    name: Hourly Energy Imported
    unique_id: hourly_energy_imported
    cycle: hourly
  energy_export_hourly:
    source: sensor.total_energy_exported
    name: Hourly Energy Exported
    unique_id: hourly_energy_exported
    cycle: hourly

So to my point earlier, if i setup my energy to show total power, total solar and net exported per day, The data looks like this:

and i put that into my energy configuration it now looks like this:

so now i think the bar charts are all messy because of the net metering and it thinks i am creating solar power at 10pm. But the guages on the right side are correct in that it caputres my net solar consumption over the period of one day.

I do not think net metering works correctly (or at least i am using the wrong data) for the energy configuration

Your problem is your total energy exported sensor. It should not decrease:

Hi Tom.
So maybe this is a misunderstaing on my part. Net exported is the cummulative (over a period of one day). at night, i am clearly not importing. During the day when i have excessive capacity, i will be exporting. In the evening, I will be again importing from the grid so the net (over the day) should start to decrease as i am net importing again and my next export is going to be less. Did i not understand this correctly? Between my house consumption, my solar energy creation, what should i put as my data going into the energy configuration? (and do i need to reset that on a per hour or per day basis?)

You did not.

You don’t keep track of the net export/import in your sensor. The energy dashboard does that for you. To do so all it requires is:

  1. A Grid Consumption sensor. This is a sensor purely for the energy you import. This increases when you use energy from the grid (not solar). It does not decrease. Though it may reset at midnight.

  2. A Return to grid sensor. This is only for the energy you export. This increases when you export energy. It does not decrease (when you import). Though it may reset at midnight.

The energy dashboard will do all the net calculations from these two sensors for you.

ahh ok. That makes a lot of sense Tom. Ok my next question is how do I get my data so it only increases on export (but not import)? I have my solar energy and my house consumption. How do I create a template sensor that only increases?

This is what I currently have (simple math between solar creation and consumption to determine exported power) that produces the above purple data. If the slope goes negative then that means I’m importing power.

template:
  - sensor:
      - name: total_energy_exported
        unit_of_measurement: kWh
        device_class: energy
        unique_id: total_energy_exported
        state_class: total_increasing
        state: "{{[(states('sensor.daily_solar_energy')| float  - (states('sensor.daily_home_energy') | float)/1000),0]| max }}"

Do you have a sensor that tells you what is going in and or out of the grid?

I do not have a direct sensor.
I have these two sensors:

  • CT clamps on my breaker panel to measure power consumed
  • Enphase energy integration that only tells me solar energy created

From there I have created some of those graphs I took a screenshots above.

Do you have a CT that measures positive for export and negative for import?

Which integration are you using to connect your CT readings to home assistant?

No. My solar system is external to my house. It looks like this:
Solar-->Meter<--Breakerbox (with CT clamps)
They started doing it this way during covid because they don’t need to enter into the house while doing the installation. I have no ability to directly monitor the meter.

The breaker box sensors are all you need for this part. Which CT is measuring import and export?

And again,