Including Variable Electricity Prices into Oemof Model

Dear all,
I am currently working on a model for my bachelor thesis in which I want to optimize a combined cycle heat and power plant (CCHP) with a thermal energy storage, a power to heat component (PtH) and a heat only boiler.
To do this I want to include variable electricity prices. I have the prices in €/MWh for every hour of the year, which is also the time step and period of my model.
However I don’t know how to link the variable costs of the power to heat component as well as the CCHP to the electricity prices in my csv_file.
Also, I want to include different taxes and fees depending on three cases:

  1. the CCHP produces power: it earns the electricity price of the respective hour
  2. the PtH module uses the power created by the CCHP, in this case electricity tax has to be paid
  3. the PtH module uses power from the grid, in this case the costs are the momentary power price, electricity tax and electricity fees
    It seems as if to achieve this I also have to create several electricity buses.
    My code looks like this so far. Note that I tried to include the electricity prices by calling my csv file (‘data’) just as you would if you include the “actual_value”. It didn’t work…
    I also added a thermal energy storage and a heat only boiler. All components, including the cchp are subject to optimization. The values for capex and variable costs aren’t included here as I don’t want to make the post even longer…
    other abbreviations:
    SS: Stromsteuer (electricity tax)
    NE: Netzentgelde (electricity fees)
filename = os.path.join(os.path.dirname(__file__), 'price_dhn.csv')
data = pd.read_csv(filename, sep=";")

### adding buses for electricity, gas and thermal energy 
B_el_1 = solph.Bus(label= 'B_el_1', balanced =True)
B_el_2 = solph.Bus(label= 'B_el_2', balanced = True)
B_gas = solph.Bus(label ='gas_grid', balanced =True)
B_th = solph.Bus(label = 'bus_th', balanced = True)'Busses Created')
### add gas source as well as electricity and thermal sinks 
gas_import = solph.Source(
    outputs={B_gas: solph.Flow(
        variable_costs= gas_price)})

grid_sink = solph.Sink(
        label= 'grid_sink', 
        outputs = {B_el_1: solph.Flow()} )

grid_source = solph.Source(
        label= 'grid_source', 
        outputs = {B_el_2: solph.Flow()})

thermal_demand = solph.Sink(
        label ='thermal_demand', inputs ={B_th: solph.Flow(
                actual_value =data['dhn_demand_n'], nominal_value = 823.3, fixed = True)})'Sources / Sinks created')
# an excess and a shortage variable can help to avoid infeasible problems; does this 
# make sense here?
#excess = solph.Sink(label='excess_el', inputs={B_el_1: Flow()})

# create both gas power plant and gas boiler

cchp = solph.components.GenericCHP(
        label = 'cchp',
        fuel_input = {B_gas: solph.Flow()},
        electrical_output={B_el_1: solph.Flow(
        variable_costs = - data['el_price']
    heat_output={B_th: solph.Flow(
    Beta=[0.122], back_pressure=False,
    investment = solph.Investment(ep_costs=epc_CCHP))

# Add HOB 
HOB = solph.Transformer(label= 'HOB', inputs = {B_gas: solph.Flow(variable_costs = var_costs_HOB)}, 
                           outputs = {B_th: solph.Flow()},
                           conversion_factors = {B_gas: 0.95},
                           investment = solph.Investment(ep_costs=epc_HOB))

# add thermal energy storage 
TES = solph.components.GenericStorage(
    inputs={B_th: solph.Flow()},
    outputs={B_th: solph.Flow()},
    inflow_conversion_factor=0.98, outflow_conversion_factor=0.95, 
    investment = solph.Investment(ep_costs = epc_TES))
# Add power to heat 
PtH = solph.Transformer (label = 'PtH', 
                         inputs = {{B_el_1: solph.Flow(variable_costs = SS)},
                         {B_el_2: solph.Flow(variable_costs = data['el_price']+SS +NE)}},
                         outputs = {B_th : solph.Flow()},
                         investment = solph.Investment(ep_costs = epc_PtH)                         )

# add everything to energysystem
system.add(B_el_1, B_el_2, B_gas, B_th, gas_import, thermal_demand, grid_sink, grid_source
           ,cchp, HOB, TES, PtH)

Thank you for your help :slight_smile: much appreciated

Hey everybody,
luckily nobody took the time to answer yet, because I fixed the problem. It seems my approach was right but there was an error with the ‘{’ brackets and I didn’t use a decimal point in the csv file but a comma instead.
However I get a new error message. I will make a new post if I can’t figure it out myself.
Thanks to those who read the post :slight_smile:

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