EnergyPlus Python Plugin

TMHP’s current EnergyPlus adapter exposes AirSourceHeatPumpBoiler as a PlantComponent:UserDefined surrogate. EnergyPlus still owns the plant loop, timestep, load dispatch, and storage-tank objects; TMHP answers each plant-solver call with a refrigerant-cycle-resolved steady state through analyze_steady().

Use this path when you have an EnergyPlus model and want the heat pump to be more physical than an empirical catalogue curve fit, without moving the whole building simulation out of EnergyPlus. This page is specific to the ASHPB reference adapter that exists today; it should not be read as a limit on TMHP’s shared refrigerant-cycle core.

What EnergyPlus Python Plugins are

EnergyPlus Python Plugins are user-defined Python classes that inherit from EnergyPlus’s EnergyPlusPlugin base class and override named methods for specific simulation calling points. In plugin mode, EnergyPlus is still launched as a normal EnergyPlus simulation; it starts an embedded Python interpreter and calls the plugin when the IDF declares the relevant plugin instance and calling manager (EnergyPlus Python Plugin documentation).

The broader EnergyPlus Python API exposes functional, runtime, and data exchange interfaces. The data exchange API is the part TMHP uses here: it reads plant-loop values and writes actuators or plugin globals during runtime callback methods (EnergyPlus Python API).

For TMHP, this is a narrow and useful boundary. EnergyPlus keeps the IDF, weather file, schedules, plant loop iteration, storage tank, sizing, and reporting. The current ASHPB adapter only replaces the heat-pump component response with a cycle-resolved steady solve, then returns outlet temperature, mass-flow request, electricity, and diagnostics to EnergyPlus.

Runtime contract

EnergyPlus Python Plugins run inside EnergyPlus’s embedded CPython. That means pyenergyplus comes from the EnergyPlus installation, not from PyPI, and TMHP plus its native dependencies must be importable by that embedded interpreter.

EnergyPlus plant solver
    -> PythonPlugin:SearchPaths
    -> tmhp.integrations.energyplus_plugin
    -> AirSourceHeatPumpBoiler.analyze_steady()

Practical setup:

  1. Install TMHP into an environment compatible with the EnergyPlus embedded Python ABI.

  2. Add that environment or package path with PythonPlugin:SearchPaths.

  3. Verify an import-only smoke plugin first. A wrong-ABI native wheel such as CoolProp can fail before the plant callback reaches useful logging.

What this enables

Workflow

Why the adapter matters

Replace a catalogue curve

Keep the same EnergyPlus plant model, but substitute a refrigerant-cycle TMHP solve for an empirical heat-pump performance curve.

Compare refrigerants in context

Run the same building and plant dispatch against different CoolProp-supported refrigerants without re-fitting component curves for every candidate.

Preserve EnergyPlus reporting

Leave EnergyPlus responsible for meters, schedules, plant loop iteration, and custom output variables while TMHP exposes compressor energy, power, convergence, and failure diagnostics.

The payoff is concrete: the whole EnergyPlus building stays exactly as it is, and the empirical catalogue curve in the plant slot is replaced by the current ASHPB refrigerant-cycle solve — so you can compare refrigerants in the same building and dispatch without re-fitting a performance curve for each candidate.

How one plant call works

EnergyPlus owns the plant loop, the storage tank, and the timestep. On each plant-solver call it hands the plugin the loop boundary values, and the plugin answers with a single steady cycle solve. (A one-shot sizing call runs once before the simulation to size the plant connection.) Walk through one call step by step:

The plugin memoizes the solve on rounded inputs, because the plant solver re-calls it with identical inputs many times per timestep. Humidity is rounded to the nearest 0.01 percentage point for both the cache key and the model input. The plugin converts the heat put into the loop into the outlet-temperature actuator with T_out = T_in + q_loop / (mdot * cp) (see Metered electricity and delivered heat for how q_loop and the metered electricity follow from the solved cycle).

IDF wiring

The adapter expects one PlantComponent:UserDefined component and two Python plugin managers:

EnergyPlus object

TMHP binding

PlantComponent:UserDefined

Default name ASHPB_UserDefined unless TMHP_UD_NAME is set.

Initialization program-calling manager

tmhp.integrations.energyplus_plugin.TmhpPlantInit sizes the plant connection so EnergyPlus can dispatch load.

Simulation program-calling manager

tmhp.integrations.energyplus_plugin.TmhpPlantSurrogate reads loop boundary values, solves TMHP, and writes actuators.

PythonPlugin:Variables

Declare tmhp_E_cmp_J for timestep energy. Optionally declare tmhp_E_cmp_W for instantaneous compressor power.

Declare the two weather variables as Output:Variable objects so the EnergyPlus CLI exposes their handles to the plugin. The plugin requests both variables on its first pass and sends weather-file humidity to the frost correction automatically.

Output:Variable, Environment, Site Outdoor Air Drybulb Temperature, Hourly;
Output:Variable, Environment, Site Outdoor Air Relative Humidity, Hourly;

Input / output boundary

The plugin reads only finite EnergyPlus boundary values before calling TMHP. Invalid required inputs are reported through issue_severe(), the plant component is driven to a safe off state, and the callback returns a non-zero status. The EPW format accepts relative humidity up to 110%, and EnergyPlus passes such readings on unclipped; the plugin uses a reading from 100 to 110% as 100% (saturated air). A missing humidity handle, a read flagged by EnergyPlus, or any other humidity value (negative, above 110%, not finite) triggers one warning per plugin instance. The solve then uses the model’s default humidity (84% for the standard frost correction). The TMHP_PLUGIN_LOG file counts the zone timesteps with a heating dispatch (warmup days excluded) solved with the weather humidity, with a reading used as 100%, and with the default, so a run shows how much of it fell back to 84%.

Direction

Field

Meaning

EnergyPlus -> TMHP

Inlet temperature

Plant Connection 1 inlet water temperature.

EnergyPlus -> TMHP

Inlet mass flow rate

Current loop-side flow available to the user-defined component.

EnergyPlus -> TMHP

Inlet specific heat

Loop fluid heat capacity used to convert heat rate to outlet temperature.

EnergyPlus -> TMHP

Load request

Positive heating load request for the plant component.

EnergyPlus -> TMHP

Outdoor drybulb temperature

Source-side air temperature T0 for the ASHPB cycle solve.

EnergyPlus -> TMHP

Outdoor relative humidity

Site Outdoor Air Relative Humidity in percent, converted to the fraction RH_out for the frost correction; 100 to 110% is used as 100%.

TMHP -> EnergyPlus

Outlet temperature actuator

Inlet temperature plus the heat put into the loop (q_loop, never more than the load request) divided by m_dot * cp, at most TOUT_MAX (95 °C).

TMHP -> EnergyPlus

Mass-flow actuator

Requests design flow when load is present and EnergyPlus has not yet provided loop flow.

TMHP -> EnergyPlus

tmhp_E_cmp_J

Timestep electricity of the whole system (compressor and outdoor fan, E_tot) in joules. The name is historical.

TMHP -> EnergyPlus

tmhp_E_cmp_W

Optional instantaneous system electricity (E_tot) in watts.

Configuration

The adapter reads its configuration once at import from environment variables:

Variable

Meaning

TMHP_ASHPB_REF

Refrigerant name. Default R32.

TMHP_ASHPB_CAPACITY

Nominal heat-pump capacity in watts. Default 15000.

TMHP_UD_NAME

PlantComponent:UserDefined object name. Default ASHPB_UserDefined.

TMHP_LOOP_DESIGN_VDOT

Design loop volume flow in m3/s. Default 0.003.

TMHP_EPLUS_ECMP_ENERGY_GLOBAL

Plugin global receiving the timestep system electricity (E_tot) in joules. Default tmhp_E_cmp_J.

TMHP_EPLUS_ECMP_POWER_GLOBAL

Optional plugin global receiving the instantaneous system electricity in watts. Default tmhp_E_cmp_W.

TMHP_PLUGIN_LOG

Optional path for per-call and convergence-tally logging. Each logged solve reports the humidity used by the model, or default when the plugin falls back to the model’s default. The tally line written every 5,000 dispatched calls adds outdoor_RH_timesteps: the zone timesteps with a heating dispatch (warmup days excluded) solved with the weather humidity (weather), with a reading above 100% used as 100% (clipped_to_100), and with the model default (default). The same counts for the whole run are written once more as an [outdoor RH final] line when the plugin’s Python interpreter shuts down: at the end of the run for the EnergyPlus command line, at the exit of the host program for a run started through the EnergyPlus Python API. The line names its run with a random id (run <12 hex digits> (pid <process> #<n>)), so several runs in one process or appended to one log file can be told apart. A zone timestep in which any call fell back to the default counts as default.

Metered electricity and delivered heat

The metered power is the system total E_tot of the solved cycle, compressor plus outdoor fan. The heat handed to the plant loop and the metered power always belong to the same operating state:

q_loop  = min(Q_cycle, load request, m_dot * cp * (TOUT_MAX - T_in))
E_meter = E_tot * q_loop / Q_cycle

Q_cycle and E_tot are the heat and electricity of the solved, continuously running cycle; q_loop / Q_cycle is the share of the timestep it runs.

  • Minimum-speed clamp. A variable-speed machine cannot deliver less than its minimum-speed capacity. At a small part load the solved cycle can deliver several times the request (e.g. 6.8 kW for 1.5 kW). EnergyPlus documents Load Request for Plant Connection N as the desired operating capacity of a connection that meets the loop load, and the loop outlet temperature fixes the heat the loop receives, so delivering Q_cycle would overheat the loop and its storage tank. The plugin therefore treats the clamp as on/off cycling: the time-averaged heat equals the request and the electricity is scaled by the same duty fraction. analyze_steady now reports such a point as that cycling mean itself (Steady state below the minimum capacity): the heat of the row is the request and its electrical input carries the EN 14825 degradation for a unit delivering to water (Cc = 0.9 unless the model is built with another Cd_cycling), so the plugin’s own scaling leaves the row as it is and the metered electricity includes that degradation. A model built with Cd_cycling=None returns the continuous point and is scaled by the plugin as before, without a penalty.

  • Outlet limit. Heat that would push the outlet above TOUT_MAX is not delivered, and the electricity that would have produced it is not metered.

Why this uses analyze_steady()

EnergyPlus is already the dynamic simulation environment. It owns the plant loop iteration, the storage tank, and the timestep integration. The plugin therefore asks TMHP for a steady component response:

result = hp.analyze_steady(
    T_tank_w=t_in,
    T0=t0,
    Q_ref_tank=q_target,
    m_dot_w=m_dot,
    RH_out=rh_out,
)

The FMU adapter uses step() instead because the FMU owns its own dynamic state. Keeping those seams separate prevents EnergyPlus tank state and FMU tank state from being mixed.

API reference

The implementation API is documented at tmhp.integrations.energyplus_plugin.