## 3 Procedure for the Conversion of a Network Section into a Smart Microgrid
type: tcp # protocol type  host: 192.168.15.75 # IP address # communication port
* Modbus RTU: this is a master/slave architecture for linking a control system to a Remote Terminal Unit (RTU) via a serial port. Commonly, the master is an HMI or a SCADA system that sends a request and the slave is a sensor or PLC that returns a response. A CRC (Cyclic Redundancy Checksum) is used as an error-checking mechanism and as a procedure to ensure data reliability. A name must be assigned to the element, the type defined, and method of communication, the communication port, baudrate, stopbits, bytesize and parity, all given, as follows:
- Modbus RTU over TCP: it is a combination of Modbus TCP and Modbus RTU. It is based on client/server architecture for communications over Ethernet as Modbus TCP/IP but uses a CRC as Modbus RTU. The same issue as in TCP/IP must be defined. - name: SmallWindTurbine1 type: rtuovertcp
host: 192.168.15.87 port: 7128
* platform: command_line name: \"Pump1\" command: \"curl -s 'http://admin:[EMAIL_ADDRESS]/io.cgi?\" (accessed on 1 January 2021) | awk '/'relays/{print substr($2, 1, 1)}\" scan_interval: 1  
Despite that there are other many communication protocols, most of the elements that can be connected to a microgrid use one of those described above.  
Once all elements are defined, the registers with the required information must be read from the addresses of each one. This procedure is also carried out in the configuration file of Home Assistant.  
In Modbus protocol, it is necessary to have the Modbus frame (it should be in the manufacturer's manual, but many times it is not and it is necessary to contact the manufacturer to provide it) to know the addresses where the variables to be read are.  
For instance, to read instantaneous power in the photovoltaic defined above, the following definition must be included in the configuration:  
- platform: Modbus #Modbus scan_interval: 1 #scan interval registers:
- name: Photovoltaic1_Instant_Power #monitored parameter hub: Photovoltaic 1 #element defined previously register_type: input #type of register (input, holding, etc.) unit_of_measurement: W #unit of the parameter slave: 1 #Modbus Id register: 44 #Modbus address count: 1 #number of address affected scale: 1 #scale (x1, x10, etc.)  
In http protocol, we do not need to include all this information; in the http address defined before is included the position of the parameter to monitor (and password if required):  
http://admin:[EMAIL_ADDRESS]/io.cgi? | awk '/'relays/{print substr($2, 1, 1)}' (accessed on 1 January 2021)  
This will have to be done for each parameter to monitor. In dispatchable generation elements, such as the photovoltaic, wind turbines, and loads, it is just necessary to read power (instantaneous values) since action orders cannot be sent to them. By contrast, in dispatchable generation elements and storage systems, it is necessary to read all the registers. With them, a SCADA is developed that allows for control of their operation through the control panel, integrated with all the elements of the grid. The steps to integrate grid elements into the same data network and establish communication with the Home Assistant control system are shown in Figure 2.  
**Step 4. ** Create a control framework: once the communication has been established between all the elements of the grid, a control interface (HMI) must be created to visualise, simply and intuitively, the working mode of each element of the grid, and to send operating instructions to achieve optimisation in the performance of the microgrid, maximising its efficiency. With Home Assistant, it is easy to create an interface to control the grid after establishing communication with all the grid elements and defining them in the configuration file. The starting point is a graphical interface that gives the possibility to insert cards with different functionalities. It is possible to add cards with maps or weather forecasts that facilitate the estimation of renewable generation systems' power production.