Method of control of at least one electrical microgrid comprising the following steps: a) acquisition of data from at least one generation sensor associated to each electrical energy generation element installed in the microgrid; b) acquisition of data from at least one consumption sensor associated to each electrical energy consumption element installed in the microgrid; c) simulation in computational means of at least one simulated element of electrical network, through the modelling of said simulated element, being each simulated element represented by a computational agent, each simulated element consisting of an equipment not installed in the microgrid but whose behaviour is simulated; d) representation in computational means of each electrical energy generation element installed in the microgrid and each electrical energy consumption element installed in the microgrid by a computational agent, through the data acquired from said at least one generation sensor and said at least one consumption sensor associated to each of them; e) having as input the computational agent representations from steps c) and d), maximization in computational means of an objective function which consists on the sum of the following components: i) the power from all the external elements of energy supply; ii) the power of all the generation components, which includes all the energy generation elements and simulated generation elements; iii) the power from all the consumption components, which includes all the energy consumption elements and simulated consumption elements; iv) the power from all the means for energy storage; f) actuation on the available resources, scheduling them, according to the result obtained in step e). a) acquisition of data from at least one generation sensor associated to each electrical energy generation element installed in the microgrid; b) acquisition of data from at least one consumption sensor associated to each electrical energy consumption element installed in the microgrid; c) simulation in computational means of at least one simulated element of electrical network, through the modelling of said simulated element, being each simulated element represented by a computational agent, each simulated element consisting of an equipment not installed in the microgrid but whose behaviour is simulated; d) representation in computational means of each electrical energy generation element installed in the microgrid and each electrical energy consumption element installed in the microgrid by a computational agent, through the data acquired from said at least one generation sensor and said at least one consumption sensor associated to each of them; e) having as input the computational agent representations from steps c) and d), maximization in computational means of an objective function which consists on the sum of the following components: i) the power from all the external elements of energy supply; ii) the power of all the generation components, which includes all the energy generation elements and simulated generation elements; iii) the power from all the consumption components, which includes all the energy consumption elements and simulated consumption elements; iv) the power from all the means for energy storage; i) the power from all the external elements of energy supply; ii) the power of all the generation components, which includes all the energy generation elements and simulated generation elements; iii) the power from all the consumption components, which includes all the energy consumption elements and simulated consumption elements; iv) the power from all the means for energy storage; f) actuation on the available resources, scheduling them, according to the result obtained in step e).