EnergyPlus with Python
EnergyPlus is the US Department of Energy’s flagship building energy simulation program. It was developed by a team of researchers and engineers and is free and open source; you can download it from the EnergyPlus website.
EnergyPlus models heating, cooling, lighting, ventilation and other energy flows. It is made of many modules that work together to calculate the energy a building needs under different weather and operating conditions, for a wide range of systems and energy sources. At its core is a model of the building based on fundamental heat balance principles.

In this article, we export an EnergyPlus model from DesignBuilder, then modify and run it from Python with the EnergyPlus engine. The notebook used here is available on GitHub.
Exporting the IDF file
- Open your DesignBuilder model (.dsb file). Here we use the Atrium example model provided with DesignBuilder.
- Go to File > Export > Export EnergyPlus or DBSim input file > Simulation.
- Open the exported file in a text editor and check its EnergyPlus version. This is the version embedded in DesignBuilder (8.6 in this example).

Installing EnergyPlus and converting the IDF file
Next, download and install the EnergyPlus version you want to use. In this example we use v8.9.0. The IDF file must then be converted from version 8.6 to version 8.9 so that it works with the installed engine:
Open IDFVersionUpdater, located in
C:\EnergyPlusV8-9-0\PreProcess\IDFVersionUpdater(assuming EnergyPlus is installed on theC:\drive).
Click Choose File to Update, select your IDF file and choose 8.9.0 as the new version.

When the conversion finishes, a new IDF file is created.

Installing and using eppy
Eppy is a Python package for scripting EnergyPlus input (IDF) and output files. Because it is plain Python, you can navigate, search and modify IDF files programmatically. With a few lines of code you can:
- make a large number of changes to an IDF file;
- apply changes only to objects that meet certain conditions;
- edit several IDF files at once;
- read the output files of a simulation;
- generate the input file for the next simulation from the results of the previous one.
To install it, run pip install eppy in a command prompt.
Eppy needs three files:
- the IDF file we just converted;
- the IDD file (
Energy+.idd), found in the EnergyPlus installation folder; - the EPW file, the weather file used for the simulation.
I suggest keeping each file in its own folder:

First, we load the model into an IDF object:
from eppy import modeleditor
from eppy.modeleditor import IDF
iddfile = r"Example\Resources\iddfiles\Energy+.idd"
fname1 = r"Example\Resources\idffiles\Model_Design_builder.idf"
Weather= r"Example\Resources\WeatherDATA\FRA_Paris.epw"
IDF.setiddname(iddfile)
idf1 = IDF(fname1,Weather)
idf1.printidf()

The IDF object contains many object types. We can loop over them to list their names:
for x in idf1.idfobjects:
print (x)

The objects you are most likely to change in an energy study are:
- idf1.idfobjects[‘LIGHTS’]: lighting load in each zone;
- idf1.idfobjects[‘PEOPLE’]: occupancy load in each zone;
- idf1.idfobjects[‘ELECTRICEQUIPMENT’]: equipment load in each zone;
- idf1.idfobjects[‘ZONEINFILTRATION:DESIGNFLOWRATE’]: infiltration rate in each zone;
- idf1.idfobjects[‘MATERIAL’]: properties of the defined materials;
- idf1.idfobjects[‘CONSTRUCTION’]: the layers that make up each wall;
- idf1.idfobjects[‘WINDOWMATERIAL:GLAZING’]: properties of the glazing;
- idf1.idfobjects[‘BUILDINGSURFACE:DETAILED’]: coordinates and construction of each surface.
Modifying the IDF file
Let’s say we want to:
- set the number of people to 5 in each zone;
- set the lighting power density to 6 W/m²;
- set the thickness of the concrete material to 0.25 m.
Occupancy:
peoples=idf1.idfobjects['PEOPLE']
for people in peoples:
people.Number_of_People_Calculation_Method='People'
people.Number_of_People=5
print (idf1.idfobjects['PEOPLE'])

Lighting:
LIGHTS=idf1.idfobjects['LIGHTS']
for LIGHT in LIGHTS:
LIGHT.Design_Level_Calculation_Method='Watts/Area'
LIGHT.Watts_per_Zone_Floor_Area=6
print (idf1.idfobjects['LIGHTS'])

Concrete thickness:
for material in idf1.idfobjects["MATERIAL"]:
if 'Concrete' in material.Name:
material.Thickness=0.25
Running the simulation
EnergyPlus can be run from the Windows command line, so a single command from Python is enough to save the modified model and launch the simulation:
import subprocess
idf1.saveas(r"out.idf")
fname1 = "out.idf"
subprocess.call(r"C:\EnergyPlusV8-9-0\energyplus.exe -w "+Weather +" -r " +fname1, shell=True)

All EnergyPlus output files are written to the working folder:
