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

Revision history [back]

Python API skipping function when not ready

I have used EnergyPlus EMS for a long time and recently attempted using the Python API. I implemented the example from the EnergyPlus GitHub: https://github.com/NREL/EnergyPlus/blob/develop/tst/EnergyPlus/api/TestDataTransfer.py in PyCharm. To verify that I was using it correctly and understood the details, I created an identical idf file with an EMS program that matched the logic and ran it in standalone EnergyPlus. However, when I compared the outputs, there was a small difference for many of the reported values.

When writing a custom Python function to be called at each callback point, it is required to include the api.exchange.api_data_fully_ready(state) to ensure that the actuator is not manipulated before the api is ready. However, I believe this means that for the first few hundred or thousand callbacks, the function is not applied. I added a counter to compare the number of times the function was called outside the api.exchange.api_data_fully_ready(state) condition versus inside the condition, and they do not match. The counter also did not match the number of times the EMS program was called in the .edd file.

This page: https://bigladdersoftware.com/epx/docs/9-3/input-output-reference/api-usage.html#subsec:data-exchange-api explains that "For almost all applications, if this is not ready, the client should just return from the callback and let EnergyPlus continue, and wait until it is ready before doing any manipulation." However, from my experiment, it leads to a discrepancy between the standalone EnergyPlus EMS and the Python API results. Is there a way to make sure it is fully ready BEFORE the first callback? So the results end up the same? I tried with my own examples as well and found the same issue.

Python API skipping function when not ready

I have used EnergyPlus EMS for a long time and recently attempted using the Python API. I implemented the example from the EnergyPlus GitHub: https://github.com/NREL/EnergyPlus/blob/develop/tst/EnergyPlus/api/TestDataTransfer.py in PyCharm. To verify that I was using it correctly and understood the details, I created an identical idf file with an EMS program that matched the logic and ran it in standalone EnergyPlus. However, when I compared the outputs, there was a small difference for many of the reported values.

When writing a custom Python function to be called at each callback point, it is required to include the api.exchange.api_data_fully_ready(state) to ensure that the actuator is not manipulated before the api is ready. However, I believe this means that for the first few hundred or thousand callbacks, the function is not applied. I added a counter to compare the number of times the function was called outside the api.exchange.api_data_fully_ready(state) condition versus inside the condition, and they do not match. The counter also did not match the number of times the EMS program was called in the .edd file.

This page: https://bigladdersoftware.com/epx/docs/9-3/input-output-reference/api-usage.html#subsec:data-exchange-api explains that "For almost all applications, if this is not ready, the client should just return from the callback and let EnergyPlus continue, and wait until it is ready before doing any manipulation." However, from my experiment, it leads to a discrepancy between the standalone EnergyPlus EMS and the Python API results. Is there a way to make sure it is fully ready BEFORE the first callback? So the results end up the same? I tried with my own examples as well and found the same issue.