Toward Sustainable Energy-Independent Buildings Using Internet of Things

: Buildings are one of the primary consumers of energy. In addition to the electricity grids, renewable energies can be used to supply the energy demand of buildings. Intelligent systems such as the Internet of Things (IoT) and wireless sensor technologies can also be applied to manage the energy consumption in buildings. Fortunately, integrating renewable energies with these intelligent systems enables creating nearly zero-energy buildings. In this paper, we present the results of our experimentation to demonstrate forming such a building and showing the beneﬁts for building users and the society. We create a system by integrating photovoltaic (PV) technology with an IoT-based control mechanism to supply and consume energy. We further illustrate “how the integration of IoT and PV technology can bring added value to the users?”. To this end, we evaluate the performance of our system against conventional ways of energy supply and consumption for a lighting use case in a dairy store. We also investigate the environmental and economic impacts of our system. In our implementation, for the IoT-based control system, we have used a set of sensors, a server, and a wireless network to control the energy consumption. We developed a web application for user interaction and software-based settings. To control the lighting system, we developed an algorithm that utilizes the ambient light, users’ movements inside the store and a historical dataset. The historical dataset was collected from the users’ behaviour as a training set for the algorithm for turning on and off the lights. We also designed an electricity management system that computes the energy generation by the PV panels, controls the energy supply, and imports and exports electricity to the grid. The results show that our system is an efﬁcient approach for creating energy-independent buildings by integrating renewable energies with IoT-based control systems. The results also show that our system not only responds to the internal demand by using domestic supply, but it also (i) offers economic beneﬁt by exporting extra renewable electricity to the grid, and (ii) prevents producing huge amounts of CO 2 . Our system is one of the ﬁrst works to achieve a nearly zero-energy building in the developing countries with low electricity accessibility.


Introduction
Buildings are the main sources of electricity consumption in different countries. In developed countries, the amount of electricity consumption in buildings is approximately 40% of the total electricity consumption per year [1]. Globally, the AC and lighting systems are the main sources of electricity consumption in buildings which consume nearly 40% and 20% of total electricity, respectively [2]. In response to the climate change, it is expected that the use of AC will increase by 10 times by 2050 [3]. Electricity consumption for lighting systems is also expected to increase by Furthermore, despite different studies performed in the fields of renewable energy systems and the Internet of things (IoT), most of them have a complex language that cannot convince the end-users to use these technologies in practice. Indeed, in a simple way, our research demonstrates how businesses and households can integrate the IoT with sustainable energy technologies to achieve multiple benefits. Particularly, our research is suitable for developing countries with low electricity accessibility, and the countries with solar radiation higher than average. As our methodology, we implemented and carried out an experimentation for three months by adding a PV panel to a building roof to generate solar energy. We designed an electricity management system that controls the electricity generation and consumption and receives electricity or sends the extra generated electricity to city the grid.
We also implemented an IoT system that controls the end user device electricity consumption, where in our case we control the lighting systems of a store. The IoT system is based on two light sensors to sense the ambient daylight, a server (as a database and control center), a Raspberry Pi which is used as the system gateway, a motion detector to track the movements, a Wi-Fi network, and a dataset collected from the users' habits. We also developed a web application to ease the user interaction with the system and offer software-based settings.
To enable the control system to operate, we designed an algorithm that senses the ambient daylight to control the electricity consumption while ensuring the visual comfort; and integrates the users' habit data on using the place while updating the users' presence through motion sensing. For the users' habit, we collected two months of historical data from the users' movement in April and May 2019, where we used this data as a training set in our algorithm for turning on and off the lights when there are no users in the place. During these two months, the user was allowed to turn on and off the lamp using the software user interface at his desired times. In June 2019, we tested the IoT system using the historical without user's input and we collected the data from the system performance.
As a result, we evaluate the performance of our system against a conventional way of energy supply and consumption. We also demonstrate the economic benefits of implementing PV panels for electricity generation in real life; and we highlight the impact on the environment by stopping CO 2 production. Our results show that using five PV panels with small sizes as 25 × 355 × 510 mm is not only sufficient to provide the electricity demand of a lighting use case, but the extra generated electricity can be exported to the grid which offers revenues for the user. In nutshell, our IoT system offers multiple benefits for businesses and households, and enables energy-independent and nearly zero energy buildings particularly in the regions with low electricity accessibility and the places where solar radiation is higher than average. This paper is organized in the following fashion. Section 2 presents the system model. Section 3 explains the control systems. Section 4 presents the results of our experiment. In Section 5, we provide a discussion and finally we conclude the paper in Section 6. Figure 1 describes the concept of solar-based energy generation and IoT-enabled intelligent controlled electricity consumption in a building. In this concept, sensors and switches of the appliances individually (lighting system in our study) are connected to a server through a wireless network. The connections can be any type of reliable short-range wireless technology or even an Ethernet cable. In addition, the data storage and the functions and electricity control mechanisms are performed on the server.

System Design
Our system consists of two parts: (i) photovoltaic solar panels, (ii) a laptop which is used as server, and (iii) IoT-based control system which includes a light sensor, a motion detector, i.e., Passive Infrared (PIR) sensor, two LED lights with the switches, a Raspberry Pi (RPi) (the central connection of different devices), and a network router which is connected to the Internet and offers wireless connection.

Photovoltaic Solar Panels
We used five photovoltaic panels of model "Zytech ZT20-18-P", with 25 × 355 × 510 mm dimensions generating an output power of 20 watt with 12VDC & 1.1A. These panels are used to transform the sunlight received at their panels to DC voltage and supply the electricity demand in the building.

IoT-Based System
We used a Raspberry Pi (RPi) Zero WH which holds built-in Ethernet and Wi-Fi network connections. RPi is used as the gateway of the system to connect the sensor and motion detector as well as the switches of the LEDs to the laptop which works as the server. We used a Yocto-Light-V3 that is a USB ambient light sensor and can simply be connected to the RPi board from the USB port. In addition, the switches of the LED lights were also connected to RPi using Ethernet cables. Indeed, to operate the system, we developed the required software for activating the light sensor, motion detector, and the switches using Python programming language and stored on a memory card and inserted in RPi. We provided the electricity using RPi's power supply. In the systems, all of the elements obtained a static IP address and we used the TCP/IP protocol to establish the communications. In the designed system, while the light sensors measure the ambient light, motion detector captures the movement and the switches obtain the status of the LED lights. Indeed, motion detectors not only are increasingly being deployed into smart environments, e.g., to control lighting and ventilation for energy management purposes, but also they have been used as a proxy for indoor air quality estimation [35]. In our design, we use one motion detector to control the lighting system based on the presence of the place users. In addition, to provide security for the system, we used security keys, encryption, and decryption modules using Python. Therefore, to provide security for the system, we used security keys, encryption, and decryption modules using Python.
Indeed, the measured status of the sensors is encrypted applying a unique security key that is defined by the system administrator, i.e., the user. The security key is stored on the server and also configured at the corresponding sensor device or switch. The security configuration is designed so that any measured data by the sensors requires two rounds of encryptions: (i) the security key encryption, and (ii) data encapsulation due to using TCP/IP protocol. Therefore, any transmitted data between the server and sensors or switches is encrypted and decrypted using its particular security key.
In nutshell, the sensors and the switches in the system use the scheme shown in Figure 2 to communicate. As illustrated, the sensors' communications are unidirectional and the data transmission happens at the sensors. Meanwhile, the communications of the switches are bi-directional, meaning that the switches can send and receive their status data to the server. If they receive data from the server, they are commanded to turn on or off the LED lights, which is due to avoiding electricity consumption and this then results in saving.

The Server
To run the IoT-based control system, we used a laptop as a local server with the specifications presented in Table 1. Using a local server instead of an Internet server was to prevent the building's control systems from failing when the Internet connection is down for any technical problem. Hence, having a local server in smart homes secures their continuous operations and ensures a reliable system. We developed a web application (Figures 3 and 4), which is stored on the laptop with a configuration presented in Table 1.

Web Application
In the back-end, to execute the control system, we used PHP programming and MySQL to develop a Web application consisting (i) Graphical User Interface (GUI) and (ii) Web API.
(i) The GUI which is designed to report the instant status of the building (in our case, the LED lights). The GUI is shown in Figure 3.
The GUI shows the electricity suppliers and consumers of the building and their respective status, updated at certain time intervals. The GUI has an administration section which is designed to allow the administrator of the system to modify the parameters and assign values ( Figure 4). The administration section allows for modifying the user's information, user's habit, and cost of electricity from the grid. The designed administration section consists of different tabs (options), each one with specific functions and editable fields. For example, selecting the sensor option or appliance option allows for modifying their IP address, security keys, locations, status, units of measurement, e.g., lux for lighting, and their status. The controller option allows for defining the rules and conditions for the system-for example, the administrator can define the level of lighting needed at the indoor environment. These options are enabled by the editable fields placed inside them. For instance, the status field in a sensor tab refers to the on and off mode of the device allows the administrator to remotely control (enable and disable) the device.  (ii) The Web API which works as a software gateway and connects to the sensors and switches. The Web API consists of a back-end program connected to the ports of the web server. The prototype of the control unit is illustrated in Figure 5. As depicted in this figure, the Web API receives all requests from the sensors and switches via the POST method of TCP/IP protocol. The requested and response data are also continuously stored in the database using the dedicated cryptographic algorithms. If the request comes from a switch, the kernel will be called and the data of related sensors and the previous status of the switch are also requested from the database. In addition, the new status of the switch will be determined and stored in the database. Then, the new status is sent to the relevant switch through the POST method. The Web API is designed so that, if there is no request from a switch for a long time or if a sensor shows an abnormal status, an alarm object, i.e., message will be sent to the administrator. Considering that the control unit uses the default setting specified by the administrator.

Electricity Production and Consumption Management
In this subsection, we explain the electricity management system for the lighting system. Because the electricity production with the panels, electricity consumption, and interaction with the grid requires a controlled plan, we planned a management system which is presented by a flowchart diagram in Figure 6. The logic of the electricity management system operates by reading the amounts of produced electricity by the solar panels (E P ) and the building electricity consumption (E C ) from their relevant sensors in real time. In the flowchart, RenSupp refers to the amount of generated electricity (E P ) by the solar panels and Demand presents the real-time amount of electricity consumption (E C ) in the building.
Next, the user habit (H) is called from the database which includes the time-stamped historical values of all sensors. Then, the user habit H and and Demand, i.e., E C , are inserted to a function called F(). In such a way, the amount of new demand is determined and replaced in the Demand variable, i.e., E C considering the historical data.
Next, the values of Demand (E C ) and RenSupp (E P ) are compared by a conditional statement. If Demand (E C ) is less than or equal to RenSupp (E P ), it means that total demand of the building should supply from the renewable resources. Then, the surplus amount of generated electricity by the solar panels can be sold to the Grid. We denote this by E ToGrid (shown by ToGrid in the flowchart). However, if RenSupp (E P ) is less than Demand (E C ), it means that generated electricity by the solar panels is not sufficient to meet the electricity demand of the building. Then, the remained amount of required electricity, i.e., GridSupp will be supplied by Grid (E G ). In addition, all of the processes and operations of the management system are stored in the database.
Our system is designed so that the function F() in the kernel of the web application can be defined in various ways. This flexibility of our system enables it to be a suitable mechanism for diverse settings in different buildings. In our study, we define the function F() as average of Demand (E C ) and the user habit H. By determining the status of connected devices to the energy suppliers, the process ends.
This process iterates periodically (e.g., each 30 s) and then the status of sensors is stored in the database per iteration.
To manage the electricity production with the panels, electricity consumption, and interaction with the grid, let us recall the following relations. Generally, the total amount of electricity consumption in a building can be defined as: where P i is the power of i th appliance, T i is the usage time of the i th appliance, and E N is the total amount of required electricity. In our study, we consider the grid electricity E G and the electricity generated by the solar panels E P to supply the building demand. We define the summation of these two sources as accessible energy E A : where E Demand is the energy that supplies the building demand and E ToGrid refers to the energy which will be sent to the Grid if there is any. Note that any electricity from renewable resources will not be sent to Grid, if the building demand Demand is greater than the electricity from generated electricity E P . Thus, using Equations (1) and (3), the energy management system will adjust the energy demand and consumption in the building.

Lighting Control System
In this subsection, we discuss the performance of our IoT enabled control system through implementation and experimentation in a dairy store (Figure 7) in the city of Tehran. This city is located in the middle east with an elevation of 1178 m from the sea level. Tehran has semi-arid climate [36] with continental characteristics and Mediterranean climate prediction patterns. The weather conditions of the place of the experiment has a direct effect on the operations and performance of our energy management system, whereas the length of sunshine (in hours) is one of the main factors of electricity generation by PV. The average monthly daylight and minimum sunshine hours in Tehran are represented in Table 2 [37]. The weather data shown in Table 2 illustrates that almost all of the months that have high average daylight also include a high average daily sunshine, whereas we carried out our experiments in April, May, and June which are among the months with highest average daily sunshine. Carrying out the experiment during these months with a high amount of sunshine enables the photovoltaic system to generate more electricity.

Impact on Electricity Consumption
To test the performance of the control system, we used the lighting system as the use case. Hence, we applied an illumination sensor and a power controller switch for the lighting system. Then, we added five photovoltaic panels to the roof of the building as power supplier.
We carried out the experiment by installing IoT-enabled devices in a dairy store in the center of Tehran. The picture and plan of the store are shown in Figure 7. As illustrated in this figure, we installed two LED lighting bulbs almost at the center of the store with a difference of 3 m in between them. We also installed an illumination sensor at 20 cm distance from the window of the store. We also installed a motion detector on the ceiling of the store to track the movements of people every 30 s. As shown by the square shape on the plan of the store, the motion detector was placed between the two LEDs.
We connected both of the LED lighting systems, the illumination sensor and the motion detector to the IoT control system that controls the LEDs by turning them on and off. Then, we collected the data from the light sensor and status of the LEDs (if they are on or off) from the first of April to the end of June 2019. Our controlling system stored the total of 262,080 data points on the database during these months. We further stored the data in a MySQL database developed on the local server. In April and May 2019, our IoT-based control system only collected the data from sensors and the status of LEDs and stored them while allowing the user to modify the status of these LEDS during these two months. In this way, we collected the user habit data (H) as explained in Figure 6.
The IoT-based control system works by the illuminance received at the sensor and implementing the Algorithm 1 on the RPi. To derive the Algorithm, we derive the parameters from our experiment and the service that is planned to be offered by the IoT-based control system. To derive the algorithm, we use inputs from the light sensor, real-time movement tracked by the motion detector, and collected historical data while aiming to offer an IoT-based service which is turning on and off the lights. In addition, the Algorithm considers the visual comfort levels defined for such an environment, i.e., dairy store which are assumed between 50 and 70 lux [38], and turns on and off the lighting bulbs using the illuminance received at the sensor.
In the Algorithm, lx refers to the measured illumination (in lux); lb1 and lb2 denote to lighting bulbs LED1 and LED2 (as depicted in Figure 7). lbx stat refers to the status of the LEDs; and lbx pred denotes the prediction of LEDs status (i.e., On = 1, Off = 0). The Algorithm uses the dataset stored on RPi. The dataset was collected from the user habit H for April and May 2019. Figure 8 shows sample plots from the ambient light variations measured by the light sensor. Figure 8a illustrates the continuous measurement of light during June 2019 and Figure 8b shows one day of measurements on 1st June 2019. These results state that the light sensor has been operating constantly during the measurement time. The light sensor inside the store was not influenced by direct sunlight. This would be due to the fact the buildings in front of the store have prevented the solar irradiation from entering the store. Indeed, receiving direct solar irradiation (or by being at high temperatures) at the sensor would drift the sensor's measurement and degrade it leading to measurements performance and would require implementing calibration techniques [39]. From the measurements, it can be seen that the sensor has measured the ambient daylight received inside the store continuously. The measurements have correctly varied with the decrease and increase of daylight. This is obvious from measurements as shown in Figure 8. The maximum measured light intensity is at most 120 lx for all days. It is also obvious that the ambient daylight gradually increases from morning until the most lighter time (i.e., noon between 12:00 p.m. and 2:00 p.m.) (Figure 8b). The fluctuations that we observe in this figure, for example between 9:00 a.m. to 10:00 a.m., present possible cloudy times, or vehicles passing in the street or stopping in front of the building which limits the amount of ambient light to enter the store. In a nutshell, from the measurements, we can conclude that the sensor has been working properly and accurately without any failure.
To decide about the status of the next minutes of the LEDs, if they should switch on or off, the Algorithm checks the status of the LEDs for the equal days, hours, and minutes (i.e., [HH:MM]) of the past two months to check if the LED was on or off. Next, using the collected data for April and May, the average status of both LEDs (which can be 1 or 0) is calculated. The average status is then multiplied with the status of the motion detector, which can be 1 or 0. The results of these status are then assigned to the prediction status lbx pred . This step is defined to influence the H in the energy management strategy. Indeed, the dairy store is not open always and all day long. This is due to several reasons for example closing the store in lunch times or early closings. Using the lbx pred , the Algorithm decides if received ambient illumination is (i) less than 50lx. Then, the Algorithm considers to turn on both of the LEDs or only one of them; (ii) more than 50lx and less than 70lx to turn on only LED1 or none; (iii) more than 70lx to turn off both of the LEDs.

Performance of the IoT-Based Control System
To evaluate the impact of using IoT-based energy control system on the electricity consumption, we compare the conventional way of using the LEDs (i.e., Lightings 1 and 2) with the IoT-based control mechanism as presented in Algorithm 1. The results are shown in Figure 9. The conventional way refers to the habit of user about using the LEDs which was collected through (UserHabit) as explained in Figure 6-while, in the controlled approach, the amount of light generated by the LEDs depends on ambient light variations measured by the light sensor.  To demonstrate the performance of the IoT-enabled system on reducing the power requirements, first we compare the results of one day of conventional way with the controlled approach. Hence, we use the H data of 31 May 2019 and compare it with 1 June 2019, while we filter and plot the data from 08:00 a.m. until 8:00 p.m. (Figure 9a). We also illustrate the monthly power requirement of both approached by using the (UserHabit) data for the months May and June 2019 (Figure 9b). Figure 9a depicts the hourly electricity consumption of the two approached in a varying ambient lighting for each hour (W/h). It can be seen that, in a conventional way, the electricity consumption remains almost constant regardless of light variations. This is while, for the IoT-based approach, the electricity consumption drastically decreases with the increase of the received ambient lighting. This result explains that the IoT-based approach is highly dynamic and depends on ambient light fluctuation in the store. The highest values of ambient light were received between 1:00 p.m. and 7:00 p.m., and almost no energy was consumed within this time interval.
In addition, Figure 9b shows the monthly electricity consumption by both approaches, while the data filtered from 08:00 a.m. until 8:00 p.m. The demand (yellow bar-chart) which is the summation of the consumption of the LED1 and LED2, in contrast with the conventional approach demonstrates a significant monthly reduction, with almost more than 50%. To conclude, the results shown with these comparisons prove using such an IoT-based control system significantly reduces the electricity consumption and avoids wasting the energy by stopping unnecessary consumption.

Renewable Energy Production and Consumption
The solar panels which are installed at the roof of the building generate 100 Wh. To compute the monthly generation, we use the information from the Table 2 and solar panel specification and apply them in the following relation: The monthly energy generation for the year 2019 with the panels are shown in Figure 10 with a blue bar-chart. Comparing these results with the "Demand" shown with a yellow bar-chart in Figure 9b that is equal to 13.64 (Kw) explains that installing such a green energy generator is not only sufficient for supporting the need of energy requirements of the LED light bulbs used in the dairy store, but there is also extra generation that can be consumed for powering other electric devices or can be sold to the electricity grid. The monthly extra generated energy is also illustrated with light green bar-charts in Figure 10.

Environmental and Economic Assessment
To assess the economic and environmental aspects of applying the solar panels together with the IoT-based energy control system, we investigate the CO 2 emission reduction caused using this technology as well as the energy costs.

CO 2 Emission Reduction
The grid electricity is mostly supplied from the fossil fuels which causes CO 2 emissions [40]. The level of CO 2 emissions also depends on the type of utilized fossil fuels. The CO 2 emissions by buildings largely contributes to global warming and adds to the air pollution in urban areas [41]. In order to determine the amount of CO 2 emission per kilowatt (Emission) for the grid electricity, we multiply the coefficient (α) to the control unit, such that: where E Conventional is the conventional way of electricity consumption which is based on user habit and E Demand denotes to the electricity demand of IoT-based system. The coefficient (α) refers to CO 2 emissions from the fossil fuels. According to U.S. electricity generation, α is equal to 0.96 kg for conventional combined cycle gas turbine plant [42].
Employing the IoT-based control system together with the solar panels contributes to reducing a significant amount of CO 2 generation. Indeed, using the data collected from the LEDs in June 2019, and using the information from the Table 2 for the whole year 2019 and applying Equation (5) resulted in an inconsiderable amount of CO 2 emission reduction. These results are presented in Table 3.

. Cost Evaluation
Implementing such a system offers two different economic benefits (B) for the user. First, it enables saving costs (C s ) because of the demand management of the system. Second, it provides revenue (Rev) that the owner can get by selling the extra supplied electricity to the grid. Using Net Presenting Value (NPV) of the project can help to understand better the economic-effectiveness of the system. The following formula is used to calculate NPV: where R t = Netcashin f low − out f lows during a single period; and i is the discount rate or return that could be earned in alternative investment; and t refers to the number of timer periods. The initial cost for this project at t = 0 is 110 USD. Therefore, the total revenue is the sum of saving costs and revenue by exporting the extra electricity to the grid (74 USD per year). According to Iran's renewable energy policy plan, the FiT (feed-in tariffs) for generated solar electricity by residential sector is 0.079 (USD/Kwh).
where P is the electricity price and E s is the saved electricity which calculated by (E Conventional − E Demand ). We also consider 0.079 (USD/Kwh) of consumption. For FiT, we also use 0.079 (USD/Kwh) based on the price in May 2020. E ToGrid is the electricity which is sent to the grid and computed by using Equation (4).
Using the data collected in June 2019 from the LEDs and applying the relations above, FiT and the energy price, we observe that our system besides supplying the energy demand of the store offers economic benefits as presented in Table 3. Assuming that the user continues with the same electricity consumption habit for the whole year and assuming the same amount of energy demand; in addition to gaining some revenues, the user saves a considerable amount of money in a year (Table 3).
On the other hand, the yearly operation and maintenance cost is estimated 10 USD. Hence, with assuming 20% discount rate and for 10 years' time period, the net presenting value of the project after three years is 25 USD. As NPV > 0, this means that the investment would add value to the owner after three years.

Discussion
The stochastic nature of renewable energy generation resources plays an important role to accurately analyze the results [43]. Indeed, it is mandatory to consider the stochastic nature when planning and operating the renewable energy system. In the planning phase, the stochastic nature of the renewable resource is important to mitigate negative impacts and improve the performance of the system. However, in the operation phase, considering the stochastic nature of renewable energy sources allows us to accurately analyze the performance of the system [44]. For example, when planning a solar system, it is important to place the solar panels in the places which receive direct sunlight and other disturbances such as shadows from buildings and trees are avoided. In addition, the solar panels are protected from heavy rain or snow that may cause failures in operations. In analysis of the operations of the renewable energy system, the ground truth (i.e., reference) data, collected from accurate weather stations can be used to investigate the performance of the system.
In our case, the stochastic nature of renewable energy generation resource (i.e., sunlight) has a direct influence on solar-based electricity generation. In our study, we carried out a continuous experiment in April, May, and June which are among the sunniest months in Tehran. This city is also located in the middle east with a stable sunny and weather situation. Due to these facts, the electricity generation process continued and did not fluctuate to raise a problem during the experiment time. However, to take into account this concern, we have designed an electricity management system for the building which connects to the city electricity grid to receive and send electricity. The designed electricity management system allows for switching from the solar-base power source to the city grid when there is an electricity shortage or when there is a failure in the solar system. Moreover, to control the lighting system, we have designed an IoT system that measures the ambient light to turn on and off the lights. Our planned IoT system uses three threshold levels of less than 50 lux, between 50 and 70 lux, and more than 70 lux to turn on and off the lights [38]. It is worth recalling that these values were selected to ensure visual comfort for the users. Indeed, the ambient light sometimes is affected by unexpected external sources which may cause errors in light sensor's measurements. For example, a car stopping in front of the store and reflecting the sunlight into the store would result in increasing the light intensity inside the store and exceeding the threshold light levels and therefore turning off the light inadvertently. Therefore, implementing appropriate strategies and intelligent methods to avoid such errors and anomalies is needed.
The anomaly detection methods allow identifying errors in the measurements of sensors in an IoT system. In literature, there are a variety of anomaly detection approaches such as machine learning methods which are used to identify specific failure modes when the received data falls outside of the learnt data model [45]. In an IoT system, applying anomaly detection methods not only enables detecting and correcting errors that improves the sensing performance; but it also provides fault detection and finding malfunctioning sensors which leads to easy maintenance of the system. Moreover, using anomaly detection methods improves security and privacy concerns by detecting for example the denial-of-service attacks and by preserving users data.

Conclusions
In this study, we aimed to investigate how the integration of IoT and PV technology can bring added value to the users. Hence, we created a system by integrating PV technology with an IoT system to generate and consume electricity for a lighting use case. We investigated the performance of the system against a conventional way of energy supply and consumption. We also evaluated the environmental and economic impacts of using solar-based electricity generation for such a use case.
We implemented an IoT-based control system which uses the ambient light and combines users' presence with users' historical movement data to control the energy, while five pieces of solar panels were used to generate and supply energy. The control system was used to turn on and off the lights of a dairy store by sensing the ambient daylight received at the store as well as the users' movements inside the place. We also designed an electricity management system that controls the energy generation and supply, and imports and exports electricity to the grid.
The results of our study demonstrated the feasibility of electricity generation from solar systems at smaller sizes and enabling nearly zero-energy buildings. The results of our experiment showed that the use of five PV panels with small sizes as 25 × 355 × 510 mm is not only sufficient to provide the electricity demand of the lighting use case, but the extra generated electricity can be exported to the grid which provides economic benefits for the owners. We also demonstrated the environmental impact of implementing such a system which stops producing huge amounts of CO 2 . Moreover, our approach motivates the businesses and households in the developing countries with low electricity accessibility, and the countries with solar radiation higher than average and with a high dependency on fossil energies to apply such intelligent systems to supply and consume energy for buildings.
As future work, we plan to create a fully intelligent system by learning the users' habits of using the spaces and defining a full control mechanism for devices and appliances in the space such as fridges and HAVC. Hence, we plan to study the feasibility and employment of solar panels at bigger scales to achieve a fully energy independent and a nearly zero-energy building which we envision to be the future of buildings.