Internet of Things based on Situation-Awareness for Energy Efficiency

Reducing spending on electricity consumption has become a challenge for residential users as well as industries due to rate hikes in electric bills in recent years. Residential users often do not know which equipment consumes more energy or how much each appliance uses energy and this makes managing energy consumption difficult. And it is in this sense that the present work presents the creation of an smart outlet that captures data about the consumption of equipment, the smart outlet is manipulated by a web system, in addition to monitoring the energy consumption it is possible to place limit values on the system sends a notification and it is possible to disconnect some equipment.


Introduction
Reducing the spending on electricity is one of the main challenges for the economy in different sectors and it is essential for the development of smart and sustainable cities.In October 2017, according to Aneel (2017) Brazilian National Electric Energy Agency approved an increase of 42.8% in the extra fee for the electric energy bill.This decision is due to the low levels of the reservoirs, which are in lower levels than those registered in the year 2001.
The theme of Smart Cities and Sustainable Communities is one of the 17 major goals of the United Nations (UN) sustainable development agenda for the horizon of 2030.One definition that is widely used in the approach is: "To use information and communication technologies (ICT) to provide an improved quality of life for its citizens at an affordable cost and optimize the use of the planet's resource" (Caragliu, del Bo and Nijkamp, 2011).
According to Rosa (2013) advances in intelligent environments are increasingly related to the creation of sustainable environments, where the applications contained besides providing automatization, comfort and mobility through systems, seek to reduce the negative effects generated to the environment.
Context-sensitive techniques are used in intelligent environments and provide the creation of applications able to capture information from the user's environment and exploiting them on the user behalf.For example, applications that know the user profile and identify that every day at seven o'clock in the morning the user wakes up may switch the water heating from a low consumption mode to one that allows the availability of heated water for morning use.After that the consumption may be reduced to a maintenance level greatly reducing the overall energy consumption.Regarding residential consumers, one of the major problems associated with electric power consumption is the lack of knowledge about the consumption of each appliance at a certain period of the day, of the week, or of the month.One solution is to provide explicit information on the appliances consumption and the total detailed energy spending of the residence.This information becomes an essential knowledge allowing the user to manage costs and the use of energy.The economic advantage may be a strong motivation for the user change of consumption behavior.
According to (Darby, 2006) actually, people have a vague idea of how much they are consuming in their home.If this lack of information did not exist, it would be possible to change the behavior of the user on a day-to-day basis, as well as to invest in energy efficiency measures, since consumption becomes visible, facilitating an understanding of expenditure control.
The present work presents details of the software and hardware created in Schiefelbein et al. (2018).The hardware uses the concept of Internet of Things, where devices are connected on the internet, enabling data reading and sending to the cloud beyond the possibility of intervening in the environment.
The hardware developed is a smart power outlet that reads the data of the electrical energy consumption of the apparatuses of a residence.The software developed is a pervasive application that allows the management of energy consumption, in the application it is possible to visualize the consumption of the connected devices the smart socket and it is also possible to set limit values that people in the house would like to pay, this way alerts are sent to notify them.
The paper is structures as follows: in Section 2, the essential concepts are presented.In Section 3 a study on the work related to the consumption monitoring based in context is presented.Section 4 presents the developed solution.Section 5 presents the case study, as well as the application of the system prototype in a case study, and finally, Section 6 presents the final considerations.

Conceptual Reference
This section will address the main concepts that serve as a basis for understanding the work.

Internet of Things
According to Razzaque et al.( 2016) the definition of the Internet of Things (IoT) includes a variety of physical elements, including phones, tablets and digital cameras, and also includes elements of our environment such as houses, cars and others.Based on this each element is connected to the internet providing information and even services.The Internet of Things enables an electronic incorporation of physical objects, making them intelligent, so at the single component level, IoT is based on the notion of "intelligent objects" ( Miorandi et al. 2012).For Sundmaeker et al. (2010) by the year 2020, there will be 50 to 100 billion devices connected to the internet.
The Internet of Things brings together a set of different technologies for its specific vision, such as sensors, hardware, firmwares, data modeling, cloud storage, processing, communication technologies, and others (Perera et al. 2014).The internet of things enables an electronic incorporation of physical objects, making them intelligent.
According to Aarts and Wichert (2009) the Internet of Things shares many aspects of intelligent environments, which enables inclusion in sensing systems embedded in the environment, IoT helps to expand the concepts of intelligent environments and create ever larger scenarios where new services are accommodated in time execution" (Miorandi et al. 2012).

Ambient Intelligence
According to Aarts and Wichert (2009) Ambient Intelligence (AmI) can be defined as electronic environments that are adaptable and context sensitive.The environment should respond to the actions of people and objects to meet their needs.To support this demand, the AmI promote the use of sensors and actuators to respond to people's needs.To offer such behavior the system must model the profile of each device to adapt themselves to the actions of the users (Schreurs et al. 2005).With these environments, it is possible to install applications sensitive to its users and to the context to anticipate needs and behaviors (Sandri 2011).
According to Weiser (1991) computation is increasingly present in human life, the term pervasive computing result from the analysis of a set of scenarios that describe the environments.Pervasive computing try to become invisible, being non-invasive to the user's daily life, but supplying its technological needs.In the perspective of pervasive computing, the computer has the ability to obtain information from the environment in which it is inserted and use it dynamically.For Lyytinen and Yoo (2002) the focus of the applications is centered on the user and their activities, providing access to the environment information (context) from various devices at any time Following these characteristics, in this work, a pervasive application is considered an application that informs the user of a situation of interest, which uses the context in which it is inserted to make the decisions.

Context-Awareness
According to Ye, Dobson, and McKeever (2012) context-awareness is one of the main research areas within Intelligent Environments, as it gives to systems the characteristics of being flexible, adaptable and able to act on behalf of the user.The context describes properties of a user environment, such as location, time, person characteristics, and resources, among others.
For Salber, Dey and Abowd (1999) the context may be defined as any information to be used to characterize the situation of an entity.An entity in turn is a person, place or object that is considered relevant for the characterization of the context state.Thus, a context-sensitive system can use the context to provide information relevant or services to the user, where relevance depends on the task in which the user is involved, the task itself being a context element (Machado et al. 2017).Therefore, from the moment that context-sensitive pervasive applications model the profile of users, their characteristics and the information of their context, they can interact in a useful way to the user.
Applications can automatically adapt to user changes and needs (be context sensitive).However, for applications to be able to infer about the environment and, consequently, to identify the situation in which the user is inserted, it is necessary to perform the context modeling, seeking to identify existing physical or abstract objects and that will influence the generation of information for applications (Machado et al. 2016).This action of the applications can be considered closed loop or open loop feedback.In the first case, the applications act directly on controlled ones adapting the situation to a correct state, in the second the applications offer information and alerts so that the user can act on the environment.In this paper, we deal with the case of open feedback loop.

Context Modeling and Context of Interest
According to Machado et al. (2014) context modeling is an important element in the construction of intelligent systems, the degree of refinement and expressiveness of the model determines the perception of the environment by the application.Generating models for this kind of environment helps to abstract some parts and improves the understanding.Therefore, modeling the context to identify the existing entities in the environment is a fundamental task for the development of context-aware systems.
To correctly model the context, Machado et al. (2017) explain that it is necessary to identify important elements that are part of the context, so that it is possible to group data from these elements and generate useful information of a high level, so that the events that are occurring in the environment can be detected.Attributing these characteristics to the context allows identifying a subset of elements of the context of interest.Systems for AmI are not able to process all the context information of a realtime environment, so it becomes necessary to identify the entities that are of interest in a given context.These features are called context of interest.The same importance exists for the semantic relations between the entities to bring more meaning to the monitored context (Machado et al. 2017).
The context of interest of an application is composed by instances of contextualized entities and their respective semantic relations.In a home environment, a context of interest can have as entity the electrical equipment, rooms of the house, people, among others (Machado et al. 2017) Within a context of interest there is a situation of interest, from the identification of the situation of interest that the application will have the defined objective.

Situation of Interest
Systems sensitive to the environment for intelligent environments should not focus on individual sensor data, but on interpreting context information at a high conceptual level.Situations are defined as abstraction states of the context of interest of applications, determined their beginning and end by specific events (Machado et al. 2017).
An event is an occurrence within a particular system or domain that has already happened or will happen, such as "opened the door" or "turned on the fan" (Etzion and Niblett, 2010).Events can be simple or complex.Simple events are produced by some context entity, such as sensors.Complex events are high-level in the semantic hierarchy and usually correspond to a pattern (correlation between simple events) (Machado et al. 2017).Complex events often require the incorporation of domain-specific knowledge in addition to correlating possible predefined patterns or attributes (Lyytinen and Yoo 2002).
For the definition of a situation of interest, it is necessary for the developer to generate a set of instances of events (processed data about a set of entities) that are of interest to the user and to specify how these events happen, as well as how they influence in the situation of interest.The current situation model is represented by def. (2).
Sa: (name, Ie, Fe) (2) Current situation (Sa) is characterized by a name and two events that show its, Initial event (Ie) and Final event (Fe), the time attribute of these events characterizes the valid time window for this situation, the time window represents a time finite where events are monitored and corresponds to a pattern of interest.The events characterizing the situations of interest have a representation, presented in def.(3).
Name is a brief description of the event, Type specifies whether the event is of the external type, because it happens due to some action of the user or the internal type Event: (name, type, {R}, pattern) (3) where it happens due to some action of the system, R defines the rules of inference that will determine that the event happened and pattern determines the correlation between events.The concepts presented in the earlier sections are fundamental for the execution of the middleware used in this work.

Situation as a Service (SIaaS) middleware
The middleware is used to characterize a layer made up of generic services, located below user applications, it hides the differences in computer architectures, operating systems, programming languages and network technologies to facilitate the development and management of applications (Delicato et. al, 2004).For Machado et al. (2014) it acts as a connection between sensor data, or devices that are in the physical environment and the applications, and these characteristics were implemented in the Situation as a Service middleware (SIaaS).
The SIaaS middleware supports the heterogeneity of devices used to detect situations of interest, allowing through layer 1 defined in the middleware, applications can be incorporated and managed.As presented in Figure 1, the SIaaS middleware includes the Upper Level (1) and Intermediate (2), where communication with the Lower Level occurs (3): (1) Upper Level: It is intended for pervasive applications; (2) Intermediate Level: the SIaaS middleware provides a stable environment for different pervasive applications to request actions.It manages the physical resources (available at the Lower Level) of the environment to identify undesirable situations that are of interest to pervasive applications, and at the Higher Level, for pervasive applications, these pervasive applications are of the most varied domains; (3) Lower Level: Referring to the physical environment in which the architecture is inserted.At this level, there are usually sensors and devices responsible for collecting data from the environment and inferring about it in some way.
For different application domains to be correctly integrated with the middleware, it is necessary for the developer of this application to follow the development methodology (Machado et al. 2017).

Methodology to Create Pervasive Applications
The methodology for the development of pervasive applications Machado et al. (2017) follows four phases for development.It begins with the need to develop a product that manipulates a given situation using the conceptual model, to start the process in the following phases: (i) Definition of the Situation of Interest: Define what will be the situation that the system must follow, since the situation of interest is the information that initiates the decision-making; (ii) Definition of Action Plan (Decision-making workflow): Define which actions should be initiated by the system in relation to the situation of interest.It will be described which features the devices of an intelligent environment can provide for the required pervasive application.Therefore, each current Situation has a reactive action plan linked, as well as each predictive situation is associated to a proactive action plan; (iii) Definition of Context of Interest: After identifying the Situation of Interest and what services are required to generate an action plan, the developer must generate instances of context entities that correspond to steps (i) and (ii).This subset of instances is the application context of interest that will be provided by the middleware whenever the situation of interest is detected.Therefore, it uses this information to understand the current context of the environment and select which actions to take.Therefore, the context of interest is the set of important information that drives the decision-making process (action plan); (iv) Identification of non-Functional Requirements of the Application: Identify the non-functional requirements for implementing the application itself, such as programming language and hardware issues.In Figure 2, the representation of the steps to be followed for the development of pervasive applications is presented.

Change in Behavior Through Feedback Intelligence
Feedback describes information about an event or action in the past that can influence the performance of the same event/action in the present or future.In the case of electric power consumption, the feedback provides users with energy use.This feedback helps to change users' energy consumption behavior (Ehrhardt-martinez and Donnelly, 2010).
According to Darby (2006) measurement in mensal kWh consumption value is mostly ignored by the users, as this data offers only a vague idea of how much energy the domestic appliances consume.Based on this finding, we studied the close feedback on energy consumption to make information about electric energy consumption more frequent and understandable.This action helps the consumption control via the behavioral change, considering that the feedback on the consumption of energy contributes to the construction of knowledge about the use of energy.
Presenting feedback on energy consumption is one way of persuading the user to change behavior.And there are countless ways to persuade the user to change behavior using persuasive techniques (Fogg 2003).

Feedback Characteristics
According to Ehrhardt-martinez and Donnelly (2010) there are several types of feedback and several aspects that should be taken into account when the goal is energy efficiency.
The main types of feedback are: Direct Feedback: Composed of information of energy consumption that are provided in real or near real time.Smart meters, web pages showing actual consumption, among others, can be cited as examples of this category.Direct feedback frequently can save 5 to 15%; Indirect Feedback: Requires an information processing before being presented to the user.It is suitable for demonstrating long-term effects.Examples include: conventional light accounts, e-mail, consumption reports via mail, web pages that present information by means of comparative graphs, among others.The energy savings using this feedback category frequently has a range from 4 to 8%.A comparative study by Darby (2001) was presented that analyzed 38 researches over 25 years, focused on demonstrating how the types of feedback can lead to a reduction in energy consumption.Table 1 shows the number of researches and the reduction in average consumption.From the analysis by Darby (2001) it may be concluded that direct feedback, alone or with a combination of other factors, is the most promising type of feedback, resulting in savings of 5%, and in cases of higher economy 20%.In addition to the types of feedbacks, the characteristics of presentation are: technology, content, mode, frequency/duration and mode of presentation to the user (Hermsen et al. 2016).
(i) Technology: There are many forms of feedback delivery, like SMS, e-mail, web and mobile applications to smart home application monitors.The ability to deliver information well-structured and often over a period of time is a strong point of digital and interactive technology, but just as the digital technology present in the feedback provides speed and persuasion it can be easily erased or forgotten (Hermsen et al. 2016); (ii) Content: Adapting the content according to each of the users who will receive the feedback, the use negative feedback (e.g.deceptive messages), positive (e.g.motivational messages) or neutral may affect the feedback effectiveness (Lam et al. .2011).Another method that presented good results was the use of comparisons and visualization of graphs containing historical expenditure as feedback (Jain, Taylor, and Peschiera, 2012); (iii) Modality: Feedback delivery mode, visual, auditory, tactile, or combination of them can draw more attention in certain applications.The visual mode can draw more attention than the auditory mode, since it usually contains more details of the feedback, but the auditory mode can produce better results than the tactile mode (Hermsen et al 2016); (iv) Frequency and Duration: The more frequently feedback is delivered and over a longer period of may lead to change in the behavior (Hermsen et al. 2016).The feedback will achieve better results to the point that its frequency does not overwhelm users' cognitive resources (Lam et al. 2011); (v) Presentation Mode: Aspects of design and usability determine the attitude of the user to the application.An intervention that has a clear design that helps emphasize the important information will bring better results (Hermsen et al. 2016).

Related Work
In this section some works related to the research theme are presented.The analyzed works monitor energy consumption in some way and present consumption in some form of feedback that will be explored.
In the work of Houde ( 2013), a study was carried out to obtain an estimate of the impact of the use of direct feedback, or the real-time feedback, the experiment lasted about eight months.The feedback technology tested was a monitoring device that records electricity consumption and a web application that displayed near real-time consumption information (information was updated every ten minutes), daily and annual consumption, and data that enabled the comparison of consumption.
The families who participated volunteered.For the study the families were divided into two groups, one that would receive real-time feedback early in the study and one that would only receive feedback after 3 months.The data was provided to households through a web interface developed by Google and named the Google Powermeter.The results showed that the greatest reductions in electricity consumption due to the visualization of the feedback occur during the morning and night peak periods: between 5h and 10h, electricity consumption decreases by 12.2% on average and from 20h to 23h, electricity consumption decreased by 8.2% on average.Currently some products developed by Google Nest are marketed, which provide an in-house automation fence and enables temperature management for example.
In the work of Nandi, Mungurwadi and Mannur (2018) is presented a web system that shows the instant consumption of electrical equipment.Real-time information helps remotely monitor and understand consumption within the household, so it is possible to manage consumption through changes in behavior.The authors made a prototype to measure the consumption, they used some sensors among them the SCT-013.Regarding design elements, it was possible to identify in the article that only the data collected instantly were presented on the screen.
In the work of Chagas et. al (2010) was used residential automation and context sensitivity for the management of electric energy.The authors explain that context sensitivity associates independence of human action to the task of managing the availability of the environment to the rational use of electric energy, opening, activating, deactivating and closing the environments according to the immediate needs of the users (context).
The tests happened in a laboratory in a university, the system identifies if it is possible to reduce the consumption for example when there is nobody in the laboratories and notifies the interested ones to take actions related to that situation.In the end the results indicated that there was 20% in the consumption of energy in laboratories.
In the work of Hartman et al. (2018) has developed a system that includes a smart device application.Raspberry Pi was used for the preliminary tests.The authors explain that these intelligent IoT devices allow the energy usage data of each of each unit to be collected and stored in a cloud-based database that can be analyzed and reported for energy conservation and analysis.
Data can be viewed in the application according to day, week or month consumption.In addition, the data can be viewed by means of graphs.The tests of the project of Hartman et al. (2018) happened in two offices, where they were monitored air conditioners and lighting units, the results presents, a significant reduction.
A table that presents some important information of each related work was done, as can be observed in Table 2.The observed criteria were, what kind of feedback was used in the system, if context sensitivity was used, which sensors used besides the form presentation of the information.
In addition, it was presented the characteristics that the present study uses in the developed system that will be presented in the next sections.
As can be seen in Table 2 the use of feedback type can be used both together, direct and indirect feedback.Because the real-time data will usually reach the user who is looking at the system at that particular moment and the indirect feedback where the data is processed before it appears to the user will reach a user who is searching for that information.But if used alone both are efficient as well.
The use of context sensitivity in systems that seek energy savings can make systems increasingly intelligent and in this way the system can act alone, this area is beginning to be explored gradually.
The use of sensors that are easily found and have a not very expensive price has been much used for manufacturing of prototypes and even large-scale hardware.As some sensors are non-invasive this facilitates handling and reduces the risk of accidents.
According to Fischer Fischer (2008) the historical comparison is a fundamental component for systems that present feedback on energy consumption and seek to reduce its consumption.

Real-time data and Graphic
Regarding the visualization of the information, to present the data in real time it is necessary that the user is looking at the software at that moment, as already mentioned in this work, and the processed data transformed into information can be analyzed more calmly at the time that the user prefer.

Architecture Supported by IoT for Energy Efficiency
In this section will be presented the system and the hardware developed in the work.Sections 4.1 through 4.5 will describe the aspects of hardware developed, and section 4.6 will describe the part of the software developed.

Hardware Architecture
For the creation of the hardware, a simple architecture was defined, as can be observed in Figure 3, composed of two layers, being: (i) the bottom layer of sensors / actuators / peripherals, which will collect current and voltage (ii) the top layer, where the firmware is located, which will be responsible for the hardware routines, such as collecting sensor data or executing commands.The developed hardware is equipped with two sensors (one responsible for collecting the electrical voltage on the device, and another responsible for collecting the electric current consumption of the device), an ethernet module (this one to provide / receive data / commands on the Internet through a link), a load relay (responsible for acting as a switch, cutting or making available the power supply to the device that is connected to it), and a control unit where the firmware is recorded.

Driver and Application Manager Module
For this work a module where it is able to install and manage applications and drivers in the middleware SIaaS was implemented, being this module belonging to the application layer and called SGAD (Application Management System and Drivers).In Figure 4 the module interface is presented.From this module it is possible for the user to acquire applications and install them at runtime on the same layer.With this module it is also possible to install drivers in the runtime so that the middleware acquires in its middle layer the knowledge about the sensors present in the layer of the physical environment, so that the middleware can manage the data between the application layer and physical environment.
Dynamic loading of artifacts, drivers, and applications occurs through a standard interface, where the module loads artifact bytecodes into memory, making them part of the system and enabling its use by the user or middleware as soon as they are installed.Drivers and applications are installed from files with .jarextensions.
The main steps of the driver loading are, after writing the file to disk, inserting the .jarfile into the Classpath, loading its bytecodes into memory and using Reflection to invoke the existing methods in the classes of the file being installed.The use of Java Reflection follows an interface pattern so that interaction between middleware, applications and drivers is possible.

Communication Between Middleware and Physical Layer
In order for the middleware to collect data from the physical environment, it must have knowledge of the sensors, but for this to happen it requires drivers to perform this communication, where these drivers will communicate with the sensor's firmware, allowing the exchange of information.
Driver is a program responsible for making the communication between a specific system and a hardware type, so that the system accesses the hardware, the driver must be part of the system, so it must know everything about the hardware and have a defined architecture and how it can be installed in the system knowing the interface of the same, and having a well-defined model of what the driver does and how it interacts with the hardware and the rest of the system (Tanenbaum, 2009).
The drivers are usually positioned below the rest of the system.Following this idea the general architecture for the system is presented in Figure 5, where for the system, intermediate layer, to communicate with the physical layer, it needs a driver.From the installed driver, the middleware contains all the knowledge about how to behave with the hardware that is present on the physical layer.Communication between the layers occurs as follows; for example, after installing an application and a driver for a temperature sensor, the application will ask the middleware for data about the temperature of the physical environment, the middleware in turn requests the data to the driver responsible for the temperature sensor, where it asks the hardware firmware, where it will collect the information and return to the driver, which will return to middleware and finally deliver the requested data to the requesting application, the communication is done using REST (Representational State Transfer).

Smart Power Outlet developed
In the creation of the Smart Power Outlet prototype, the Atmega328p micro controller Atmel (1995) was employed to control the circuit of the intelligent socket.Electrical current data collection was performed using the sensor SCT 013-20A, a non-invasive current sensor.To measure the voltage, a voltage sensor was developed, where four diodes, a capacitor and a variable resistor were used.The variable resistor performs the micro adjustment of the voltage sensor; the voltage signal of the secondary output of the circuit transformer is rectified so that the microcontroller has an external voltage reference signal.Power control (on/off) is done by a load relay, as soon as equipment is switched on and off, dates and time information will also be collected.All collected data is sent to a local server via an Ethernet connector attached to the board and associated to the microcontroller.
The circuit that encloses the smart-board is shown in Figure 6.In ( 1  The data collected from the intelligent socket are the voltage and current consumed by the electrical equipment, the power, and the date and time of each collection performed, approximately every 7 seconds, and the data related to equipment is stored in the database through the local server.For the explanation of the calculation of the expense value a graph is generated from the energy consumed in relation to the time of given equipment, from the data collected.It is important to remember that the calculation will indicate an approximate value of consumption.The calculation is shown in Figure 7. Always from two points, where we have the power one (P1), power two (P2), and the time interval between these two points (a).
By making the necessary conversions (W to kW and seconds to hour) the data are applied in the simple trapezoid formula, where the largest base of the formula is P1 and the smallest base is P2, making the sum of the two powers, multiplying the sum generated by the time interval (a) between the two points P1 and P2, and soon after divided by two; from this result the value of the kWh consumed in that time interval is obtained.
In order to know how much total kWh was consumed by the equipment, the total area under the curve is calculated.Since the kWh consumed by the device, it is enough to multiply by the tariff that the local power utility charges, for the calculations of the prototype was used the value of R$ 0,537391 as value of kWh consumed.The next section presents a case study, used in the evaluation of the work, related to the system proposed in this study.

Hardware Viability
From the hardware developed, some tests were done to make it viable.For this, we performed the scheme presented in Figure 8, where we used a voltmeter to measure and compare the voltage measured by the hardware, two ammeters to compare with the current sensor present in the developed hardware, and a single-phase meter to compare the final load measured for validation purposes.For load, as at the moment the hardware only measures apparent power, lamp frames were used, as they can simulate different levels of resistive load.The first validation occurred in the insertion of different levels of power, this first test was given to observe the behaviour and possible failures.First, a load of 600 Watts was inserted, just after 900 Watts and finally 1020 Watts, during the test, no differences were demonstrated.Figure 9 shows the loads throughout the test.In order to validate the kWh of the hardware developed, a non-digital singlephase meter was used in parallel, but at different loads, as shown previously in Figure 9. Initially the single-phase meter had its registered value reset, and soon after, loads of 1020 watts of power were inserted in both devices, in the single-phase meter and in the developed hardware.
When the loads were applied, the kWh validation test was started, where the 1020 watts was waited for the moment when the single-phase meter registered 1 kWh.The test started at 15 hours and 51 minutes, after approximately 55 minutes, the singlephase meter registered 1 kWh, with this the test closed at 16 hours and 46 minutes, and the result obtained in the hardware was quite satisfactory, recording 1.0403017 kWh.

Pervasive Application developed
The developed application is fed with aggregated (high level) data from the context provided by the middleware, which in turn receives the raw data from the context generated by a smart socket, also developed in this work.When the user installs the application, he defines what is the unwanted situation and the context of interest (smart socket) and if the application should act on the situation or if the application sends the information for the user take a decision.
An example of an undesired high-level situation reported by the user could be "I would not like the value spent on electric energy in the month to big higher than 100 dollars and I want to be notified to act on the situation should it occur" or "I do not want that the value spent on the consumption of air conditioning to go higher than 50 dollars", allowing the application to inform the user about the occurrence of the situation of interest.From the identification of these situations, the application acts or alerts the user, presenting feedback on these expenses and then the user can take some decision about the situation, such as turning off the air conditioning or other electrical equipment through the application.Following the methodology, each phase was characterized as follows: Situation of Interest: In this application, a current situation was considered as a situation of interest of the pervasive application of electric energy, this work does not address predictive situations.Therefore, a current and interesting situation is detected when a value or a percentage over a certain value stipulated by the user is exceeded.This situation is produced after the SIaaS middleware realizes that the values of the light bill have gone from the predicted, resulting in a current situation.The current situation, as already described, is characterized with name, initial event (Ie) and Final event (Fe).In the definition 4 the event (Ie), which initializes the situation called "electricity bill passed from the desired value", is represented, and the final event (Fe) of this situation: Events are composed of semantic relations and these are composed of context entities, they are modeled so that they can be changed according to the domain of the application.The events ev1 (Table 3) and ev2 (Table 4) were modeled as shown.The monitoring of expenses related to the consumption of electric energy is presented through a web application developed in Java, Figure 10, where it is possible to follow the value spent in the month, until a certain date (red square in the image).Action Plan: The undesired situation is detected with the start of event 1 (ev1), where the limit value of the equipment consumption has exceeded the stipulated value, the application then issues an alert (Alert1) for the user to choose one of the actions previously defined.In addition, the application is waiting for the user to choose (Action1, Action2 and Action3), after which the user will be aware that the value has already exceeded the value he would like to pay, this characterizes the final event (ev2) "User Aware of the value of electricity bill".In Figure 11 this situation is represented in a BPM (Business Process Model).In the application developed, the screen where the value established by the user is exceeded and the screen of decision making, where he can disconnect some equipment are presented in Figures 12 and 13.

Application's Context of Interest:
In the application, the context of interest is formed by instances of entities, following the statement presented in Section 2.4.The context of interest of the application has a user that has its location known by the system and the house has equipment connected to the intelligent socket, this socket intelligent device allows the devices to be turned on and off remotely and provides the collection of the consumption data of the device to which it is connected.The context of interest of the application is represented in the def. 5.

Non-Functional Application Requirements:
In this version of the system, the raw data pertaining to the reading of the electricity consumption is captured by the intelligent socket and transmitted to a local server, where the middleware is installed.From the raw data present in the middleware database, the calculations to know the value consumed are carried out in real time.The information presentation is through direct feedback and graphs that show consumption in a time line.

Case Study -Use of the pervasive application for energy control
The scenario for the evaluation of the proposed architecture and the pervasive application consists of a fictitious scenario where a family of four people lives in the house.John, the owner of the residence, spends every month on a problem, which is the high consumption of electricity.
To try to get around this problem, he decides to make his home a smart environment.He buys a middleware called SIaaS with a module called SGAD (Application and Management System) and an application for control and management of electrical energy called appPervGEE (Pervasive Power Management Application), and it also acquires smart power outlets that will replace conventional household electrical outlets.
The Smart Power Outlet will provide data on the consumption of equipment connected to it, where appPervGEE will use this data to turn into useful information, as well as detect faults in the electrical network, warn users and / or cut off the power supply to a device for example, overloading the network.
The appPervGEE aims to monitor and help John make decisions about the consumption of individual electrical equipment in his residence, the application makes the monitoring of the electrical appliances of the residence that are connected to the smart sockets, and with this, generate graphs where the owner of the residence can make decisions about the use of the equipment besides knowing the current electric energy expenditure of the month on each device properly connected.The middleware's goal is to manage the data provided from the smart power outlets in the environment and manage the data for the appPervGEE.The purpose of the SGAD module is to enable the user to install and manage the applications and drivers required for smart power outlets to function properly.
In this scenario it is considered that all the electrical outlets of the residence have been changed and that all electrical devices (Air-conditioning, refrigerator, television, hair dryer and others) are connected to them.The Smart Power Outlet generate data for the middleware that will generate events that may be of interest to installed applications, for example a device connected to the smart power outlet generating an overhead in the electrical network, the middleware will identify and generate an event that can be assumed by some application that controls that problem.According to these definitions the following scenario was considered for the developed approach: John is a middle-class citizen, married and has two daughters, one of his biggest concerns is in relation to the electric bill at the end of each month.John and his wife spend most of the day in their jobs, and their daughters as they study in the morning, spend the rest of the day at home, so they do not have a spend-time control of electricity in the month.To solve this problem he decides to make his house a smart environment, with this John starts to carry out research in the market and finds a solution to his problem regarding the consumption of electric energy, as in the future he intends to put other intelligent functionalities in his residence he opts by installing a middleware, and a module to install the applications.
After installing the middleware in the residence, John acquires intelligent electrical outlets to replace the current electrical outlets of the house, these outlets collect the consumption of the devices that are connected to it and send them through the internet, but another fact that John chose the outlets is the one of them besides realizing the collected one of electric energy consumption also serve like a breaker, cutting off the electricity if it identifies a high current, with this John will be more calm with his daughters alone at home, because in case of any problem of short or about the appliance will cut off the power and generate an event for the middleware that later another application will recognize this event and warn John of the event, thus avoiding a possible fire or possible electric shock to one of his daughters.
The acquired smart power outlet accompany beyond the driver for proper operation with the middleware, one AppPervGEE system that can be installed on middleware from SGAD module, acquired by John, from this system he can monitor the expenditure of each present electrical appliance in the residence, stipulate an overall limit spend for the month, manage which appliances should be in operation by cutting or providing power from the smart electrical outlet through the system, in addition to having a past expense history.
After everything is up and running, John starts using the AppPervGEE system installed in his middleware.Initially to manage electric energy expenses John stipulates a maximum amount of R$ 100 to spend in the month and asks for the application to notify you when this amount is reached.After a few days, the application consuming data from smart electrical outlets through the middleware, John can already see the electrical energy expenditures of his appliances, and he realizes that the air conditioning in the bedroom of one of the daughters stays connected for many hours without necessity, the From this observation it configures in the application to activate the air conditioning from the smart outlet only at certain times of the day, causing unnecessary expenses of electric power to occur.
Missing a few days to close the month, the application notifies John that the estimated spend for the month of R$ 100 has been reached, and with this the application asks if he wants to ignore the warning or if he prefers to go for an action plan, as John cannot afford to spend more in the month then opts for the stock plan where all the electrical appliances of the residence are managed, he visualizes some graphs of consumption of the appliances and decides to deactivate appliances that are only for family comfort, such as air -conditioning of the bedrooms and the dishwasher, with this, John manages to reach the end of the month with an electric energy expenditure well below the previous ones.
Figure 14 shows the system screen showing the monetary values that are being spent in the residence of John.In this it is possible to visualize the total to be paid in the month until the day besides showing a chart of consumption and the total that each device spent until this day of the month, with this John can see beyond the consumption of other appliances that the air conditioning of his room has spent the equivalent of R$ 13,31.In Figure 15, the screen with the actions predefined by John, in this screen the alert has already been issued, then this means that the user is already aware of the situation that he is in, and he can then perform the actions that he had predefined.
The user can instantly monitor the consumption of the individual equipment and the entire residence, so that they can have control over their electricity bill.As a result of the evaluation of the presented case study, John can easily have the complete perception of the expenses generated by the electrical equipment of his residence at the moment he wishes.It is possible to obtain in real time the energy consumption of the same and, in addition, to manage the electric energy expenses of your residence having at the end of each month a great result of saving in the electric bill.From the analysis of the scenario was observed that with the feedback that the system provided the user managed to have control over their spending, because it can monitor the consumption in real time.Real-time tracking provides management over spending on energy consumption.

Conclusion
The work presented concepts related to pervasive computing, a methodology for creating pervasive applications was directly addressed.From this methodology a system for electric energy management was developed, the data presented in the application were collected from a hardware that was also developed, called smart socket.
Although the case study was described in the form of a scenario, the data collected is real, as well as the equipment connected in the intelligent socket developed.In the application was implemented only in the reactive mode, ie a certain situation of interest had to happen for the alerts to be activated, this way users are warned and can make the decisions.
For future work will be implemented the proactive form of the application, that is, the user can make decisions before consumption reaches the limit value that he himself was.The next tests will happen in more residences, in this way it will be possible to have a greater precision and it will be possible to make comparisons between the consumption.Some safety measures will also be inserted that aim to bring more reliability to the project as a whole.

Figure
Figure 3. Hardware Architecture

Figure 4 .
Figure 4. SGAD module screen for application and driver management.

Figure 5 .
Figure 5. Communication architecture between applications, middleware system and hardware through the driver.
) part of the circuit diagram representing the power supply; (2) represents part of the circuit for operation of the current sensor; (3) the diagram representing the sensor created for the voltage collection and in (4) the microcontroller is represented.

Figure 6 .
Figure 6.Scheme of the smart power outlet prototype

Figure 7 .
Figure 7. Graph of the power over time of an equipment.

Figure 8 .
Figure 8. Connections made for hardware viability.

Figure 11 .
Figure 11.Action Plan of the application.

Figure 12 .
Figure 12.Warning screen where the limit value is exceeded.

Figure 15 .
Figure 15.Screen for decision making.
. Each pervasive application has a Context of Interest (C), which represents a group of valid semantic relations at a specific time.The context of interest for a pervasive application is represented in def. 1.