## 3 Results
### Simulation of New Routines
\begin{table}
\begin{tabular}{p{56.9 pt} p{56.9 pt} p{56.9 pt} p{56.9 pt} p{56.9 pt}} \hline \hline
**Endpoint** & **Method** & **Path Parameters** & **Query Parameters** & **Body Parameters** & **Description** \\ \hline / & GET & & & Display the API documentation using Swagger UI. \\ \hline /consumption & GET & Date and time & & Returns a list of energy consumption values of all appliances at the given date and time. \\ /consumption & GET & Appliance identifier, date, and time & Returns the energy consumption value of the given appliance at the given date and time. \\ /consumption & GET & & List of dates and times & Returns the list of total energy consumption of all appliances at the given dates and times. \\ /consumption & GET & Date and time & Returns the total energy consumption of all appliances at the given date and time. \\ \hline /appliance & GET & & Returns the list of all appliances. \\ /appliance & GET & Appliance identifier & Returns a specific appliance. \\ \hline /routine & GET & & Returns the list of all routines \\ /routine & GET & Routine identifier & Returns a specific routine \\ \hline /simulate & POST & & Routine to simulate & Simulates the addition of a routine and returns a list of recommendations and errors (if any). \\ /simulate /consumption & POST & Date and time & Routine to simulate & and returns a list of energy consumption values of all appliances at the given date and time. \\ /simulate /consumption & POST & Appliance identifier, date, and time & Returns the energy consumption value of the given appliance at the given date and time. \\ /simulate /consumption & POST & Date and time & Routine to simulate & and returns the list of total energy consumption of all appliances at the given date and time. \\ /simulate /consumption & POST & List of dates and times & Routine to simulate & and returns the total energy consumption of all appliances at the given dates and times. \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Endpoints of the Digital Twin’s REST API. throughout the day. Therefore, the _State Matrix_ has been designed. Each row of the matrix represents one specific minute of the day, while each column refers to a household appliance. Each cell contains a unique identifier corresponding to the operation mode in which the appliance is configured for that particular minute. Before adding a new routine, the system checks if any conflict will arise by comparing the current State Matrix with a hypothetical one, in which the routine has already been saved. Specifically, two types of conflicts are taken into account:  
1. _An appliance has conflicting operation modes in the same time interval_. This conflict emerges when two routines want to use the same appliance simultaneously but with two different modes. Such a scenario happens when a cell in the original matrix, holding an operation mode other than \"stand-by\", is replaced by a distinct value in the new matrix. Figure 5 shows an example in which this type of conflict occurs and is correctly identified;
2. _The power consumption of the appliances in a time interval exceed a maximum limit_. In this case, the user asks their smart devices to use a quantity of energy that is above the maximum load capacity of the house (commonly set to 3 kW for domestic use in Italian households; the Italian case is representative of those countries that share an issue with constrained energy availability). Such a case is identified by computing the sum of the consumption values for each row of the matrix and comparing it with the maximum allowed value. In addition to identifying conflicts, the developed API can also guide users in optimizing their routines by providing them with recommendations. Two families of recommendations can be produced:  
1. _Change routine's start time._ The system can suggest to users a better start time for their routines, according to the energy cost of running them at different times during the day.