Solar in Home Assistant: PV, Import, Export, Self-Consumption, and Dynamic Pricing Integrations
Solar in Home Assistant: PV, Import, Export, Self-Consumption, and Dynamic Pricing Integrations
In Lesson 5 you prepared whole-home measurement. Now we connect it to solar. This is the most important lesson in the energy module, because PV doesn't stop at a number of kWh produced. What matters is how much you used on-site, how much you drew from the grid, how much you sent back, and what that energy was worth over time.
This lesson is long, because it ties together many threads: inverter data, whole-home meter data, the Energy Dashboard, self-consumption, battery storage, net metering and export credits, dynamic pricing, and integrations. You don't need to deploy all of it right away. Understanding the flows and knowing where to get data for a decision matters more.
Plan on about 75 to 90 minutes. When it comes to dynamic pricing and net metering, rules can change over time and vary a great deal by country, region, and utility. In this course I explain the underlying concepts and show you how to use them in Home Assistant, but always check current information with your grid operator, your electricity supplier, and your own solar interconnection agreement.
This lesson's core rule
With solar, knowing how much you produced isn't enough.
You need to know how much you used on-site, how much you drew from the grid, how much you sent back, and what that energy was worth over time.
Four figures you need to tell apart
With solar in Home Assistant, you'll most often encounter four kinds of data. Each answers a different question. If you mix them up, the Energy Dashboard and your conclusions will be wrong, even when the individual numbers look reasonable.
| Figure | Usual source | What it tells you |
|---|---|---|
| PV production | Inverter, manufacturer integration | How much energy the panels produced |
| Grid import | Whole-home meter, Shelly 3EM, DIN | How much energy you drew from the grid |
| Grid export | Whole-home meter, Shelly 3EM, DIN | How much energy you sent back to the grid |
| Home consumption | Calculated, or from a meter | How much energy the home's installation used |
Lesson 5 introduced a simple balance formula. When you have PV production, import, and export from the same period, you can estimate home consumption:
The balance formulahome consumption = PV production + import - export
The result depends on the measurement point and how the inverter and meter report their data. It's an approximation for analysis, not an official settlement figure.
PV power and PV energy: today and total
An inverter usually gives you two kinds of PV data. Power in W tells you how much you're producing right now. Energy in kWh tells you how much you've produced in total, or over a given period. It's the same pattern you learned in Lesson 3: power is a moment, energy is the result after time.
PV power in W: for a live chart, alerts, a "how much sun is out right now" view.
PV energy in kWh: for the Energy Dashboard, daily counters, and production analysis.
Daily vs cumulative energy: your inverter may have both a daily counter and a lifetime one. For the Energy Dashboard and utility_meter, you need a cumulative counter or a periodic one from Lesson 3.
Don't just look at production
An installation that produces plenty of kWh but exports most of it doesn't save as much as one with high self-consumption. Production is only half the picture.
Self-consumption: energy used on-site
Self-consumption is the PV energy you used right away at home instead of sending it to the grid. Under most net metering or export-credit arrangements, this is usually the most valuable part of your production, because you avoid buying energy from the grid at the full retail rate. The higher your self-consumption, the better you're using your own production.
When you have PV production and export from the same period, you can estimate self-consumption like this:
The self-consumption formulaself-consumption = PV production - export
Or equivalently: self-consumption = home consumption - import, when all three figures come from the same period and the same measurement point.
The self-consumption percentage shows what share of your own production you use on-site. If you produce 30 kWh on a sunny day and export 20 kWh, self-consumption is 10 kWh, or about 33%. The rest went to the grid. In Lessons 7 and 8 we'll use this for decisions about devices and dashboards.
The Energy Dashboard with solar
In Lesson 2 you configured the Energy Dashboard. With solar, you add three main sources: production under Solar panels, import and export under Electric grid. Each has to be an energy entity in kWh, cumulative, with the correct attributes from Lesson 2.
1. PV production: your inverter's energy entity in kWh.
2. Grid import: energy drawn, in kWh.
3. Grid export: energy sent back, in kWh.
4. Save and wait for statistics. A complete solar picture on the Energy Dashboard takes time.
The Energy Dashboard won't show self-consumption as its own category. You have to calculate it yourself, or build your own template sensor. That's normal. The system dashboard gives you production, import, and export. The rest is your own analysis.
Template sensors: home consumption and self-consumption
Below is an example of template sensors built on the daily counters from utility_meter in Lesson 3. I'm assuming you already have: daily PV production, daily import, and daily export. Swap in your own names.
A template doesn't fix bad data
If import, export, or PV production are wrong, calculated consumption and self-consumption will be wrong too. First make sure the source entities make sense.
Daily home consumption and self-consumption
Same period, same units
Use data from the same period for these formulas: daily production, daily import, daily export. Don't mix daily production with a counter that's been accumulating since the start of the year, or the result will be meaningless.
template:
- sensor:
- name: "Home Consumption Daily"
unique_id: home_consumption_daily
unit_of_measurement: "kWh"
device_class: energy
availability: >
{{ states('sensor.pv_production_daily') not in ['unknown', 'unavailable', 'none']
and states('sensor.grid_import_daily') not in ['unknown', 'unavailable', 'none']
and states('sensor.grid_export_daily') not in ['unknown', 'unavailable', 'none'] }}
state: >
{% set pv = states('sensor.pv_production_daily') | float %}
{% set imp = states('sensor.grid_import_daily') | float %}
{% set exp = states('sensor.grid_export_daily') | float %}
{{ (pv + imp - exp) | round(2) }}
- name: "Self-Consumption Daily (No Battery)"
unique_id: self_consumption_daily_no_battery
unit_of_measurement: "kWh"
device_class: energy
availability: >
{{ states('sensor.pv_production_daily') not in ['unknown', 'unavailable', 'none']
and states('sensor.grid_export_daily') not in ['unknown', 'unavailable', 'none'] }}
state: >
{% set pv = states('sensor.pv_production_daily') | float %}
{% set exp = states('sensor.grid_export_daily') | float %}
{{ (pv - exp) | round(2) }}
Don't hide a negative result
If the balance comes out to -2 kWh, that's valuable information: the sensors cover different periods, one hasn't updated, import and export are swapped, or the data comes from different measurement points. Converting the result to zero hides the problem. For a simple dashboard, you can add a separate alert for a result below zero.
For a self-consumption percentage, you can add another sensor. Remember that dividing by zero needs some care. Below is a simple guarded version.
template:
- sensor:
- name: "Self-Consumption Percent Today"
unique_id: self_consumption_percent_today
unit_of_measurement: "%"
state: >
{% set pv = states('sensor.pv_production_daily') | float %}
{% set auto = states('sensor.self_consumption_daily_no_battery') | float %}
{{ ((auto / pv) * 100) | round(1) if pv > 0 else 0 }}
Self-consumption versus self-sufficiency
Self-consumption and self-sufficiency aren't the same thing. Self-consumption tells you what percentage of your PV production you used on-site. Self-sufficiency tells you what percentage of the home's consumption was covered by your own solar. You can have high self-consumption with a small system, but still draw a lot from the grid. You can also have large production but low self-consumption if you export most of the energy.
template:
- sensor:
- name: "Self-Sufficiency Percent Today"
unique_id: self_sufficiency_percent_today
unit_of_measurement: "%"
state: >
{% set consumption = states('sensor.home_consumption_daily') | float %}
{% set auto = states('sensor.self_consumption_daily_no_battery') | float %}
{{ ((auto / consumption) * 100) | round(1) if consumption > 0 else 0 }}
Battery storage and state of charge
If you have battery storage, charging, discharging, and state of charge (SOC) join the picture. In the Energy Dashboard, storage gets configured under its own category. Your inverter or battery controller usually gives you charging power, discharging power, and an SOC percentage entity.
SOC in %: how much energy is in the battery right now. Useful for alerts and automations.
Charging and discharging: power or energy in kWh, depending on the integration.
The battery changes the balance: some PV output can go into storage instead of straight to the home or the grid.
Have battery storage? The simple formula isn't enough anymore
In a system with a battery, energy can flow from PV to the battery, from the grid to the battery, and from the battery to the home or the grid. In that case, "PV + import - export" doesn't describe the full balance. As a rough guide: home consumption ≈ PV + import + discharge - export - charging, but only with known measurement points and a known sign convention from your inverter. Self-consumption = PV - export with a battery in the mix also includes energy routed to storage: that isn't always "used on-site right away." The simple sensors in this lesson are for systems without a battery.
Net metering and export credits in plain terms
How exported solar energy gets valued varies a lot depending on where you live and who your utility is. In some places you'll get a kWh-for-kWh net metering credit. In others, exported energy earns a separate export rate, sometimes called a feed-in tariff or an export credit, that may be lower than the retail price you pay for imported energy, and may itself vary with wholesale market prices at the time of export. The exact rules, credit rates, and any expiration on unused credits depend on your specific utility, your interconnection agreement, and local regulation. Home Assistant can help you understand the direction and scale of these flows, but it doesn't replace your utility's own billing.
What this means for you: the more of your own solar you use on-site, the less expensive grid energy you have to buy.
Home Assistant doesn't replace your bill: it shows trends and helps you decide, but it doesn't issue an invoice or track your utility's credit balance.
Net metering and export-credit rules, rates, and any expiration terms can change. Don't base major financial decisions solely on a simplified model in Home Assistant. Check your interconnection agreement, your utility's communications, and current regulatory information for your area.
A dynamic wholesale price isn't automatically your buy price
A dynamic or wholesale market price can influence what your exported energy is worth. It doesn't mean that's exactly what you pay to import 1 kWh from the grid. To manage when you buy energy, use the price that comes from your own rate plan: any dynamic tariff, your supplier's markup, and delivery costs.
Dynamic and wholesale pricing: the value of energy over time
In a growing number of markets, electricity has a price that changes hour by hour, or even every fifteen or thirty minutes, based on wholesale conditions. In the UK, this is familiar from tariffs like Octopus Energy's Agile plan. In parts of the US, some utilities offer real-time or day-ahead pricing plans tied to wholesale market prices. The exact mechanism, the settlement period, and how it interacts with solar export credits depend heavily on your specific utility and rate plan, so don't treat this lesson as financial or legal advice.
| Concept | What it means |
|---|---|
| A dynamic or real-time price | A wholesale-linked price over short periods, for example hourly or every 30 minutes. |
| A monthly or seasonal average | An averaged wholesale price, used in some settlement schemes. |
| Your actual rate | Not always equal to the raw wholesale price. Check the current rules and any adjustment factors in your rate plan. |
Check your own case
Some households are billed on a smoothed, averaged wholesale price; others are billed on the short-period real-time price directly. Which one applies to you, and how it interacts with any solar export credit, depends on your utility, your rate plan, and local regulation. Always confirm your specific arrangement with your supplier or grid operator rather than assuming.
Grid operators and market operators typically publish wholesale price data through an official reporting service, and the exact publication format can change over time. That means any Home Assistant integration pulling this kind of price data should be actively maintained and matched to the current official data source for your market.
Check your sources
Official price data comes from your grid or market operator. In Home Assistant you can use community integrations from HACS that pull this kind of price data for your market, for example UK integrations built around Octopus Energy's Agile tariff, or region-specific integrations for other wholesale price feeds. Entity names and options depend on the specific integration. After installing one, check its documentation and match it to your own billing arrangement.
Inverter integrations: where to get PV data
The inverter is your main source of PV production data. How you connect to it depends on the brand and model. In Home Assistant you'll encounter a few paths.
| Method | Pros | Notes |
|---|---|---|
| The official manufacturer integration | Simple UI configuration | Often cloud-based data, with delays |
| Modbus TCP/RTU | Local, fast data | Requires register configuration |
| MQTT / ESPHome | Flexible, local | You need to know the topic or a ready-made template |
| HACS, for example Solarman | Good for many budget inverters | Check compatibility with your model |
In practice you'll come across integrations for brands like FoxESS, Huawei, Fronius, Solis, Sofar, GoodWe, Growatt, or inverters supported through Solarman. Don't pick an integration just by brand name from a forum post. Check the exact inverter model, the dongle version, the communication method, and whether the data is local or cloud-based.
Local data is better for automation
The manufacturer's cloud can be convenient to start with, but for fast decisions about export, battery charging, or switching on a device, local data works better: Modbus, MQTT, ESPHome, or the whole-home meter from Lesson 5.
A dynamic pricing integration in Home Assistant
Community dynamic-pricing integrations from HACS pull prices from official sources and build sensors with the current price, the price a few hours out, and sometimes the cheapest and most expensive windows of the day. With that, you can show the price on a dashboard, or use it in an automation from Lesson 7.
1. Install a dynamic pricing integration matching your market through HACS.
2. Check the current-price entity and any next-day price entities.
3. Compare units: $/MWh versus $/kWh.
4. Don't automatically tie a dynamic price to your solar export credit without checking the actual rules.
A simple sensor: is it cheap right now
template:
- binary_sensor:
- name: "Energy Price Cheap Now"
unique_id: energy_price_cheap_now
icon: mdi:cash-minus
state: >
{{ states('sensor.energy_price_now_per_mwh') | float(9999) < 60 }}
Watch the units
The threshold 60 only makes sense if your integration reports the price in $/MWh. If the entity reports $/kWh, the threshold needs to be a thousand times smaller, for example 0.06. Before building an automation, check the entity's unit in Developer Tools, States.
The threshold is an example
Swap in your own price entity name and threshold. Units and reporting depend on the integration. Watch the prices for a week first, then set thresholds.
What to show on a dashboard to start
We'll build a full energy dashboard with a power flow card and ApexCharts in Lesson 8. At this stage, a simple set of cards that answers the most important questions each day is enough.
PV power right now: whether the panels are producing.
Import and export right now: whether the home is drawing or sending back.
Production, import, export today: daily counters from utility_meter.
Self-consumption today: your calculated template sensor.
The current energy price: if you have a dynamic pricing integration.
Battery SOC: if you have battery storage.
Common mistakes
You only look at PV production: you ignore import, export, and self-consumption.
You confuse inverter production with home consumption: those aren't the same data.
Import and export swapped: the Energy Dashboard shows a mirror image of what's really happening.
Counters from different periods: you compare daily production against a cumulative export figure.
You treat a dynamic price as fixed: the price changes over time, and your solar export settlement has its own separate rules.
The inverter's cloud as your only source: delays break fast decisions and alerts.
HA treated as official billing: it's an analysis tool, not a substitute for your bill or your utility's credit ledger.
You mix up self-consumption with self-sufficiency: one tells you about your PV production's usage, the other about your home consumption's coverage.
You don't check the price entity's unit: a threshold of 60 for $/MWh isn't the same as 60 for $/kWh.
The battery vanishes from the balance: you count PV, import, and export, but ignore charging and discharging the storage.
Assignment: your first picture of solar in Home Assistant
To do
☐ Find your PV production, import, and export entities in Developer Tools, States.
☐ Add PV production, import, and export to the Energy Dashboard, if the entities are correct.
☐ Build daily counters for production, import, and export with utility_meter.
☐ Calculate daily home consumption and self-consumption with simple template sensors.
☐ If you have a dynamic pricing integration, add the current price to a simple dashboard.
☐ Over several days, record production, import, export, self-consumption, and your self-consumption percentage.
☐ Check whether your price data is reported in $/MWh or $/kWh.
☐ Tell self-consumption and self-sufficiency apart. Record both values if you have the full data set.
☐ If you have battery storage, record SOC, charging, and discharging separately.
☐ Compare the trend with your inverter's app or your utility's meter. Look for it making sense, not penny-perfect agreement.
Key takeaways
Solar isn't just production: import, export, consumption, and self-consumption all matter.
PV power is now, PV energy is the result: the same pattern as W and kWh from Lesson 3.
Self-consumption = PV - export: the higher it is, the better you're using your own energy.
The Energy Dashboard gives you a foundation: production, import, export. You calculate the rest yourself.
Dynamic pricing and net metering rules vary: check your grid operator, your utility, and your current agreement.
Local data is better for decisions: a local inverter connection or your whole-home meter, not just the cloud.
What's next
In Lesson 7 we'll move from data to decisions: standby, rate plans, PV surplus, dynamic pricing, and careful automations built around actual payback. We'll use what you built today: production, import, export, self-consumption, and the price of energy over time.
If you finish this lesson seeing not just how much you produce, but also how much you use on-site and how much you send back, you have a genuine picture of solar in Home Assistant. That's the foundation for savings that actually make sense.