API Python examples of Data Transfer in EnergyPlus
Thank you again for your responses. I am attaching the Python script and the list of actuators for a better understanding.
1) My goal is to override the air properties at the inlet of the AHUs (not the weather file). Thus, from the available API data list of the simulation, I chose all the actuators related to the “Outdoor Air System Node” to perform the override of the Wet bulb temperature, which are (…._OAINLET NODE, …._COOLC COND OA NODE, … _COOLCOA REF NODE) and I used almost all the calling points. However, I could not get any satisfactory overrideC:\fakepath\Actuators.png.
class AverageZoneCalcs(EnergyPlusPlugin):
def __init__(self):
super().__init__()
self.do_setup = True
def on_end_of_zone_timestep_before_zone_reporting(self, state) -> int:
if self.do_setup:
self.data["zone_volumes"] = []
self.data["zone_temps"] = []
self.data["zone_humidity_ratios"] = []
zone_names = ["Perimeter_top_ZN_" + str(i) for i in range(1, 5)] + ["Perimeter_mid_ZN_" + str(i) for i in range(1, 5)] + ["Perimeter_bot_ZN_" + str(i) for i in range(1, 5)] + ["Core_bottom", "TopFloor_Plenum", "MidFloor_Plenum", "FirstFloor_Plenum", "Core_mid", "Core_top"]
for zone_name in zone_names:
handle = self.api.exchange.get_internal_variable_handle(state, "Zone Air Volume", zone_name)
zone_volume = self.api.exchange.get_internal_variable_value(state, handle)
self.data["zone_volumes"].append(zone_volume)
self.data["zone_temps"].append(
self.api.exchange.get_variable_handle(state, "Zone Mean Air Temperature", zone_name)
)
self.data["zone_humidity_ratios"].append(
self.api.exchange.get_variable_handle(state, "Zone Mean Air Humidity Ratio", zone_name)
)
self.data["avg_temp_variable"] = self.api.exchange.get_global_handle(state, "AverageBuildingTemp")
self.data["avg_hum_ratio_variable"] = self.api.exchange.get_global_handle(state, "AverageBuildingHR")
self.do_setup = False
zone_temps = list()
zone_humidity_ratios = list()
for t_handle in self.data["zone_temps"]:
zone_temps.append(self.api.exchange.get_variable_value(state, t_handle))
for hr_handle in self.data["zone_humidity_ratios"]:
zone_humidity_ratios.append(self.api.exchange.get_variable_value(state, hr_handle))
numerator_t = 0.0
numerator_hr = 0.0
denominator = 0.0
for i in range(5):
numerator_t += self.data["zone_volumes"][i] * zone_temps[i]
numerator_hr += self.data["zone_volumes"][i] * zone_humidity_ratios[i]
denominator += self.data["zone_volumes"][i]
average_temp = numerator_t / denominator
average_HR = numerator_hr / denominator
self.api.exchange.set_global_value(state, self.data["avg_temp_variable"], average_temp)
self.api.exchange.set_global_value(state, self.data["avg_hum_ratio_variable"], average_HR)
return 0
class Dehumidifier(EnergyPlusPlugin):
def __init__(self):
super().__init__()
self.need_to_get_handles = True
self.handles = {}
self.values = {}
self.psych = None
self.OA_DBT_handle = None
self.OA_WBT_handle = None
self.Patm_handle = None
self.WBT_override_handle = None
def get_handles(self, state):
if self.need_to_get_handles:
self.handles["OA_DBT"] = self.api.exchange.get_variable_handle(
state,
"Site Outdoor Air Drybulb Temperature",
"Environment"
)
self.handles["OA_WBT"] = self.api.exchange.get_variable_handle(
state,
"Site Outdoor Air Wetbulb Temperature",
"Environment"
)
self.handles["Patm"] = self.api.exchange.get_variable_handle(
state,
"Site Outdoor Air Barometric Pressure",
"Environment"
)
self.handles["PACU_BOT_WBT_override"] = self.api.exchange.get_actuator_handle(
state,
"Outdoor Air System Node",
"Wetbulb Temperature",
"PACU_VAV_BOT_OAINLET NODE"
)
self.handles["PACU_MID_WBT_override"] = self.api.exchange.get_actuator_handle(
state,
"Outdoor Air System Node",
"Wetbulb Temperature",
"PACU_VAV_MID_OAINLET NODE"
)
self.handles["PACU_TOP_WBT_override"] = self.api.exchange.get_actuator_handle(
state,
"Outdoor Air System Node",
"Wetbulb Temperature",
"PACU_VAV_TOP_OAINLET NODE"
)
self.need_to_get_handles = False
def handles_are_valid(self, state):
handles_are_valid = True
for (k, v) in self.handles.items():
if v == -1:
handles_are_valid = False
print(k, v)
self.api.runtime.issue_severe(state, f"Handle not found for '{k}'")
return handles_are_valid
def OA_inlet_manager(self, state ...
I was not able to completely follow your code, but I did try to write a simpler program that set the outdoor air conditions on the 5ZoneAirCooled.idf example file that is shipped with E+. It worked for the drybulb temperature, but not the wetbulb. I think there is an E+ bug with setting the wetbulb temperature. I have filed an E+ issue. That may be why you are not seeing any override.