Energy dashboard grid consumption incorrect

I appear to be not understanding something about the energy dashboard setup. It’s not functioning like I’d expect, so I need a little guidance. See my dashboard image for reference:

I have successfully added my grid consumption, return to grid, and solar production. I just have the three values. The problem is, I expect that when my solar production is higher than my consumption, I should be showing 0 for grid consumption since that power is coming from solar, not the grid… but the energy dashboard displays everything as if I am pulling that power from the grid.

I expected the energy dashboard to show me my grid usage vs solar usage, but it appears to just want to show ALL of my consumption as coming from the grid, despite this not being the case. Does the energy dashboard not perform these calculations to determine where the usage is coming from?

If it’s supposed to be doing these calculations, is there something I could be doing wrong to cause it not to display things properly?

You need a from and to grid sensor.

Sorry, I misspoke when I posted that. I DO also have the calculated return to grid value.

What confused me is it seems like I also have to perform a transformation on the total consumption before I pass the value to the energy dashboard… I expected that the energy dashboard would help out with the calculations so that if I add multiple consumption values, it would handle the totals to tell if I was using all of my solar.

What I am seeing is that the energy dashboard doesn’t really do any of the math for me.

I had to calculate the return to grid with a template sensor, and then I also had to calculate the total consumption from the grid, where as long as my electric usage is lower than the solar production, the grid consumption gets set to 0.

I’ve been able to calculate all of these values just fine using some template sensors.

I just didn’t expect to need to do some of the calculations, since I thought the energy dashboard would handle some of it if I just gave it the raw values.

Would you mind sharing your calculation?
I also wonder why the total consumption seems to increase with higher solar power:
(even though I am feeding back into the grid with my small double panel)
Thank you.

Yeah, no problem. I ended up needing to do some basic calculations for total Watts first (for solar production, and then grid in and grid out).

solar_power_production_in_positive_watts:
  unique_id: solar_power_production_in_positive_watts
  value_template: >-
    {% set power = (states('sensor.solar_panels_total_production_watts') | float) %}
    {% if power < 0.0 %} {{ ((states('sensor.solar_panels_total_production_watts') | float) * -1) }}
    {% else %} 0.0 {% endif %}
  friendly_name: Solar Power Production In Positive Watts
  device_class: Power
  unit_of_measurement: 'W'

total_electric_consumption_in_positive_watts:
  unique_id: total_electric_consumption_in_positive_watts
  value_template: >-
    {{ ((states('sensor.home_electricity_total_use_watts') | float) + (states('sensor.wallbox_portal_charging_power') | float)) }}
  friendly_name: Total Electric Consumption In Positive Watts
  device_class: Power
  unit_of_measurement: 'W'

power_sent_to_grid_in_positive_watts:
  unique_id: power_sent_to_grid_in_positive_watts
  value_template: >
    {% set grid_out = ((states('sensor.solar_power_production_in_positive_watts') | float) - (states('sensor.total_electric_consumption_in_positive_watts') | float)) %}
    {% if grid_out > 0.0 %} {{ grid_out }}
    {% else %} 0.0 {% endif %}
  friendly_name: Power Sent To Grid In Positive Watts
  device_class: Power
  unit_of_measurement: 'W'

total_power_consumed_from_grid_in_positive_watts:
  unique_id: total_power_consumed_from_grid_in_positive_watts
  value_template: >
    {% set grid_in = ((states('sensor.total_electric_consumption_in_positive_watts') | float) - (states('sensor.solar_power_production_in_positive_watts') | float)) %}
    {% if grid_in > 0.0 %} {{ grid_in }}
    {% else %} 0.0 {% endif %}
  friendly_name: Total Power Consumed From Grid In Positive Watts
  device_class: Power
  unit_of_measurement: 'W'

After that I used the statistic integration sensors to get kWh as needed for the Energy dashboard.

- platform: integration
  name: Total Energy Consumed From Grid kWh
  unique_id: total_energy_consumed_from_grid_kwh
  source: sensor.total_power_consumed_from_grid_in_positive_watts
  unit_prefix: k
  round: 2
  method: left

- platform: integration
  name: Total Energy Sent To Grid kWh
  unique_id: total_energy_sent_to_grid_kWh
  source: sensor.power_sent_to_grid_in_positive_watts
  unit_prefix: k
  round: 2
  method: left

- platform: integration
  name: Total Solar Energy Produced kWh
  unique_id: total_solar_energy_produced_kWh
  source: sensor.solar_power_production_in_positive_watts
  unit_prefix: k
  round: 2
  method: left

Those integration sensors can be used by the Energy dashboard directly and it now displays everything as I’d expect.

My total consumption increases with higher solar production simply because more sun also means more heat, so I run my AC a lot more, and AC is a heavy energy user.

For reference, this is what the actual dashboard looks like with the fixed data:

All the blue grid consumption in the morning and evening, and all the purple returned during the daytime certainly makes me want to update my system with a few more panels and some batteries!

Thank you so much @eric10k93.
That’s great and I will start to play around with this.
Much appreciated!