NREL: Python Opens Up New Applications for EnergyPlus Building Energy Simulation
Buildings account for more than 40% of U.S. energy use and 70% of the country’s electricity use. Reducing that consumption and “shaping” it to match renewable generation is one of the key challenges of our clean energy future. We need to design and operate buildings to be more efficient, flexible, and responsive. To do that, we must be able to better predict and model building energy use in a range of applications.
Whole building energy modeling (BEM)—physics-based simulation of building energy use—is a multipurpose tool for building energy efficiency and grid integration, supporting traditional applications like design, code compliance, and even code development. The U.S. Department of Energy (DOE) has invested in BEM and its applications since the 1970s, most recently and notably with EnergyPlus®, its flagship open-source BEM engine.
BEM in general, and EnergyPlus in particular, are well established in applications such as high-performance building design, code compliance, and even code development—the latter done by evaluating the costs and savings of proposed amendments on a suite of fixed archetypal models of different building types including an office building, a school, a hospital, and high-rise apartments. These traditional applications are similar to one another in that they are primarily concerned with minimizing total annual energy use. They use BEM in a simple way: (1) define a building model including choosing from a menu of operational strategies, (2) run an annual simulation using a weather file, and (3) analyze the annual results.
Building Energy Modeling Basics
BEM software uses physics calculations to simulate the energy use of a building. BEM software accounts for the effects of weather via heat transfer through walls, windows, and the ground; occupancy; plug loads; lighting; the operation of the HVAC and water heating equipment; and the interactions between these subsystems.
BEM allows designers and engineers to predict the relative savings and costs of different equipment and design options and informs decision-making in energy efficiency use cases including design, energy efficiency code development, creation and testing of commercial products, and research.
The realities of changing weather, an evolving grid generation mix with a growing proportion of intermittent renewables, the introduction of behind-the-meter generation and storage, and a focus on grid response, grid stability, and resilience are changing the requirements of traditional BEM applications and elevating new applications.
The primary difference in requirements is the elevated importance of building system control and response. Annual energy use is still important. However, time of use and the ability to responsively shed and shift energy use—typically away from times of peak use or minimal renewable availability to times of lower use and greater renewable availability—is just as important. BEM needs to evolve to be able to evaluate advanced, responsive control strategies and to support use cases through simulation to evaluate energy use over minutes or hours instead of an entire year.
Enter Python EMS
For many years, EnergyPlus has had an application programming interface (API) that allowed users and outside software to interact with it during simulation. This feature was called Energy Management System (EMS) because its primary use was the implementation of custom control algorithms. These algorithms represented a virtual EMS for a virtual building represented by the simulation.
Historically, users of the EMS feature were forced to write their code in a very simple and bespoke computer language that was similar in capabilities to circa 1980 BASIC. The original EMS feature did not allow the use of outside libraries and could only use data that was available at the beginning of the simulation.
Recently, however, the EMS feature got a significant upgrade with support for the popular and powerful Python scripting language. Python EMS allows EnergyPlus to integrate and exchange data with a large number of outside tools and libraries. Notable examples include the ability to use machine learning libraries in the implementation of building control algorithms, the ability to acquire real-time data from equipment and building control systems, and the ability to be embedded in larger real-time applications that require fine-grain simulation control. These new capabilities allow users to develop, optimize, test, and deploy complex new building technologies and control strategies.
The National Renewable Energy Laboratory’s (NREL’s) Edwin Lee leads the EnergyPlus project and is the main developer of the Python EMS feature. Lee said advances in the modeling capabilities of EnergyPlus are especially important as building energy management becomes more complicated.
“It is very important to be able to further customize building models, especially as real-world experimentation is so expensive in comparison,” Lee said. “For instance, simulating the impact of different control algorithms is more practical than testing them out in the context of a real building, especially if that building does not exist yet.”
Python libraries offer new resources for building simulations, including:
Machine learning algorithms (PyTorch, Tensorflow)
Scientific routines that can handle large amounts of data (NumPy)
By adding Python code, users can create reusable libraries for building energy modeling projects.
Python EMS is implemented by embedding a Python interpreter within EnergyPlus. Python was chosen for its multiplatform support, large developer community, and a vast and growing set of libraries for everything from visualization to statistics to machine learning.
Many of these libraries simply “supercharge” the basic capability of the original EMS feature—the ability to customize EnergyPlus with new control strategies, new equipment models, new metrics and trend variables, and other modified or new simulation features.
Python libraries also allow simulation to interact with live data sources including remote servers and physical equipment like sensors and building automation systems. Python EMS allows EnergyPlus simulation to use real-time data sources including current weather, weather forecasts, real-time occupancy counts, actual indoor temperatures, equipment status, and others. The ability to integrate with live data sources enables “real-time” applications of energy simulation in which outside data and simulation results influence one another dynamically. Such real-time applications include co-simulation of multiple buildings—in which the simulation of each building views the simulation of others as external data sources—as well as product testing and dynamic model-driven building control.
Python EMS in Action: Supermarket Load Flexibility at Emerson Electric
One industry actor that has already leveraged Python EMS is Emerson Electric, a $17 billion company that develops automation solutions to enhance energy efficiency on both sides of the meter. In 2020, Emerson partnered with NREL to identify ways to improve the efficiency and load flexibility of a particularly energy-intensive sector: supermarkets. To save on operating costs—in addition to being high-energy, supermarkets are also notoriously low-margin—as well as make supermarkets into more grid-responsive assets, Emerson sought a 25-kW reduction of total building load over a peak-demand four-hour period while maintaining or improving both product quality and occupant comfort.
Supermarket refrigeration and HVAC are energy-intensive loads that offer a significant opportunity for flexibility but require careful monitoring and control to maintain food safety and quality and occupant comfort. Complicating matters is the fact that HVAC and refrigeration interact. That blast of cold air you feel in the dairy aisle reduces the need for air conditioning, but may introduce a need for heating! It is important to be able to predict interactions between the two systems to ensure the entire building is adjusting its load and actually netting savings overall. With perishable inventory at stake, supermarket operators are inclined to be risk averse and reluctant to implement new control strategies without extensive validation.
To explore new HVAC and refrigeration control strategies, Emerson and NREL researchers used EnergyPlus to model the Emerson Helix Center, a test bed for supermarket energy management. EnergyPlus modeled the HVAC and refrigeration systems and the interactions between them along with occupancy, plug loads, and lighting. The team used Python EMS to prototype different control strategies. It also used it to extend EnergyPlus to evaluate conditions and product temperatures inside refrigerated cases, predicting food safety. Without Python EMS, the team would have needed to perform costly experiments or attempt to predict case temperatures using post hoc calculations after running simulations in EnergyPlus.
NREL researcher Grant Wheeler leads the NREL team collaborating with Emerson. Wheeler values Python EMS for its ability to flexibly and quickly evaluate the conditions and simulate the numerous controls and strategies that interest Emerson.
“EnergyPlus allows us to create a virtual supermarket to experiment with, and PythonEMS allows us to rapidly prototype and test strategies. We can evaluate so many more scenarios so much more quickly than if we had to use a physical supermarket,” Wheeler said.
Next Step: Python EMS for Real-Time Control
The first phase of the Emerson project used Python EMS to customize EnergyPlus. Building on that successful phase, Emerson is now developing a predictive controller for dynamic supermarket energy system management. The controller will use Python EMS to embed EnergyPlus into a dynamic optimization-driven control framework. Using real-time weather forecasts and current supermarket refrigeration and HVAC conditions, the framework will use EnergyPlus to evaluate and select from among 6,000 possible control strategies for a given timeframe. Wheeler describes the approach as “a digital twin that can run scenarios, predict issues, and optimize operation over short time intervals using real-time data.” This proactive approach to building management will provide additional savings for supermarkets.
Praise From Emerson’s VP
“Emerson is working on developing tools to enable grid-interactive efficient buildings, and Python EMS has helped by adding capabilities to traditional building-level simulation tools, such as EnergyPlus. Specifically, Emerson in collaboration with NREL are using Python EMS to add physics-based refrigerated case models to a building-level supermarket model. This is helping us develop advanced model-based controls of the entire building, to improve operational efficiency, improve grid flexibility, and reduce its carbon footprint. Additionally, Python EMS will ultimately ensure the project’s success by providing modeling flexibility and convenience to building managers and end users by using a highly accessible programming language, Python.”
–Dr. Robert J. Comparin
Vice President for Research, Emerson Commercial and Residential Solutions
What’s Next for Python EMS: Machine Learning
Machine learning has transformed many industries, from social media and product marketing to medical research and even autonomous driving. It is poised to have similar impact on building control.
One of the driving motivations behind Python EMS is the recognition of the need to be able to use EnergyPlus to evaluate machine-learning-driven control strategies and drive this exciting research field forward, as few building managers would be willing to let researchers experiment with and fine-tune machine learning algorithms on a physical occupied building.