Last active
July 12, 2021 12:32
-
-
Save mitchute/5a9f107aba213f1b683f4052027fc162 to your computer and use it in GitHub Desktop.
Python Plugin Relative Humidity Actuator Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PythonPlugin:Instance, | |
Rel Hum Test, !- Name | |
Yes, !- Run During Warmup Days | |
PythonTest, !- Python Module Name | |
Test; !- Plugin Class Name | |
PythonPlugin:Variables, | |
MyGlobalVariables, !- Name | |
RelHumFromOutputVar, !- Variable Name 1 | |
RelHumFromActuator; !- Variable Name 2 | |
PythonPlugin:OutputVariable, | |
Rel Hum From Output Variable, !- Name | |
RelHumFromOutputVar, !- Python Plugin Variable Name | |
Averaged, !- Type of Data in Variable | |
SystemTimestep; !- Update Frequency | |
PythonPlugin:OutputVariable, | |
Rel Hum From Actuator, !- Name | |
RelHumFromActuator, !- Python Plugin Variable Name | |
Averaged, !- Type of Data in Variable | |
SystemTimestep; !- Update Frequency | |
Output:Variable,*,Site Outdoor Air Relative Humidity,hourly; | |
Output:Variable,Rel Hum From Output Variable,PythonPlugin:OutputVariable,hourly; | |
Output:Variable,Rel Hum From Actuator,PythonPlugin:OutputVariable,hourly; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test(EnergyPlusPlugin): | |
def __init__(self): | |
super().__init__() | |
# class member variables | |
self.relhum_from_output_var_handle = None | |
self.relhum_from_actuator_var_handle = None | |
self.outdoor_air_relhum_handle = None | |
self.outdoor_air_relhum_actuator_handle = None | |
self.need_to_get_handles = True | |
def get_handles(self, state): | |
# get variable handles and save for later | |
self.outdoor_air_relhum_handle = self.api.exchange.get_variable_handle(state, | |
"Site Outdoor Air Relative Humidity", | |
"Environment") | |
self.outdoor_air_relhum_actuator_handle = self.api.exchange.get_actuator_handle(state, | |
"Weather Data", | |
"Outdoor Relative Humidity", | |
"Environment") | |
self.relhum_from_output_var_handle = self.api.exchange.get_global_handle(state, "RelHumFromOutputVar") | |
self.relhum_from_actuator_var_handle = self.api.exchange.get_global_handle(state, "RelHumFromActuator") | |
self.need_to_get_handles = False | |
def on_begin_zone_timestep_before_set_current_weather(self, state) -> int: | |
# initialize if the API is ready | |
if self.need_to_get_handles: | |
if self.api.exchange.api_data_fully_ready(state): | |
self.get_handles(state) | |
else: | |
return 0 | |
# get the current relative humidity value from the output variable, assign it to the global variable | |
current_relhum = self.api.exchange.get_variable_value(state, self.outdoor_air_relhum_handle) | |
self.api.exchange.set_global_value(state, self.relhum_from_output_var_handle, current_relhum) | |
# set the new ODA relhum value via the actuator and assign it to the global variable | |
new_relhum = 34.56789 | |
self.api.exchange.set_actuator_value(state, self.outdoor_air_relhum_actuator_handle, new_relhum) | |
self.api.exchange.set_global_value(state, self.relhum_from_actuator_var_handle, new_relhum) | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment