## 2 Methodology
Additional parameters such as connection timeout and update frequency also need to be adjusted [94]. Once the communication is established, it is necessary to configure input and output nodes (for reading values or sending commands, respectively). This requires determining the device's identification number (Unit-ID), the Modbus register address, the number of addresses occupied by the register, and the register type (input, holding, etc.) [94]. Finally, after reading the value from the corresponding Modbus address (which is a value between 0 and 65,536), it needs to be interpreted using a JavaScript function programmed to obtain the actual value of the variable being measured, based on the information collected in the Modbus frame regarding the scaling factor and data type (integer: int, unsigned integer: uint, floating point: float, etc.) [94]. Additionally, Home Assistant, another free open-source platform based on the Internet of Things architecture, serves as a pivotal component for automation and control purposes. It offers a user-friendly interface and supports the integration of a wide array of smart devices and protocols. By leveraging Home Assistant's extensive capabilities, the proposed methodology enables the development of a sophisticated control system that can effectively regulate the parameters under scrutiny. Home Assistant receives information about the different parameters from NodeRed and allows the creation of automations based on events, schedules, or any other conditions by programming in YAML or using the visual automation editor. The Home Assistant control panel enables the creation of customised views by configuring cards and panels to display real-time information, such as device status, graphs of measured variables, etc. The adoption of these open-source programmes demonstrates the methodology's commitment to accessibility and affordability. Leveraging NodeRed and Home Assistant ensures flexibility and adaptability and allows for further customizations and enhancements based on specific needs. Figure 1 shows the flow of data and commands between Home Assistant, NodeRed, and the elements of the microgrid. NodeRed communicates with all the elements of the microgrid to collect all the necessary data and sends them to Home Assistant, which works as a human-machine interface and allows their visualisation in real time (1 data per second). The operation commands are activated from Home Assistant and sent to the different elements of the microgrid through NodeRed. Step 3. Characterise the efficiency of the elements of the microgrid. Once all the elements of the microgrid have been identified and monitored, it is necessary to characterise them in order to subsequently classify them according to their efficiency. To characterise dispatchable generation sources, it is necessary to run them at different powers and see the resource consumption associated with them. In order to characterise storage elements, their efficiency has to be calculated in terms of the energy they consume or supply in charging and discharging processes (according to Equation (1)) at different instantaneous powers. \[\text{Performance:}\;\eta=\text{P}_{\text{out}}/\text{P}_{\text{in}}\times 100\% \tag{1}\]  
where:  
\(\eta\): is the performance. \(\text{P}_{\text{out}}\): is the output power (injected by the element under consideration into the microgrid). \(\text{P}_{\text{in}}\): is the input power (consumed from the microgrid by the element under consideration). Step 4. Microgrid energy management. Energy management in a microgrid encompasses many aspects, and it is always difficult to single out one over another. In this methodology, the main objective is to optimise the performance of the microgrid by prioritising the commissioning of dispatchable generation sources and the charging and discharging of storage systems according to their efficiency, reducing the energy consumption of the distribution grid and eliminating power peaks.