How to get NetMetered Grid data into the Energy Dashboard?

What’s the best way to get NetMetered Grid Energy data into the Energy Dashboard?

I have a single stream of net metered grid energy where the totalized absolute value ramps and down for imports and exports.

I also have a single stream of net metered power data which goes positive and negative for imports and exports.

But the Energy Dashboard seems to want TWO SEPARATE sensors, one for Imported Grid energy and one for Exported Grid Energy.

Is there a way to configure either the Energy Dashboard or a Power Meter to accept a single stream of net metered data?

The Energy Dashboard, for the Energy reporting, requires up to 5 distinct entity sensors [grid-import, solar, grid-export, battery-charge, battery-discharge] each of which must be a positive value of the energy moved, with state class ‘total’ / ‘total-increasing’ and device class ‘energy’, and a unit of measurement such as Wh or kWh or similar.

Your net metered grid energy is of little use as it conflagrates the import energy and export energy.

The Power data is much more useful. This will be the Power as a measurement, which is positive for import and negative for export [or the other way about, but we can fix that later].

If you split the power into two separate sensors, one for import power and one for export power, both of which are then positive values, then you can use the Reimann Sum (Integral integration) to convert the power to energy, ending up with one energy sensor for import, and another energy sensor for export.

This just requires a helper - template - sensor.

If you use something like…

{%- set pwr = states('sensor.mb_grid_power') |int(0) %}
Import {{ pwr if pwr>0 else 0 }} Export {{ -pwr if pwr<=0 else 0}}

as the template for the state value, you can read the power entity state value, and use either of the pwr if pwr>0 else 0 statements, one for the import and the other for the export. This then gives two sensors.

You need to swap them around if your power is negative on import, and you may wish to add availability tests to this. With |int(0) the value returned is just 0 if the power sensor goes unavailable. Also make sure that you add the state class as ‘measurement’ device class as ‘power’ and a unit of measurement to match.

The next part is to use helper - integral to create a Riemann sum integral sensor (again you need two). Use the import-power / export-power sensor created above as the source, set the prefix as required, and use the left-rule (important to use left-rule).

This should then give you monotonically increasing Import Energy and Export Energy sensors, which can then be added to the energy dashboard.

The power sensor you started with can be added as-is directly to the power section of the energy dashboard. If the sensor is positive for import (towards the home) use as-is, otherwise use the inverted option.

That should all work. Ask again if this is too brief and you need further detail.

Hope this helps!