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

Correct way to use DataExchange API

asked 2020-11-01 16:59:32 -0600

Red gravatar image

updated 2020-11-01 22:02:40 -0600

I am trying to use the DataExchange API to read the hourly "Site Outdoor Air Drybulb Temperature" variable. The code I use is from the official documentation:

one_time = True
api_ready = False
outdoor_dry_sensor = 0
outdoor_temp = []
def time_step_handler(state):
  global api_ready, one_time, outdoor_dry_sensor
  if one_time:
      api_ready = True
      outdoor_dry_sensor =
          state, u"Site Outdoor Air Drybulb Temperature", u"ENVIRONMENT"
      if outdoor_dry_sensor == -1:
      one_time = False
  if api_ready:
    oa_temp =, outdoor_dry_sensor)
api = EnergyPlusAPI()
state = api.state_manager.new_state()
api.runtime.callback_end_zone_timestep_after_zone_reporting(state, time_step_handler)

These are some of my relevant simulation parameters:

Timestep = 1
RunPeriod from 1/1 to 1/2
SizingPeriod:WeatherFileDays from 1/1 to 1/2

so I expected to get an "outdoor_temp" of size 48 that has weather data from day1 and day2. but I get an "outdoor_temp" of size 240 that has weather data of day1 and day2 in this order:

day1 day1 day1 day1 day2 day1 day1 day1 day1 day2

What am I doing wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-12-14 12:53:06 -0600

hermmanhender gravatar image

Hi. I was doing some tests with the API and I came across some things like that.

First, you could use the () function to avoid calculations during the warm-up stage of the simulation. It is easy to use a conditional if (state) == 0: which checks for equality to 0 (the function returns 1 if it is warm-up and 0 otherwise).

Second, it sure returns all that amount of information and not the 48 measurements that you would like because you are calculating in each timestep of the simulation. You can use a conditional as follows if (state)% n == 0 :, where n would be equal to the timestep that you have configured in your IDF if you want hourly values.

I hope you find it useful.


edit flag offensive delete link more


Thank you @hermmanhender. Those 3 extra repetitions of day1 of simulation time were indeed due to the warmup stages. I did find a way to avoid that, but your solution is easier. My other problem was setting SimulationControl:Run Simulation for Sizing Periods to Yes, which caused another repetition in my output.

Red gravatar image Red  ( 2020-12-16 08:38:33 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer


Question Tools



Asked: 2020-11-01 16:59:32 -0600

Seen: 210 times

Last updated: Dec 16 '20