Solar Import and Export Metering: Avoiding Double Counting in Home Assistant

Solar import and export metering in Home Assistant: avoid double-counting PV, battery and household energy using signed grid power, bidirectional kWh counters and correct sensor boundaries.

Quick Summary (TL;DR)

To avoid double counting in Home Assistant, measure each physical energy flow once and assign it to the correct boundary. Grid import is energy entering the property from the utility; grid export is energy leaving it. Solar production is energy generated by the PV system. These are different quantities, and a solar inverter’s production sensor must not be added to a grid import sensor as though both described electricity bought from the network.

For a conventional grid-connected, solar-only home, a useful accounting check is home consumption = PV generation + grid import − grid export, assuming the figures cover the same interval, there is no battery, and the PV production reading represents AC energy delivered into the monitored household system. With a battery, add battery discharge and subtract battery charge at consistent measurement boundaries, allowing for losses and any separately accounted inverter consumption. Home Assistant’s Energy dashboard needs cumulative energy entities in kWh, not instantaneous watts or battery percentage.

What you need Preferred measurement Common mistake
Grid import Import counter at the grid connection Using net signed power as a lifetime import counter
Grid export Separate export counter at the same grid boundary Subtracting export a second time
Solar generation Inverter’s validated production-energy counter Confusing inverter output with whole-home consumption
Battery charging/discharging Two appropriately defined battery energy counters Using state of charge as a kWh flow
Individual loads Appliance or circuit submeter Adding a subset of loads to the whole-home consumption total

Start with a measurement boundary, not a device list

Imagine a line drawn across the utility connection. Any electricity flowing into the home crosses it as import; electricity flowing out crosses it as export. A bidirectional meter at that point is the best source of both. A second line at the solar inverter’s AC output defines PV generation. A third at the battery defines charge and discharge. Each boundary tells a different story.

The biggest source of misleading Home Assistant Energy charts is mixing measurements from different lines. A CT clampAliExpress price around a feeder, a solar inverter portal, an electricity supplier’s smart meter, and a hybrid inverter can all report valid readings yet still refer to different boundaries. Before choosing a sensor in the Energy configuration, note what it measures, where it is installed, the sign convention and whether the value is power or accumulated energy.

A whole-home meter at the utility connection is not the same as a solar inverter’s grid-power estimate, even when their numbers are close. The inverter’s estimate may depend on an external CT placed at a particular location, periodic polling or a vendor-specific convention. Your revenue meter is authoritative for billing, while a correctly installed local meter is ideal for automation and short-term diagnostics.

Understanding power signs, counters and units

Power is an instantaneous rate in W or kW; energy accumulates power over time in Wh or kWh. A device that reports −1,200 W during export is not reporting −1.2 kWh. You must integrate over time before using a power sensor as an energy source. In Home Assistant, the Integration (Riemann sum) helper can perform this calculation when native cumulative counters are not available, but it depends on regular updates, sensible units and adequate handling of gaps.

Devices disagree about positive and negative directions. Some define grid import as positive; others define export as positive. Some use separate positive import and export counters; others expose a single signed net counter or per-phase power. Test the sign with a known house load and, if available, during definite solar export. Do not assume a negative number is wrong and do not reverse a CT without checking the manufacturer’s instructions.

Sensor or value Typical unit Use in Energy dashboard? Interpretation
Grid active power W or kW Not directly Signed instantaneous flow at grid boundary
Grid imported energy kWh Yes Increasing energy brought in from utility
Grid exported energy kWh Yes Increasing energy sent to utility
Solar generation power W Not directly Current AC or DC inverter output, depending on device
Solar generated energy kWh Yes Accumulated PV production at stated boundary
Battery state of charge % No Estimate of stored capacity, not energy transferred
Battery charged / discharged energy kWh Yes, separately Distinct directional flows across battery boundary

For energy entities, use a correctly reported device class of energy, appropriate state_class (total_increasing where applicable), and units that Home Assistant recognises. A sensor’s capabilities can vary by integration and firmware. Check its statistics and attributes rather than relying solely on the displayed friendly name.

The basic solar-only example

Suppose readings over the same one-hour interval are:

  • PV generation: 5.0 kWh
  • Grid import: 1.0 kWh
  • Grid export: 2.0 kWh

With no battery and compatible AC-side measurement boundaries, home consumption is 5.0 + 1.0 − 2.0 = 4.0 kWh. Of the 5.0 kWh produced, 2.0 kWh went to the grid and approximately 3.0 kWh was used on site. The home also bought 1.0 kWh, giving 4.0 kWh total load.

Now suppose you mistakenly put the PV generated-energy counter into both the Solar Production and Grid Return slots. Home Assistant will interpret 5.0 kWh as exported, even though the grid meter says 2.0 kWh. The charts may show too little or even impossible household consumption. Similarly, adding a load smart plugAliExpress price’s 1.0 kWh to a 4.0 kWh whole-home figure counts the appliance twice: the grid/PV balance already includes it.

Flow in the one-hour example Energy What it means
Solar generation 5.0 kWh All PV energy at the chosen AC output
Grid import 1.0 kWh Utility supplied during that hour
Grid export 2.0 kWh Sent back to utility
On-site PV use 3.0 kWh Generation minus export, in this simplified case
Total home consumption 4.0 kWh PV on-site plus grid import

Do not add import and export counters to calculate household load. Imports and exports are opposite directions at the same boundary. The correct relationship depends on the rest of the energy system.

Solar plus battery: add charge and discharge at the right point

A battery introduces another reservoir. In a simplified AC-side energy balance over one interval, house consumption ≈ PV AC generation + grid import + battery discharge − grid export − battery charge. This assumes the battery counters are measured at an appropriate AC-equivalent boundary and include or consistently exclude conversion losses. If counters are on the DC battery side while PV production is measured on the AC side, the equality will require adjustment for power-conversion losses; it will not be exact.

Consider a simplified hour with 6.0 kWh PV generation, 0.5 kWh imported, 1.0 kWh exported, 1.5 kWh battery charging and 0.5 kWh battery discharging (all expressed at compatible system boundaries). Estimated home consumption is 6.0 + 0.5 + 0.5 − 1.0 − 1.5 = 4.5 kWh. In reality, batteries generally do not charge and discharge equally throughout an hour; the example simply illustrates the separate terms.

Battery measurement Why it is needed Easy error
Battery charging energy Energy entering storage Entering charger consumption under grid import as well
Battery discharging energy Energy returned by storage Treating discharge as new solar generation
State of charge (%) Monitoring remaining battery capacity Converting change in percentage directly to kWh without capacity or efficiency assumptions
Inverter AC output Power delivered to loads Using total AC output as PV-only production in a hybrid system
Grid meter at point of connection True import and export Using a hybrid inverter’s internal virtual grid estimate instead

Hybrid inverter caveat: an inverter’s labelled “production” or “output” sensor may include battery discharge, grid pass-through or PV-only production depending on model and sensor. This must be checked against vendor documentation. If you count battery output as solar production and then also count battery discharge, you are counting the same energy twice. Sometimes a separate PV generation sensor or external AC generation meter is necessary.

Three-phase imports and exports are not always netted alike

For a three-phase installation, check whether the energy meterAliExpress price reports whole-system net import/export or sums per-phase directional flows. These are not necessarily equal. Imagine L1 importing 2 kW, L2 exporting 1 kW, and L3 exporting 0.5 kW at the same instant. Algebraic net grid power is +0.5 kW import, but summing only the importing phase produces 2 kW import and summing exporting phases produces 1.5 kW export. Both presentations can be legitimate views, depending on meter and tariff rules.

That difference is especially noticeable with single-phase solar inverters on three-phase supplies. A Home Assistant energy system may show simultaneous import and export even when net power is modest. Do not overwrite official metering conventions to make a dashboard look intuitive. Record whether your utility settlement method and meter registers correspond to algebraic netting or individual directional phase accumulation.

Three-phase approach Import shown in example Export shown in example Typical implication
Signed algebraic sum, then split direction 0.5 kW 0 kW Net flow at that instant
Directional per-phase sums 2.0 kW 1.5 kW Simultaneous import/export visible

These figures are power, not kWh. Extend the situation over a full hour at unchanged power to get equivalent energy values. Real loads and solar production constantly vary, so always prefer the meter’s genuine integrated registers over calculations based on sparse snapshots.

Choosing an accurate meter: three practical architectures

1. Bidirectional meter at the grid connection. A professionally installed DIN-rail Modbus meter with distinct import/export kWh registers is a strong foundation. Select the correct single- or three-phase model, direct connection versus CT operation and documented Modbus map. The local meter can operate independently of the inverter vendor’s cloud portal. Review our ESP32 Modbus SDM120/SDM630 guide if building a wired interface.

2. CT-based grid monitor. A supported three-phase CT system, such as a correctly specified Shelly Pro 3EM installation, can provide local grid measurements without routing full feeder current through the meter. The CTs must be sized, phased and oriented properly, and the reference-voltage wiring installed by a qualified professional. A reversed CT or mismatched phase creates misleading signs and power factors. For a DIY alternative, see the existing ESP32 CT-clamp energy monitoring guide, but do not treat a hobby CT board as a revenue-grade utility meter.

3. Inverter-native grid and solar measurements. This is often the easiest option if the manufacturer exposes trustworthy production, import and export totals through a supported local interface. Check that the inverter’s external meter or CT is present and configured; inverter production is not automatically the same as grid exchange. Cloud integrations can also lag or omit historical samples, so assess what happens when broadband fails.

Monitoring arrangement Best reason to choose it Key limitation
Certified bidirectional DIN meter Independent grid import/export registers Requires panel space and professional wiring
Multi-phase CT monitor Local telemetry and circuit flexibility Correct CT phase mapping and calibration essential
Inverter-only telemetry Low additional hardware cost Sensor coverage and cloud/local dependency vary
Optical utility-meter pulse/LED reader Non-invasive utility import history, where supported Pulse streams may not separately identify export or solar generation

Never install a meter, open a live electrical panel or move CTs onto live conductors without competent, locally compliant electrical work. CT secondaries and exposed conductors require the protection prescribed by the hardware manufacturer.

Configure Home Assistant Energy correctly

Open Settings → Dashboards → Energy (navigation may vary by Home Assistant version). Configure Grid consumption using the meter’s imported energy entity, then Return to grid using the exported-energy entity. Add Solar panels using the sensor that represents PV generation rather than the grid export register. If a battery is fitted, configure separate energy charged to battery and energy discharged from battery sensors when the integration provides suitable counters.

Prioritise built-in, non-resetting device-provided kWh registers; verify units and long-term-statistics eligibility. If only signed live power is available, do not feed it directly to a lifetime energy input. Split positive and negative power into separate non-negative flows and integrate each flow with an appropriate helper. Avoid negative total-increasing energy counters. The exact HA helper setup and sampling method depend on the integration and may differ from the example below.

Illustrative template sensors for a signed grid-power reading

This example assumes sensor.grid_power is positive on import, negative on export, in watts, and updates reliably. Check your meter’s convention before copying. These entities provide power only, which can then feed separate Integral/Riemann sum helpers to create kWh energy counters.

template:
  - sensor:
      - name: Grid Import Power
        unique_id: grid_import_power_split
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        state: >-
          {% set p = states('sensor.grid_power') | float(none) %}
          {{ [p, 0] | max if p is not none else none }}
      - name: Grid Export Power
        unique_id: grid_export_power_split
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        state: >-
          {% set p = states('sensor.grid_power') | float(none) %}
          {{ [-p, 0] | max if p is not none else none }}

Caution: this sample illustrates direction splitting, not a complete drop-in Energy dashboard configuration. Verify template syntax against your installed Home Assistant version, treat unknown readings as unavailable rather than zero where practical, choose the integration unit prefix so the result is in kWh, and inspect statistics before using the generated counters. Direct cumulative import/export meters are preferable because they are less sensitive to polling intervals and outages.

Checklist: catch double counting before publishing your dashboard

Test Expected result If it fails
Turn on a known load while PV output is low Grid import power rises, or export drops Check sign and CT direction
Observe clear midday export Export counter increases Verify grid boundary sensor and directional register
Compare inverter PV production with external meter Trends and interval energy broadly agree Check PV/AC/DC boundary and missing inverter readings
Add a battery load change Battery discharge and home load move plausibly Verify battery charge/discharge sign and inverter semantics
Check individual plug totals They remain subsets of home consumption Remove any manually added appliance energy from household total
Compare with a utility bill Import/export intervals and meter units are consistent Investigate tariff periods, phase netting and counter resets

Do not compare instantaneous power sampled at two slightly different times as if it were an exact energy balance. Compare energy integrated over the same hour or day. Meter polling delays, inverter internal losses, standby consumption and measurement tolerances will create legitimate small differences.

Why Home Assistant totals disagree with your electricity supplier

The most common causes are different start/end times, energy units, import/export registers, three-phase settlement conventions, meter pulse constants, daylight-saving changes and lost samples. A utility bill can aggregate calendar days or tariff registers differently from an Energy dashboard that uses local timezone and rolling statistics.

Start with the supplier’s actual opening and closing register values, not an estimated bill. Compare them against the same interval in the local import/export cumulative counters. An error of exactly ×1,000 points to W/Wh versus kW/kWh or a pulse-constant mismatch. An error that tracks solar output suggests that export or generation is being misassigned. A small offset that grows during battery cycles suggests that AC-versus-DC boundary losses or hybrid inverter semantics require attention.

For system-level issues, the existing Home Assistant Energy Dashboard troubleshooting guide explains statistics and ESPHome pitfalls. For choosing among sensor technologies, read energy monitoring methods compared.

Buying recommendations by installation type

Solar-only retrofit: choose a reliable bidirectional grid meter plus the existing inverter’s genuine solar production-energy counter. If no trusted solar total is available, ask whether the inverter provides a documented local integration before buying another meter.

Hybrid inverter with battery: use the vendor’s documented power and energy definitions, preferably with a properly installed utility-boundary meter. Ensure the inverter’s “solar generation” does not bundle battery discharge and that charge/discharge counters are in compatible units.

Three-phase with solar on one phase: prioritise documented per-phase and total registers. Confirm the import/export accounting method used by your utility and avoid rebuilding revenue-meter totals from sampled instantaneous power if the meter exposes integrated directional totals.

Cloud-independent Home Assistant: use local Modbus or a supported local meter integration, an appropriately maintained network and a system that retains cumulative counters through Home Assistant downtime. The cost is not just the meter: allow for professional electrical labour, CTs, compatible gateway and network equipment where required.

Frequently asked questions

Is net grid energy the same as grid import?

No. Net energy is import less export over the interval. The Energy dashboard generally needs distinct imported and exported kWh readings to display each direction accurately.

Can I use the solar inverter’s lifetime yield as grid export?

No. Solar yield is total PV generation; grid export is only the portion delivered out to the network. Much of solar generation may be used by the home or stored in a battery.

Should I add smart-plug consumption to whole-home consumption?

No. Smart plugs are valuable for attributing part of the whole-home total to appliances. They should not be added on top of an already complete grid-plus-solar consumption balance.

Why does my dashboard show import and export at the same time?

It can be normal when looking at three-phase directional registers or interval aggregates. Check whether the supplier’s meter nets phases and whether the dashboard sources report per-phase or overall directional energy.

Does a battery state-of-charge sensor count as battery energy?

No. SoC is a percentage estimate, not a measured charged/discharged energy counter. Battery capacity, depth of discharge and efficiency make percentage-based kWh estimates particularly unreliable for energy-accounting statistics.

Official references and further reading

Bottom line: use one well-defined grid boundary, a separate genuine solar-production counter and, where fitted, consistent battery directional-energy counters. If the numbers are on different sides of an inverter or are sampled at different times, reconcile those differences before assigning entities to Home Assistant Energy.

CONTINUE EXPLORING / SMART HOME & ESPHOME

Read next

Practical guides related to this article.

Explore the topic →
HARDWARE DECISION GUIDEChoosing Home Assistant hardware?

Compare practical options before you choose hardware.

Compare options →