System for distributing electrical energy over a cluster of electrical devices, the cluster comprising at least one smart grid participating electrical device and at least one smart grid non-participating electrical device, the smart grid participating electrical device having flexibility with respect to the execution of a task assigned to it and being connected to an electrical grid through a smart grid by a smart grid agent, the smart grid agent being configured to determine the amount of electrical energy in function of time to be delivered to and from the electrical grid for the smart grid participating electrical device of the cluster based on information of the smart grid participating electrical device and the smart grid, the system further comprising a meter for measuring the amount of electrical energy actually delivered to and from the electrical grid for the cluster, characterized by a controller comprising software components for determining the difference between the amount of energy determined by the smart grid agent to be delivered to and from the cluster over a predetermined period of time and the amount of energy measured by the meter actually delivered to and from the cluster over the predetermined period of time, the controller being provided as a computer or a server connected to the smart grid and receiving signals representing the amount of energy determined by the smart grid agent to be delivered to and from the cluster over a predetermined period of time and signals representing the amount of energy measured by the meter actually delivered to the cluster over the predetermined period of time for determining the difference between them, detection of usage of electrical energy by the at least one non-participating device being done by the determining of the difference between the amount of energy determined by the smart grid agent to be delivered to and from the cluster over the predetermined period of time and the amount of energy measured by the meter actually delivered to and from the cluster over the predetermined period of time, the controller comprising software components for simulating a virtual smart grid participating electrical device based on the determined difference and for providing the smart grid agent with information based on the determined difference such that the smart grid agent is configured to determine the amount of electrical energy in function of time to be delivered to and from the electrical grid for both the smart grid participating electrical device and the non-participating electrical device of the cluster based on information of both the smart grid participating electrical device and the non-participating electrical device of the cluster and the smart grid and such that the difference between the amount of energy determined by the smart grid agent to be delivered to and from the cluster over the predetermined period of time and the amount of energy measured by the meter actually delivered to and from the cluster over the predetermined period of time is reduced, wherein the controller is s adapted to simulate the virtual smart grid participating device with a PI or PID controller; the controller being a PID controller adapted to implement a calculation algorithm having three separate parameters: a proportional, an integral and a derivative parameter, denoted P, I, and D, respectively, P depending on a present error, I depending on an accumulation of past errors, and D being a prediction of future errors, based on current rate of change, wherein PID controller calculation algorithm is given by: u t = P ⋅ e t + I ⋅ ∫ 0 t e τ d τ + D ⋅ d dt e t wherein u(t) is the output of the PID controller, the parameters P, I and D represent respectively proportional gain, integral gain and derivative gain, t represents the elapsed time since the beginning represented by 0 and e(t) represents the error being the difference between the amount of energy determined by the smart grid agent to be delivered to and from the cluster over the predetermined period of time and the amount of energy measured by the meter actually delivered to and from the cluster over the predetermined period of time.