Storage does not charge everytime



Hello :),

I have some problems in my first test with oemof .

My enrgysystem has PV, demand, battery and a grid connection (sink and demand).

When the battery is not fully charged and there is more PV energy then load/demand, the battery should charge but sometimes oemof decide to use the grid connection instead of the battery.

program file:

Elektrischen Bus initialisieren

bel = solph.Bus(label=“electricity”)

demands (electricity/heat)

energysystem.add(solph.Sink(label=‘last’, inputs={bel: solph.Flow(
nominal_value=1, actual_value=data[‘last’], fixed=True)}))

demands (electricity/heat)

energysystem.add(solph.Sink(label=‘Emob’, inputs={bel: solph.Flow(
nominal_value=1, actual_value=data[‘emob’], fixed=True)}))


energysystem.add(solph.Source(label=‘pv’, outputs={bel: solph.Flow(
actual_value=data[‘pv’], nominal_value=1, fixed=True)}))

Netzüberschuss, Einspeisung

energysystem.add(solph.Sink(label=‘Netzeinspeisung’, inputs={bel: solph.Flow(

Knappheitsquelle, Netzbezug

energysystem.add(solph.Source(label=‘Netzbezug’, outputs={bel: solph.Flow(


battery = solph.components.GenericStorage(label=‘Batterie’,
inputs={bel: solph.Flow(variable_costs=0)},
outputs={bel: solph.Flow(variable_costs=0)},

can someone help me?



Hi Börn,

does this mean that the PV power is fed into to the grid? If yes, this could be the case if it is indifferent cost-wise which does not seem to the the case at a first glance.

Overall, some metrics would help to illustrate the problem. Could you provide all (maximum) capacities or just put your example on some file hosting service like Dropbox or github?



Yes the pv power comes into to grid.

here is the script and the datarow:

thanks for helping me :slight_smile:


If you have more excess than needed some of the excess energy will be stored and some will be exported. But as it is a ‘perfect foresight’ approach this may happen in reverse order. A human would first load the storage and export the remaining excess if the storage is full but the solver knows exactly how much energy will be produced so the storage may be charged at the end of an excess period with the exact amount that is needed afterwards. There is nothing wrong with that you just have to keep it in mind if you interpret your results.

It is just a guess and if you need a more detailed answer you have to show me the part where the “wrong” behavior happens, because we do not have the time to prepare the results, sorry. You could present a plot (just some days around the occurrence) with the state of charge (relative) of the storage and the flows around the electricity bus.


In other words: If the order of dispatch (charge/discharge) is indifferent concerning your objective (costs) it might appear unintuitive but is still a valid optimal result.

You might reduce the time horizon and check whether the unexpected/unwilled behaviour occurs less frequently. This should be the case if the formulation is right. A help into the LP file for a small time horizon might also provide more details.



Here is the first picture of the problem (two follow in the next post):

I reduced the time horizon. A time of the summer which has the problems which are shown on the pictures, but the problem is just the same

Thanks for ur answer. I tried to solve the problem with increasing the maximum capacity of the storage. But it does not help.

Do u have any other ideas how i could fix it?




To me, the modelling looks allright and the answer can only be that the dispatch is indifferent concerning the objective.

At least at a quick glance it looks plausible to me on my system:


For me everything looks fine. You added the possibility to export energy into the grid and so energy is exported into grid in times when nothing else make sense. The energy can only be used to satisfy the demand and when the demand is satisfied the energy will be exported.

Why do you want the storage to be fully charged if the energy is not needed?


Your PV seems to be so over-dimensioned that the feed-in is indifferent concerning the objective.


Ups, we answered at the same time :slight_smile:


Okay, now i understand the ‘perfect foresight’. The battery only charge as long as needed to have enough energy for the demand.

I will test storage invest to find the perfect capacity.

Thank You!


I think the storage is just under-dimensioned in relation to the pv-production and thus can be loaded within a couple of time steps:

battery = solph.components.GenericStorage(label='Batterie',
                                          inputs={bel: solph.Flow(variable_costs=0)},
                                          outputs={bel: solph.Flow(variable_costs=0)},

Thus the time of charging/discharging becomes indifferent concerning the costs.

In theory if you set up the capacity to some real big value, the “unwilled” behaviour should vanish and approve that your model works right from a mathematical perspective.