Large Language Model-Based Method for HVAC System Control Code Automatic Generation
Abstract
1. Introduction
- (1)
- HVAC systems involve various devices and data sources, such as a single room’s terminal system, which includes devices like air valves, water valves, frequency converters, temperature sensors, pressure sensors, etc., involving a dozen variables. Different devices process and transmit data in distinct ways, with a typical example being different data units leading to variations in data magnitude. The carriers of this information include text documents, images, tables, and more, which face the problem of vast amounts of information but limited effective information. How to integrate multifaceted information and efficiently convert it into the required control commands remains an insufficiently solved problem.
- (2)
- Actual applications have high requirements for safety and reliability. AI-based control methods often face trust issues, which limit their application in engineering practice. AI control methods are typically data-driven, meaning they discover patterns through training on large amounts of data to achieve precise control. However, data-driven methods suffer from poor interpretability, with results based on statistics rather than logical reasoning. In control scenarios where logic is emphasized, the difficulty in explaining the process can lead to trust issues. Code generated by LLMs often exhibits considerable uncertainty and may sometimes fail to compile or meet specified requirements [32].
- (3)
- The generation of control code for HVAC (Heating, Ventilation, and Air Conditioning) systems involves multiple complex and interrelated tasks, such as information integration, code generation, code verification, and modification. These tasks require different capabilities and processing logic. Although large language models excel in natural language processing and code generation, they were originally designed as general-purpose tools and lack a deep understanding of the complex requirements in specific domains [38]. For example, information integration requires extracting valid information from multi-source heterogeneous data, code generation must adhere to strict logic and rules, and code verification necessitates high-precision safety evaluation. These tasks not only require powerful generative capabilities but also demand in-depth domain knowledge, logical reasoning abilities, and rigorous safety control. When executed solely by large language models, they may fail to fully cover these requirements, potentially leading to incomplete, inaccurate, or impractical results that do not meet the demands of real-world applications.
2. Materials and Methods
2.1. Multi-Agent Framework Overview
2.1.1. Workflow Description
2.1.2. Agent Roles and Functions
2.1.3. Support Components in Multi-Agent Framework
2.2. Multi-Agent Collaboration Process
2.2.1. Preliminary Knowledge Preparation
2.2.2. Code Generation
2.2.3. Code Validation and Debugging
2.2.4. Code Execution and Case Collection
3. Results
3.1. Experimental Design
3.2. Evaluation Criteria
3.2.1. Syntax Correctness (SC)
3.2.2. Functional Completeness (FC)
3.2.3. Control Logic (CL)
3.2.4. Overall Accuracy (ACC)
3.2.5. Reliability (RAL)
3.3. Performance of the Framework
3.3.1. Efficiency
3.3.2. Accuracy
3.3.3. Scalability
3.3.4. Reliability
3.4. Other Experiments
3.4.1. The Impact of Code Segment Splitting
3.4.2. The Impact of Each Element in the Prompt on Accuracy
3.5. Real-World Deployment
3.5.1. Hardware Architecture and Deployment
3.5.2. Control Code Execution Mechanism
4. Discussion
4.1. Advantages of the LLM-Based Method
4.2. Limitations
5. Conclusions
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
Abbreviations
| LLM | Large Language Model |
| HVAC | Heating, Ventilation and Air Conditioning |
| MBD | Model-Based Design |
| RAG | Retrieval-Augmented Generation |
Appendix A
| ######## System |
| You are an expert in the HVAC field, proficient in writing control code for air conditioning terminals using the Rust language. |
| ######## Task Description |
| Your task is to write a Rust program to control an air conditioning terminal to maintain a stable room temperature. |
| ######## Scenario Description |
| The room you need to regulate has a fresh air unit that supplies air from outdoors and performs primary cooling. Indoors, there is a return air unit responsible for secondary cooling, and several fume hoods continuously exhaust air outdoors. The outdoor temperature is unknown. The user’s target temperature is unknown. The target temperature is: 26.0 °C. The room has 2 fume hoods, with face velocities of “fume_hood1_114_1_current_face_velocity” and “fume_hood1_114_2_current_face_velocity,” and cross-sectional heights of “fume_hood1_114_1_window1_height_value” and “fume_hood1_114_2_window1_height_value,” respectively. The width is fixed at 1.266 m. You can control the fresh air unit to supply air indoors. The controllable variable is the inverter frequency: “AO2_room1_114_frequency_setpoint,” which is proportional to the air supply volume. You can control the water valve opening: “AO1_room1_114_air_conditioning_water_valve_opening” to regulate the supply air temperature. The larger the opening, the lower the supply air temperature, and the smaller the opening, the higher the supply air temperature. The following variables may have different room numbers, which is normal. Be sure to name them exactly as shown below. You can observe the current supply air temperature: “room1_114_AHU_supply_air_temperature,” indoor temperature: “room1_113_fan_coil_return_air_temperature_2,” whether the air valve is open: “DO1_room1_114_air_valve_switch_command,” whether the inverter is on: “DO2_room1_114_inverter_start_stop_control_command,” the feedback of the water valve opening: “AI7_room1_114_fresh_air_unit_water_valve_opening_feedback,” the water valve opening setpoint: “AO1_room1_114_air_conditioning_water_valve_opening,” and the feedback of the inverter frequency: “room1_114_frequency_feedback.” The correction factor for fume hood data is 1000.0, which may differ from the example. Use this value for correction. |
| ######## Rules |
The following safety rules must be followed:
|
| ########## Requirements |
| Indoor air pressure and temperature must be maintained, meaning the fresh air unit’s supply volume must be close to the fume hoods’ exhaust volume. The supply air temperature must be lower than the indoor temperature; otherwise, condensation may occur, leading to user complaints. The supply air temperature must not be significantly lower than the user’s setpoint; otherwise, it may cause user complaints. You must return a single function named ‘loop_fn’ and provide a concise description in the comments. Please return the result to me in XML format as follows: <Code Start> …… <Code End> Where ‘……’ contains only the code, with no additional information. To ensure direct compilation of the code in ‘……,’ provide only the single Rust function named ‘loop_fn’ and its comments. Do not include any other text. No explanation is needed! |
| ######### Example |
| The example below is highly similar to the target function. You only need to replace the variable names and note any changes in the number of variables. Be sure to follow the structure, logic, and generic variable names provided in the example! The room you need to regulate has a fresh air unit that supplies air from outdoors and performs primary cooling. Indoors, there is a return air unit responsible for secondary cooling, and several fume hoods continuously exhaust air outdoors. The outdoor temperature is unknown. The user’s target temperature is unknown. The average room temperatures recorded in the past few days were: 24 °C, 24.6 °C, 24.4 °C. The room has 2 fume hoods, with face velocities of “fume_hood1_110_1_current_face_velocity” and “fume_hood1_110_2_current_face_velocity,” and cross-sectional heights of “fume_hood1_110_1_window1_height_value” and “fume_hood1_110_2_window1_height_value,” with a constant width of 1.286 m. You can control the fresh air unit to supply air indoors. The controllable variable is the inverter frequency pv, which is proportional to the air supply volume. You can control the water valve opening “AO1_room1_110_air_conditioning_water_valve_opening” to regulate the supply air temperature “room1_110_AHU_supply_air_temperature.” The larger the opening “AO1_room1_110_air_conditioning_water_valve_opening,” the lower the supply air temperature “room1_110_AHU_supply_air_temperature,” and the smaller the opening “AO1_room1_110_air_conditioning_water_valve_opening,” the higher the supply air temperature “room1_110_AHU_supply_air_temperature.” You can observe the current supply air temperature “room1_110_AHU_supply_air_temperature,” indoor temperature “room1_110_return_air_temperature_sensor,” whether the air valve is open “DO1_room1_110_air_valve_switch_command,” whether the inverter is on “DO2_room1_110_inverter_start_stop_control_command,” the feedback of the water valve opening “AI7_room1_110_fresh_air_unit_water_valve_opening_feedback,” and the water valve opening setpoint “AO1_room1_110_air_conditioning_water_valve_opening.” |
| ######### Code Example |
| <Code Start> Function loop_fn() // Initialize values InitializePreviousValues() // Calculate temperature difference v590 = CalculateTemperatureDifference() // Correct data for window height CorrectWindowHeightValues() // Calculate total ventilation volume f1, f2, fl = CalculateVentilationVolume() // Determine if air supply is needed based on air volume and temperature If IsAirSupplyRequired(fl) Then // Check and manage inverter, frequency setpoint, and air valve ManageInverterAndAirValve() Else // Manage system start: open water valve and air valve If IsSystemStarting() Then OpenWaterValve() If IsWaterValveOpen() Then OpenAirValve() If IsAirValveOpen() Then StartInverterAndAdjustFrequency() AdjustWaterValveOpening() End If End If End If End If End Function<Code End> |
References
- Zhang, C.; Li, J.; Zhao, Y.; Li, T.; Chen, Q.; Zhang, X.; Qiu, W. Problem of data imbalance in building energy load prediction: Concept, influence, and solution. Appl. Energy 2021, 297, 117139. [Google Scholar] [CrossRef]
- Gu, J.; Wang, J.; Qi, C.; Min, C.; Sundén, B. Medium-term heat load prediction for an existing residential building based on a wireless on-off control system. Energy 2018, 152, 709–718. [Google Scholar] [CrossRef]
- Pérez-Lombard, L.; Ortiz, J.; Pout, C. A review on buildings energy consumption information. Energy Build. 2008, 40, 394–398. [Google Scholar] [CrossRef]
- Krstić-Furundžić, A.; Vujošević, M.; Petrovski, A. Energy and environmental performance of the office building facade scenarios. Energy 2019, 183, 437–447. [Google Scholar] [CrossRef]
- Lee, D.; Cheng, C.-C. Energy savings by energy management systems: A review. Renew. Sustain. Energy Rev. 2016, 56, 760–777. [Google Scholar] [CrossRef]
- Schumacher, F.; Fay, A. Formal representation of GRAFCET to automatically generate control code. Control Eng. Pract. 2014, 33, 84–93. [Google Scholar] [CrossRef]
- Li, Z.; Jia, H.; Zhang, Y.; Chen, T.; Yuan, L.; Cao, L.; Wang, X. AutoFFT: A template-based FFT codes auto-generation framework for ARM and X86 CPUs. In Proceedings of the International Conference for High Performance Computing, Networking, Storage, and Analysis 2019, Denver, CO, USA, 17–22 November 2019. [Google Scholar]
- Hu, K.; Duan, Z.; Wang, J.; Gao, L.; Shang, L. Template-based AADL automatic code generation. Front. Comput. Sci. 2019, 13, 698–714. [Google Scholar] [CrossRef]
- Yue, W.; Dan, L.I.; Xiao, D.; Zhigang, L. Energy storage converter study based on MATLAB auto code generation. Power Electron. 2014, 48, 3. [Google Scholar] [CrossRef]
- O’Halloran, C. Automated verification of code automatically generated from Simulink. Autom. Softw. Eng. 2013, 20, 237–264. [Google Scholar] [CrossRef]
- Lee, S.C.; Gagas, B.S.; Wang, Y.; Lorenz, R.D. Implementing advanced AC drive controls using auto-coding methods. In Proceedings of the 18th International Conference on Electrical Machines and Systems (ICEMS), Pattaya, Thailand, 25–28 October 2015. [Google Scholar]
- Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A.N.; Kaiser, Ł.; Polosukhin, I. Attention is all you need. Adv. Neural Inf. Process. Syst. 2017, 30, 5998–6008. [Google Scholar]
- Lin, T.; Wang, Y.; Liu, X.; Qiu, X. A survey of transformers. arXiv 2022, arXiv:2106.04554. [Google Scholar] [CrossRef]
- Brown, T.B.; Mann, B.; Ryder, N.; Subbiah, M.; Kaplan, J.D.; Dhariwal, P.; Neelakantan, A.; Shyam, P.; Sastry, G.; Askell, A.; et al. Language models are few-shot learners. Adv. Neural Inf. Process. Syst. 2020, 33, 1877–1901. [Google Scholar]
- Chowdhery, A.; Narang, S.; Devlin, J.; Bosma, M.; Mishra, G.; Roberts, A.; Barham, P.; Chung, H.W.; Sutton, C.; Gehrmann, S.; et al. PaLM: Scaling language modeling with pathways. arXiv 2023, arXiv:2204.02311. [Google Scholar]
- Chung, H.W.; Hou, L.; Longpre, S.; Zoph, B.; Tay, Y.; Fedus, W.; Li, Y.; Wang, X.; Dehghani, M.; Brahma, S.; et al. Scaling instruction-finetuned language models. arXiv 2022, arXiv:2210.11416. [Google Scholar] [CrossRef]
- Zhang, S.; Dong, L.; Li, X.; Zhang, S.; Sun, X.; Wang, S.; Li, J.; Hu, R.; Zhang, T.; Wu, F.; et al. Instruction Tuning for Large Language Models: A Survey. arXiv 2023, arXiv:2308.10792. [Google Scholar] [CrossRef]
- Wei, J.; Wang, X.; Schuurmans, D.; Bosma, M.; Xia, F.; Chi, E.; Le, V.Q.; Zhou, D. Chain-of-thought prompting elicits reasoning in large language models. Adv. Neural Inf. Process. Syst. 2022, 35, 24824–24837. [Google Scholar]
- Tarassow, A. The potential of LLMs for coding with low-resource and domain-specific programming languages. arXiv 2023, arXiv:2307.13018. [Google Scholar]
- Liu, Z.H.; Zeng, R.N.; Wang, D.X.; Peng, G.Y.; Wang, J.Y.; Liu, Q.; Liu, P.Y.; Wang, W.H. Agents4PLC: Automating Closed-loop PLC Code Generation and Verification in Industrial Control Systems using LLM-based Agents. arXiv 2024, arXiv:2410.14209. [Google Scholar] [CrossRef]
- Fu, X.Y.; Laskar, M.T.R.; Chen, C.; TN, S.B. Are Large Language Models Reliable Judges? A Study on the Factuality Evaluation Capabilities of LLMs. arXiv 2023, arXiv:2311.00681. [Google Scholar] [CrossRef]
- Bran, A.M.; Cox, S.; Schilter, O.; Baldassari, C.; White, A.D.; Schwaller, P. Augmenting large language models with chemistry tools. Nat. Mach. Intell. 2024, 6, 525–535. [Google Scholar] [CrossRef]
- Ji, Y.L.; Shen, F.C.; Wu, J.; Xie, Q.J.; Zhang, Y. Linear Reasoning vs. Proof by Cases: Obstacles for Large Language Models in FOL Problem Solving. arXiv 2026, arXiv:2602.20973. [Google Scholar] [CrossRef]
- Lee, J.; Yoon, W.; Kim, S.; Kim, D.; Kim, S.; So, C.H.; Kang, J. BioBERT: A pre-trained biomedical language representation model for biomedical text mining. Bioinformatics 2020, 36, 1234–1240. [Google Scholar] [CrossRef]
- Domkundwar, I.; NS, M.; Bhola, I.; Kochhar, R. Safeguarding AI agents: Developing and analyzing safety architectures. arXiv 2024, arXiv:2409.03793. [Google Scholar]
- Lewis, P.; Perez, E.; Piktus, A.; Petroni, F.; Karpukhin, V.; Goyal, N.; Küttler, H.; Lewis, M.; Yih, W.; Rocktäschel, T.; et al. Retrieval-augmented generation for knowledge-intensive NLP tasks. Adv. Neural Inf. Process. Syst. 2020, 33, 9459–9474. [Google Scholar]
- Pan, J.; Liang, W.S.; Yidi, Y. RAGLog: Log anomaly detection using retrieval augmented generation. In Proceedings of the IEEE World Forum on Public Safety Technology (WFPST), Herndon, VA, USA, 14–15 May 2024. [Google Scholar]
- Zhu, P.; Chen, W.; Chen, D.; Liu, J.; Liu, Z.; Liu, Y.; Lin, G. An efficient query system for coal mine safety information based on retrieval-augmented language model. In Proceedings of the International Conference on Intelligent Computing 2024; Lecture Notes in Computer Science; Springer: Singapore, 2024; Volume 14876. [Google Scholar]
- Lee, Y. Developing a computer-based tutor utilizing generative AI and retrieval-augmented generation. Educ. Inf. Technol. 2024, 30, 7841–7862. [Google Scholar] [CrossRef]
- Posedaru, B.-S.; Pantelimon, F.V.; Dulgheru, M.N.; Georgescu, T.M. AI text processing using retrieval-augmented generation: Applications in business and education. In Proceedings of the International Conference on Business Excellence; Sciendo: Warsaw, Poland, 2024; Volume 18, pp. 209–222. [Google Scholar]
- Yu, W. Retrieval-augmented generation across heterogeneous knowledge. In Proceedings of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies: Student Research Workshop, Seattle, WA, USA, 10–15 July 2022; pp. 52–58. [Google Scholar]
- Siddiq, M.L.; Casey, B.; Santos, J. A lightweight framework for high-quality code generation. arXiv 2023, arXiv:2307.08220. [Google Scholar] [CrossRef]
- Zhuang, C.; Liu, J.; Xiong, H.; Ding, X.; Liu, S.; Weng, G. Connotation, architecture and trends of product digital twin. Comput. Integr. Manuf. Syst. 2017, 23, 753–768. [Google Scholar]
- Zhang, W.; Wang, G.; Yan, Y.; Chu, H.; Wang, J.; Cao, Z. Intelligent test of spacecraft based on digital twin and multiple agent systems. Comput. Integr. Manuf. Syst. 2021, 27, 16–33. [Google Scholar]
- Jørgensen, B.N.; Howard, D.A.; Clausen, C.S.B.; Ma, Z. Digital twins: Benefits, applications and development process. In Proceedings of the Portuguese Conference on Artificial Intelligence 2023; Lecture Notes in Computer Science; Springer: Cham, Switzerland, 2023; Volume 14116. [Google Scholar]
- Lu, J.; Zheng, Z.; Langtry, M.; Jackson, M.; Zhao, Y.; Feng, C.; Zhang, R.; Zhang, C.; Zhang, J.; Choudhary, R. Automated building energy modeling for energy retrofits using a large language model-based multi-agent framework. iScience 2025, 28, 113867. [Google Scholar] [CrossRef]
- Lu, J.; Tian, X.; Feng, C.; Zhang, C.; Zhao, Y.; Zhang, Y.; Wang, Z. Clustering compression-based computation-efficient calibration method for digital twin modeling of HVAC system. In Proceedings of the Building Simulation; Tsinghua University Press: Beijing, China, 2023; Volume 16, pp. 997–1012. [Google Scholar]
- Lu, J.; Tian, X.; Zhang, C.; Zhao, Y.; Zhang, J.; Zhang, W.; Feng, C.; He, J.; Wang, J.; He, F. Evaluation of large language models (LLMs) on the mastery of knowledge and skills in the heating, ventilation and air conditioning (HVAC) industry. Energy Built Environ. 2024, 6, 875–892. [Google Scholar] [CrossRef]
- Zhang, S.; Mu, H.; Liu, T. Improving accuracy and generalizability via multi-modal LLMs collaboration. In Proceedings of the International Joint Conference on Neural Networks, Yokohama, Japan, 30 June–5 July 2024. [Google Scholar]
- Tan, J.C.M.; Motani, M. LLMs as a system of multiple expert agents: An approach to solve the ARC challenge. In Proceedings of the IEEE Conference on Artificial Intelligence (CAI), Singapore, 25–27 June 2024. [Google Scholar]






















| Category | Example |
|---|---|
| Fundamental physics | The wet bulb temperature is usually lower than the dry bulb temperature. |
| Industry standards | To ensure indoor CO2 concentration is below 1000 ppm, each person requires 30 m3/h of fresh air. |
| Equipment control rules | The corresponding damper must be opened before turning on the VFD. The water valve must be opened before opening the damper. |
| Coding rule | For Rust code, use “//” to start single-line comments. Comments should be concise and clearly describe the function. |
| Demonstration cases | The room has {equipment list}; controllable parameters: {list}; control code: {code} |
| Data transmission formats | Fume hoods in room 1_XX transmit data in mm. Divide by 1000 to convert to meters. |
| Device lists | Room 1_XX has 2 fume hoods and 1 AHU. |
| Device parameters | Parameters in room 1_110: room1_110_air_conditioning_water_valve_opening; room1_110_AHU_supply_air_temperature; room1_110_return_air_temperature_sensor; … |
| Personalization Type | Impacts on Code |
|---|---|
| Type 1: Unequal number of laboratory equipment (61 rooms) | Code for calculating ventilation volume must be adjusted according to the amount of equipment |
| Type 2: Different models of fume hoods (65 rooms) | Data validation parameters must be modified according to the fume hood data transmission protocol |
| Type 3: Data naming inconsistencies (82 rooms) | Variable names must strictly follow the project description, even if a few variables deviate from other naming conventions |
| Method | Single Room (min) | All Rooms (min) |
|---|---|---|
| LLM-based method (this work) | 5 | 5 × X/N (parallel) |
| Manual coding | 15 | 15 × X |
| Template and parameter-based | — | 120 (fixed setup) |
| Model-Based Design (MBD) | 10 | 10 × X |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Jiang, R.; Xia, K.; Huang, J.; Lu, J. Large Language Model-Based Method for HVAC System Control Code Automatic Generation. Buildings 2026, 16, 1722. https://doi.org/10.3390/buildings16091722
Jiang R, Xia K, Huang J, Lu J. Large Language Model-Based Method for HVAC System Control Code Automatic Generation. Buildings. 2026; 16(9):1722. https://doi.org/10.3390/buildings16091722
Chicago/Turabian StyleJiang, Ruiqin, Ke Xia, Jiahua Huang, and Jie Lu. 2026. "Large Language Model-Based Method for HVAC System Control Code Automatic Generation" Buildings 16, no. 9: 1722. https://doi.org/10.3390/buildings16091722
APA StyleJiang, R., Xia, K., Huang, J., & Lu, J. (2026). Large Language Model-Based Method for HVAC System Control Code Automatic Generation. Buildings, 16(9), 1722. https://doi.org/10.3390/buildings16091722
