## 2 Methodology  
The objective of this document is to present a four-step methodology for the energy management of a smart microgrid based on the efficiency of dispatchable generation sources and storage systems. The prescribed sequence of actions required to attain these desired outcomes is outlined as follows:  
Step 1. Identification of elements. First of all, it is necessary to identify all the elements necessary to carry out the energy management of a smart microgrid:  
1. Metre of the energy distribution company: To monitor the energy consumption/injection of energy to the distribution network from the microgrid. 2. Renewable dispatchable generation sources: A smart microgrid can be made up of different sources of power generation, most commonly including photovoltaic and small wind energy, although they are not dispatchable from a resource point of view. However, there are other sources of renewable energy generation that can be managed, such as hydroelectric power, which will need to be monitored to issue operating commands (start-up and shut-down depending on the needs of the microgrid). 3. Distributed energy storage systems: The most commonly used in microgrids are batteries (lead-acid, lithium, etc. ), although many different storage systems can be used. The different storage systems that make up the microgrid must be monitored to provide them with charging and discharging commands. Step 2. Monitoring of elements. After identifying the various components, a crucial next step involves monitoring and integrating them into a comprehensive control software. This software serves as a communication conduit, enabling the elements within the microgrid to interact with one another effectively. Through this integrated control system, commands are issued to dispatchable generation sources and distributed energy storage systems, contingent upon the consumption of the microgrid from the distribution network. It is necessary to monitor the following parameters:  
1. Instantaneous power of the microgrid: This parameter serves as a vital indicator of the energy dynamics of the microgrid. When the value of this power parameter exceeds zero, it means that the microgrid is consuming energy from the distribution grid. Conversely, if the value falls below zero, it implies that the energy generated by the renewable generation sources integrated within the microgrid surpasses the energy demands of its loads. This negative value indicates a surplus of energy, resulting in the microgrid exporting energy back to the distribution network. 2. All parameters necessary to operate the dispatchable renewable generation sources: instantaneous power, start and stop commands, power setpoints, etc. 3. All parameters necessary to operate the stored energy systems: instantaneous power, on/off commands, charge and discharge commands, etc. In order to continuously track and analyse the aforementioned parameters and effectively establish a control system, implementation will rely on the utilisation of two open-source software programmes: NodeRed and Home Assistant [94; 95]. This strategic choice represents a noteworthy advantage associated with the proposed methodology. The incorporation of NodeRed and Home Assistant offers a comprehensive and robust framework for monitoring and controlling various parameters within the system. NodeRed, a free, open-source programming tool, provides a visual programming interface that enables the creation of flows for data processing and communication between different elements of the microgrid. The Modbus protocol is the most widely used protocol in the industry, and practically all equipment has it. If any element of the microgrid does not have it, other protocols such as MQTT, HTTP, etc. will be used. To communicate with a device using the Modbus communication protocol from NodeRed, it is necessary to configure a Modbus node for that device, defining the IP address, port number (default is 502), and the communication mode (Modbus TCP/IP or Modbus RTU).