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

Revision history [back]

Refer to the Data Transfer API: https://nrel.github.io/EnergyPlus/api/python/datatransfer.html

Potentially of interest are actual_date_time(), actual_time(), current_time(), day_of_month(), month(), year(), minutes()

I have an example here: https://github.com/jmarrec/OpenStudio_to_EnergyPlusAPI/blob/main/OpenStudio_to_EnergyPlusAPI.ipynb

Something along these lines will get you started:

month = api.exchange.month(state)
day = api.exchange.day_of_month(state)
hour = api.exchange.hour(state)
minute = api.exchange.minutes(state)
current_time = api.exchange.current_time(state)
actual_date_time = api.exchange.actual_date_time(state)
actual_time = api.exchange.actual_time(state)

# Year is bogus, seems to be reading the weather file year instead...         
# So harcode it to 2009
# year = api.exchange.year(state)
year = 2009


timedelta = datetime.timedelta()
if hour >= 24.0:
    hour = 23.0
    timedelta += datetime.timedelta(hours=1)
if minute >= 60.0:
    minute = 59
    timedelta += datetime.timedelta(minutes=1)

dt = datetime.datetime(year=year, month=month, day=day, hour=hour, minute=minute)
dt += timedelta

Refer to the Data Transfer API: https://nrel.github.io/EnergyPlus/api/python/datatransfer.html

Potentially of interest are actual_date_time(), actual_time(), current_time(), day_of_month(), month(), year(), minutes()

I have an example here: https://github.com/jmarrec/OpenStudio_to_EnergyPlusAPI/blob/main/OpenStudio_to_EnergyPlusAPI.ipynb

Something along these lines will get you started:

month = api.exchange.month(state)
day = api.exchange.day_of_month(state)
hour = api.exchange.hour(state)
minute = api.exchange.minutes(state)
current_time = api.exchange.current_time(state)
actual_date_time = api.exchange.actual_date_time(state)
actual_time = api.exchange.actual_time(state)

# Year is bogus, seems to be reading the weather file year instead...         
# So harcode it to 2009
# year = api.exchange.year(state)
year = 2009

 # E+ uses "end of timestep" conventions, which python does NOT like AT ALL.
timedelta = datetime.timedelta()
if hour >= 24.0:
    hour = 23.0
    timedelta += datetime.timedelta(hours=1)
if minute >= 60.0:
    minute = 59
    timedelta += datetime.timedelta(minutes=1)

dt = datetime.datetime(year=year, month=month, day=day, hour=hour, minute=minute)
dt += timedelta