[FEATURE] Stored Energy Cost Sensor (€/kWh) for Dynamic Battery Strategies #269
Replies: 4 comments 4 replies
|
Thanks for the suggestion! 🙌 Here's how this works:
If your idea is very specific to your setup, it may not make it into the core integration — I'll try to suggest a workaround in that case. Feel free to discuss details or alternatives below. |
|
This suggestion is to define a way to keep track of a price for the energy stored in our batteries. In itself this suggestion doesn't do anything with that information yet. I too do have built something like this using 2 separate template sensors:
I have found however that many people only keep track of the accumulated costs and accumulated profits and don't keep track of the actual value for a battery's content. And consequently they need complex decisions to build a price based control methos. f.e. using fixed price levels or an average for the day like you do. This suggestion aims to create a unified method to keep track of the actual cost of the energy charged when we charged the battery, so we can properly determine if and how big a profit or loss we will make when we discharge the battery now, simply by comparing the charging costs with the current price because the sensor has the exact same unit of measurement: euro/kWh. I did intentionally not share my implementation for the both sensors yet. I'm hoping to first get the discussion going on how to properly determine and keep track of a price for the energy once it is in our battery. The core of this suggestion is to keep track of the price in euro/kWh, instead of tracking the value of the total energy in euros like most people seem to do. |
|
Hi, I will implement the Stored Energy Cost sensor in Omnibattery 1.5.0. My proposed definition is a persistent weighted-average cost in currency/kWh for the energy currently stored in each battery, plus an optional system aggregate. Charging contributions would include the source price and configured efficiency. Discharging would reduce the stored quantity without changing the remaining average cost. Before implementation, please confirm:
These decisions are important because “stored energy cost” and “stored energy opportunity value” can produce different results for solar-charged energy. |

Uh oh!
There was an error while loading. Please reload this page.
Area of the proposal
Sensors, entities, or statistics
What problem would this solve?
To optimize dynamic energy management and accelerate ROI, users need to know the actual "cost price" of the energy currently stored in their battery.
Comparing this internal cost price against real-time grid import rates and export/feed-in tariffs allows Home Assistant (and automation strategies) to make smarter decisions—such as determining whether it is profitable to discharge to the grid, power household loads, or preserve the stored energy for upcoming peak prices.
Proposed solution
Add a new sensor (e.g., sensor.battery_stored_energy_cost) that continuously tracks the weighted average cost price of the energy currently stored in the battery, expressed in currency/kWh (e.g., €/kWh).
Why track €/kWh instead of cumulative total spent (€)?
Invariance during discharge: When the battery discharges, the remaining energy retains the exact same cost per kWh. Only the total kWh count changes, meaning this sensor only needs updating during charging cycles.
Modular & robust: Adding/removing battery units or recalibrating capacity won't corrupt historical cumulative cost tracking.
Simple total value calculation: The instantaneous value of the energy inside the battery is simply:
$$\text{Total Value (€)} = \text{Stored Energy Cost (€/kWh)} \times \text{Current Battery Energy (kWh)}$$
Calculation Logic during Charging
When the battery is charging ($\Delta E_{\text{in}} > 0$ ), the new stored energy cost per kWh ($C_{\text{new}}$ ) is calculated as a weighted average:
$$C_{\text{new}} = \frac{(E_{\text{old}} \times C_{\text{old}}) + (\Delta E_{\text{in}} \times P_{\text{charge}})}{E_{\text{old}} + \Delta E_{\text{in}}}$$
Where:
$E_{\text{old}}$ = Stored energy prior to charging step ($\text{kWh}$ )
$C_{\text{old}}$ = Previous stored energy cost ($\text{€/kWh}$ )
$\Delta E_{\text{in}}$ = Energy added in this step ($\text{kWh}$ )
$P_{\text{charge}}$ = Instantaneous charge price ($\text{€/kWh}$ )
Determining Instantaneous Charge Price ($P_{\text{charge}}$ ):
The price depends on the source powering the charge cycle:
$$P_{\text{charge}} = \left( \frac{\text{Power}{\text{PV}}}{\text{Power}{\text{Total In}}} \times \text{Export Tariff} \right) + \left( \frac{\text{Power}{\text{Grid}}}{\text{Power}{\text{Total In}}} \times \text{Import Tariff} \right)$$
Example use case
Key Benefits & Use Cases
Arbitrage Decision Making: Discharge to the grid only when$\text{Export Price} > \text{Stored Energy Cost} + \text{Battery Degradation Margin}$ .
Load Management: Avoid using battery energy for non-critical loads if the current grid import price happens to be lower than what it cost to charge the battery in the first place.
ROI Tracking & Strategy Optimization: Provides exact financial insight into charging efficiency and payback performance over time.
Who would benefit from this?
Most Omnibattery users
Alternatives or workarounds
No response
Additional context
No response
Confirmations
All reactions