Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello.

Here a possible solution to your problem.

import sys
sys.path.insert(0, 'C:/EnergyPlusV9-4-0')
from pyenergyplus.api import EnergyPlusAPI
api = EnergyPlusAPI()

#Define your function to execute in runtime
def my_function(state):
   if api.exchange.api_data_fully_ready(state): #Necessary condition
        if api.exchange.warmup_flag(state) == 0:
           # Handles
           To_handle = api.exchange.get_variable_handle(state, "Site Outdoor Air Drybulb Temperature", "Environment")
           Ti_handle = api.exchange.get_variable_handle(state, "Zone Mean Air Temperature", "Thermal Zone: Modelo_Simple")
            # Variable value
            To = api.exchange.get_variable_value(state, To_handle)      
            Ti = api.exchange.get_variable_value(state, Ti_handle)
            '''Here you can put Ti in a DataFrame, array, other'''

#After define you function, you must initializate the program
state = api.state_manager.new_state() #Necessary condition
api.state_manager.reset_state(state)
api.runtime.callback_begin_zone_timestep_after_init_heat_balance(state, my_function)
api.runtime.run_energyplus(state, ['-d', Folder_Output_path, '-w', Weather_file_path, IDF_file_path])

I hope that this code will be useful.

Best Regards, Germán Henderson

Hello.

Here a possible solution to your problem.

import sys
sys.path.insert(0, 'C:/EnergyPlusV9-4-0')
from pyenergyplus.api import EnergyPlusAPI
api = EnergyPlusAPI()

#Define your function to execute in runtime
def my_function(state):
   if api.exchange.api_data_fully_ready(state): #Necessary condition
        if api.exchange.warmup_flag(state) == 0:
           # Handles
           To_handle = api.exchange.get_variable_handle(state, "Site Outdoor Air Drybulb Temperature", "Environment")
           Ti_handle = api.exchange.get_variable_handle(state, "Zone Mean Air Temperature", "Thermal Zone: Modelo_Simple")
            # Variable value
            To = api.exchange.get_variable_value(state, To_handle)      
            Ti = api.exchange.get_variable_value(state, Ti_handle)
            '''Here you can put Ti in a DataFrame, array, other'''

#After define you function, you must initializate the program
state = api.state_manager.new_state() #Necessary condition
api.state_manager.reset_state(state)
api.runtime.callback_begin_zone_timestep_after_init_heat_balance(state, my_function)
api.runtime.run_energyplus(state, ['-d', Folder_Output_path, '-w', Weather_file_path, IDF_file_path])

I hope that this code will be useful.

Best Regards, Germán Henderson