Prevent Electrical Storage from charging & discharging at the same time

Hello guys it’s me again.

How can I prevent the system from charging and discharging the battery at the same time? I already tried to set low variable costs for in- and output but that’s not working. Do you have an idea on how to fix that?

for bus in range(elStorage):
    inputs={bel: Flow(nominal_value=maxPower, variable_costs=0.01)},
    outputs={bel: Flow(nominal_value=maxPower, variable_costs=0.01)},
    loss_rate=0.001, initial_storage_level=None,
    inflow_conversion_factor=chargeEfficiency, outflow_conversion_factor=dischargeEfficiency,))

its just a simple generic storage like this one.
in my model the excess electricity can be fed in the grid to gain profit. vice versa the system can buy electricity from it. These costs are not final of course and no fees are included. I tried setting the costs for buying electricity a bit higher but that had no effect either.

#bought electricity from the grid
es.add(Source(label="shortage_el", outputs={bel: Flow(variable_costs=elPrice["Preis"]+10)}))

#direct marketing for excess electricity
es.add(Sink(label="excess_el", inputs={bel: Flow(variable_costs=-1*elPrice["Preis"])}))

I get a flow situation like this, which doesn’t make a lot of sense:

problem solved, please close!

Would be nice to explain how you solved the issue in case other users do have the same problem.


Dear @steve , we are having a similiar problem right now. Could you give us a short hint on how you solved it or what caused the problem?

Many thanks


There is an additional constraint in oemof.solph to prevent to flows from being active at the same time but it will create a mixed-integer problem and in my opinion this is not necessary in 90% of the cases.

Normally this indicates that it is good/necessary for the system to “dump” energy and you have to analyse why. Even though it is not the preferred/wanted it is a possible behaviour.

See: More than one storage on the bus

ok, thank you!

What is this additional constraint? Could you send the code, please?
Thanks! Greetings, Amélie

General information:

You can find examples for the usage of pre-designed constraints in the reference docs:

You can also create your own constraint and add it. Have a look a this example:

1 Like
Text and images licensed under CC BY 4.0Data licensed under CC0 1.0Code licensed under MITSite terms of serviceOpenmod mailing list.