|
| 1 | +# Optimizing PV production |
| 2 | + |
| 3 | +## Introduction |
| 4 | +In this tutorial we want to write an application that optimizes the energy produced from a PV system with |
| 5 | +Battery for self consumption. |
| 6 | +In order to do so we need to measure the power that flows through the grid connection point |
| 7 | +(TODO link to glossary) to determine excess power. |
| 8 | + |
| 9 | +Before we start it's assumed that you have finished the first [tutorial](./getting_started.md) |
| 10 | + |
| 11 | +## Measure the excess power |
| 12 | + |
| 13 | +When using the term excess power what we actually mean is the consumer excess power, that is the power that |
| 14 | +flows from the PV system into the grid. |
| 15 | + |
| 16 | +!!! note |
| 17 | + |
| 18 | + We are using the passive sign convention (TODO link) and thus power flowing from the PV is negative |
| 19 | + and consumed power is positive. |
| 20 | + |
| 21 | +We want to measure the excess power. In order to do so you can use the SDK's data pipeline and especially |
| 22 | +the pre defined consumer and producer power formulas (TODO is there a documentation for those?) |
| 23 | + |
| 24 | +```python |
| 25 | +async def run() -> None: |
| 26 | + ... # (1)! |
| 27 | + |
| 28 | + # negative means feed-in power due to the negative sign convention |
| 29 | + consumer_excess_power_engine = ( |
| 30 | + microgrid.logical_meter().producer_power |
| 31 | + + microgrid.logical_meter().consumer_power |
| 32 | + ).build("excess_power") # (2)! |
| 33 | + cons_excess_power_recv = cons_excess_power_engine.new_receiver() # (3)! |
| 34 | +``` |
| 35 | + |
| 36 | +1. The initialization code as explained in the Getting Started tutorial. |
| 37 | +2. Construct the consumer excess power by summing up consumer and producer power each of which having |
| 38 | +opposite signs due to the sign convention. This returns a formula engine. |
| 39 | +3. Request a receiver from the formula engine which will be used to consume the stream. |
| 40 | + |
| 41 | +## Control the Battery |
| 42 | + |
| 43 | +Now you can use a battery pool to control the batteries. |
| 44 | +Finally you need to combine the data pipeline with the controlling to build the optimization logic. |
| 45 | + |
| 46 | + |
| 47 | +```python |
| 48 | + ... |
| 49 | + |
| 50 | + battery_pool = microgrid.battery_pool() # (1)! |
| 51 | + |
| 52 | + async for cons_excess_power in cons_excess_power_recv: # (2)! |
| 53 | + cons_excess_power = cons_excess_power.value # (3)! |
| 54 | + if cons_excess_power is None: # (4)! |
| 55 | + continue |
| 56 | + if cons_excess_power <= Power.zero(): # (5)! |
| 57 | + await battery_pool.charge(-cons_excess_power) |
| 58 | + elif cons_excess_power > Power.zero(): |
| 59 | + await battery_pool.discharge(discharge_power) |
| 60 | + |
| 61 | +``` |
| 62 | + |
| 63 | +1. Get an instance of the battery pool. |
| 64 | +2. Iterate asynchronously over the constructed consumer excess power stream. |
| 65 | +3. Get the `Quantity` from the received `Sample`. |
| 66 | +4. Do nothing if we didn't receive new data. |
| 67 | +5. |
| 68 | + |
| 69 | + |
| 70 | +## Further reading |
| 71 | + |
| 72 | +(TODO links) |
| 73 | +To create more advanced applications you may want to read the documentation on actors and channels. |
0 commit comments