Cloud-Based Machine Learning Framework For Residential HVAC
Cloud-Based Machine Learning Framework For Residential HVAC
Abstract—Occupant behavior prediction has become a a quantitative thermal comfort criterion for a large group of
significant part of smart building technologies. This research people in a specific environment. A scale of PMV ranges
emphasizes on HVAC (Heating Ventilation and Air from -3 to 3 or from cold to hot respectively. According to
Conditioning) system as its operation is crucial in terms of both [5], thermal sensation collected using a questionnaire is used
energy usage and user comfort. In previous researches, comfort
prediction is developed using the filled questionnaires from
as an input of a neural network, where PMV is an output
signal used to regulate the operation of the compressor, fan,
2021 13th International Conference on Knowledge and Smart Technology (KST) | 978-1-7281-7602-4/21/$31.00 ©2021 IEEE | DOI: 10.1109/KST51265.2021.9415840
12
Authorized licensed use limited to: Carleton University. Downloaded on May 27,2021 at 13:20:55 UTC from IEEE Xplore. Restrictions apply.
source are stored inside Firestore database and finally used to C. Mobile Application
train ML algorithms to perform predictive control of the air A mobile application interface shown in Fig. 3. is
conditioner through IR emitter attached on the end device. developed for providing another remote air-conditioner
Behaviors of cloud services (depicted with the red arrow control. After a button is pressed, a corresponding command
in Fig. 1.) are governed by Cloud Functions which run is sent to the end device via RTDB.
backend commands in response to a triggered event. This The geolocation of a user is assumed to be the same as
research developed Cloud Functions with NodeJS runtime for his/her phone’s GNSS data. If the change in distance is more
Javascript. than 50 meters, current latitude and longitude will be reported
every 4 minutes interval to the Firestore database. Home
location can be selected as current geolocation or can be
selected on a map interface. This application is developed
with Flutter open-source mobile UI development framework.
A. End Device
Having an ESP32 module as the microcontroller, the end
device of which the schematic diagram is shown in Fig.2 can
communicate via WiFi and execute multiple tasks managed
by FreeRTOS (Real-time Operating System). Ambient Fig. 3. Mobile Application User Interface
temperature, CO2, and relative humidity (RH) captured by
SCD30 sensor are sent to ESP32 via I2C port periodically. A D. Firestore Database
940nm IR emitter carries commands to the A/C (Tested on
Mitsubishi MU-SGD18VC). The end device synchronizes its Firestore is a non-relational database that hierarchically
data with the Realtime Database (RTDB) via a REST API. stores data. User data are stored in a collection of which
documents inside are data from RTDB, geolocation from a
mobile device, and user settings such as home location.
Collected data from different documents are joined inside
a sub-collection of the database by Cloud Function every 5
minutes as shown in Fig. 4. Joined data are then indexed by
timestamp. The current location of the user and home location
is used to calculate a displacement by Haversine formula [8].
At the same time, current outdoor weather data of the location
set as ‘Home’ will be retrieved from an external data source
with its REST API.
B. Realtime Database
Realtime database (RTDB) is a non-relational database
which stores and synchronizes data which are structured as
JSON (JavaScript Object Notation) tree in realtime between Fig. 4. Data aggregation in database
cloud backend and the end device.
RTDB is used as a medium between backend services and
the end device. Data sent from RTDB to the end device are E. Machine Learning Framework
remote control parameters which can turn on/off, change First, ML models were pre-trained with a test user in a
temperature, or set fan speed. In the opposite direction, testbed environment. 2-month collected data indexed with a
ambient conditions collected by the sensor are transferred timestamp are injected to the data analysis platform
from the end device to RTDB. Upon RTDB update, ambient (Anaconda) to train prediction models (described in Section
condition data and A/C adjustment are also logged. III) on premise. Then models and their scalers are uploaded
13
Authorized licensed use limited to: Carleton University. Downloaded on May 27,2021 at 13:20:55 UTC from IEEE Xplore. Restrictions apply.
to the Cloud storage. Prediction engine APIs are provisioned Cyclic continuous features which are hour (h) and day (d)
independently in container environments with Cloud Run. are separated into 2 dimensional values [1] as:
While serving, Cloud Function is responsible for sending an
HTTP request with current data from Firestore database as a ℎ1, ℎ2 = ∙2 , ∙2 (1)
request body to each prediction engine API as shown in Fig.
4. These APIs are developed with Python Flask microweb 1, 2 = ∙2 , ∙2 (2)
framework.
Standardized to zero mean and variance of 1, input is used
to train ML algorithm. This research chose artificial neural
network (ANN) because of the ability to define a complex
non-linear relationship between input and output. The 5-Fold
cross validation (CV) is used to determine performance of 20
combinations of hyperparameters of ANN with an accuracy
(percent of correct prediction from all samples) as a metric.
Hyperparameter set in Table I is chosen with the highest
average accuracy of 96.5% over 5 folds.
Neurons in 5:5:5:2
Fig. 4. ML Framework layers
Activation ReLu:ReLu:Softmax:Softmax
Each engine performs its prediction by 1.) acquiring the
Optimizer Adam
prediction model and the data scaler from cloud storage. 2.)
applying data scaler to transform the incoming data to the
B. Thermal Comfort Prediction
training data distribution. Finally, predicting using scaled
The ASHRAE Standards, recognized standards for
data, then delivering output to the RTDB to perform
ventilation system design, stated that there are 6 factors that
predictive control of the A/C.
affect thermal comfort which are metabolic rate, clothing
As the system is developed with a test subject whose
insulation, air temperature, radiant temperature, airspeed and
behavior is unique among other users. Retrain Engine is
relative humidity, air temperature and relative humidity can
programmed to fit a new batch of incoming data to the
be directly collected by low-cost end device. Since metabolic
pretrained model and adjust parameters every 2 weeks to
rate is varied by the activities throughout the day, hour of day
ensure high performance in prediction.
and day of week can be used as factors to imply the routine
activities that affect the change in metabolic rate and clothing.
III. PREDICTION MODEL ANALYSIS Time and weather conditions can also reflect radiant
temperature from the sun. According to [10], outdoor
Prediction models are developed from data collected over
environment factors can alter human perception of thermal
a period of 2 months.
comfort. Thus, 4 classes of outlook (sunny, cloudy, rainy,
A. Occupancy Prediction thunderstorm) are also used as features. The level of CO2 can
Hour of day in 24 hours and day of week are used as a estimate occupancy.
time frame for prediction of the weekly routine whether the To sum up, air temperature, relative humidity, CO2, hour
user will be staying at home or not. Historical data is used to of day, day of week, outdoor temperature, outdoor feels-like
predict displacement in the future timestep. Displacement (S) temperature, and outlook are used as features of a learning
data in previous time steps which are 20 (t-4), 15 (t-3), and algorithm. The thermal discomfort data of the user which are
10 (t-2) minutes before the prediction target timestep is stored labeled as ‘Too Hot’ and ‘Too Cold’ is determined by the
in a sliding window [9]. Together with time data as shown in adjustment (increase/decrease) of the A/C temperature as
Fig. 5, historical displacement data is used to predict shown in algorithm I.
occupancy at the future timestep (t) which is 10 minutes after
the current timestep. Algorithm I
If A/C status == 1:
If setTemp(t) > setTemp (t-1):
Comfort = “Too Cold”
Elif setTemp(t) < setTemp (t-1):
Comfort = “Too Hot”
Else:
Comfort = “Neutral”
14
Authorized licensed use limited to: Carleton University. Downloaded on May 27,2021 at 13:20:55 UTC from IEEE Xplore. Restrictions apply.
in a state between 2 discomfort classes, this research utilized TABLE II. WEEKLY ACCURACY OF OCCUPANCY PREDICTION
probabilistic classification using support vector classification
(SVC) with sigmoid kernel on a 2-month dataset of the 5 mins 10 mins 15 mins 20 mins
discomfort. As the size of the dataset is only 277 records, Week 1 95.2% 94.5% 94.1% 92.8%
ANN is not suitable for solving the problem. Week 2 95.4% 94.1% 93.4% 88.6%
The model was trained with 75% of the dataset and tested Week 3 94.1% 92.5% 91.4% 90.3%
with the rest. The result in Fig. 6 shows a relationship Week 4 89.8% 89.1% 90.6% 88.7%
between probability from 0 (Too Cold) to 1 (Too Hot) and
the frequency of the labeled data in the test set. At the Assuming 10 minutes of precooling can ensure thermal
probability range 0-0.25, 90% of data is predicted as ‘Too comfort without consuming too much energy, 10 minute-
Cold’, while at probability range 0.75-1, 91% is predicted as session is used in the production model. To prevent the model
‘Too Hot’. from further accuracy dropping, the retraining process is
implemented every 2 weeks. Thus, the accuracy can be
maintained at over 95% all the time. Data from week1 and
week2 are used to fit the original model and weights are
adjusted. Accuracy using the adaptive model in week3
increased from 95.5% to 97% and 92.1% to 95% in week4.
The example of correct occupancy prediction is shown in
Fig. 8. Displacement at 21:50, 21:55 and 22:00, time, and day
of week at 22:10 is used to predict occupancy at the time
22:10 which is 10 minutes later than the time of the last
Fig. 6. Predicted probability of discomfort dataset known displacement. This prediction is correct as the real
distance turned zero (blue line), occupancy (red line)
Ordinal regression [11] is applied to the probability predicted beforehand is already turned to 1 which means
predicted by SVC as 0-0.25 to be ‘Too Cold’, 0.25-0.75 to be presence.
‘Neutral’ and 0.75-1.00 to be ‘Too Hot’. Since the purpose of
the model is to recognize the comfort zone of the user, a
metric used to define the performance of the classifier is a
recall (percentage of true positive from all true samples) of
prediction on ‘Neutral’ data.
Fig. 7. Predicted probability of ‘Neutral’ data. On the other hand, if the occupant’s arriving behavior is
out of routine, prediction result will be incorrect as shown in
Fig. 7 shows the prediction result as the data labeled as Fig. 9 where prediction result turned to 1 which is ‘presence’
‘Neutral’ is tested on a model. 84.5% of the total data lie 5 minutes before the occupant arrived.
under the probability range of 0.25-0.75.
15
Authorized licensed use limited to: Carleton University. Downloaded on May 27,2021 at 13:20:55 UTC from IEEE Xplore. Restrictions apply.
For the thermal comfort prediction model, the recall of [9] H. Hota, R. Handa, and A. Shrivas, "Time series data prediction using
sliding window based rbf neural network," International Journal of
comfort sensation (Neutral) on 4 weeks of data with and Computational Intelligence Research, vol. 13, no. 5, pp. 1145-1156,
without retraining on data from week1 and week2 is shown 2017.
in Table III. The maximum recall of a thermal comfort [10] C.-H. Huang, H.-H. Tsai, and H.-C. Chen, "Influence of Weather
prediction with this model is about 85% due to the difficulty Factors on Thermal Comfort in Subtropical Urban Environments,"
Sustainability, vol. 12, no. 5, p. 2001, 2020.
of defining metabolic rate and clothing by using the only time
[11] E. Satake, K. Majima, S. C. Aoki, and Y. Kamitani, "Sparse ordinal
to imply routine. Besides, airspeed is the factor that cannot be logistic regression and its application to brain decoding," Frontiers in
captured by the low-cost end device. Moreover, sometimes neuroinformatics, vol. 12, p. 51, 2018.
the occupant might remain too hot or too cold without
realizing the thermal discomfort condition.
V. CONCLUSION
In this article, a plug-and-play cloud-based ML
framework was developed in a cost-efficient system. A
combination of data collected by an end device and a mobile
phone can be used to create the models which explain the
occupancy and thermal comfort sensation of the occupant
with good performance without any additional cost from
hardware installation. Thanks to the adaptive learning
models, accuracy of occupancy prediction can be maintained
above 95% and the recall of thermal comfort prediction can
be maintained above 80% without human intervention.
This system is suitable for single room residence such as
a condominium since the platform was developed using only
one end device. Therefore, in future work, it is important to
develop a sensor network to collect and extract usage of the
A/C in residence with multiple rooms and multiple
occupants.
REFERENCES
16
Authorized licensed use limited to: Carleton University. Downloaded on May 27,2021 at 13:20:55 UTC from IEEE Xplore. Restrictions apply.