## 1 Introduction
In rural areas, irrigation control is performed by comparing environmental parameters with sensors located along the crop, electrovalves as actuators that control the water flow and thus obtain greater efficiency and less water waste [14]. Although these studies have contributed to the improvement of irrigation, they do not consider the future state of irrigation variables, so their decisions are not the most optimal. Optimal irrigation has not been fully addressed with smart tools, such as model-based predictive control (MPC), which allow the improvement of agricultural production at low costs by taking advantage of optimally managed natural resources and analyzing the technical feasibility of future events [15]. Agriculture is one of the main energy demanders in society through the extraction of water for irrigation [16], and it should be taken into account that crops interact with solar radiation, which means that the higher the radiation, the greater the water needs of the crop. A viable solution is solar pumping in off-grid systems to supply water to different communities [17; 18]. On the other hand, irrigation systems require energy for their operation and the most common is that irrigations are located in areas far from the power grid and require diesel-based generation units, in few cases based on renewable resources [19]; however, microgrids can be an alternative in order to supply the energy to this system in an environmentally friendly way. In developing countries, in rural areas that do not have access to electricity supply, agricultural production is affected. Therefore, the combination of a water management systems for irrigation water requirements with an energy management system considering climatic conditions optimizes the use of energy and water in agricultural production [20]. Microgrids are useful for supplying electricity demand in isolated locations, considering the characteristics of the loads and managing energy [21]. The surplus energy after supplying the local demand can be stored in batteries to reduce the consumption of energy based on fossil sources [22]. Work has been done on proposals for smart irrigation; however, this is not enough--techniques that also use water optimally are required, supporting the reduction of water resources and minimizing the effect of global warming. In addition, including energy sources to supply the demand of irrigation systems based on natural resources and managing them properly contributes to the reduction of carbon footprints. Currently, there are problems in food production in the agricultural sector due to the increase in the world population growth [1; 23] as well as pollution problems due to the use of pumps based on fossil resources in isolated areas, far the electricity grid. These aspects have increased the costs of agricultural production [24]. In order to reduce these problems, some studies have researched how to meet the demand for water by reducing energy consumption [25; 26]. Thus, it is necessary to create strategies to save water resources and energy and minimize pollution. In this context, the main aim of this article is to propose a smart irrigation system considering optimal energy management based on model predictive control (MPC), which achieves efficient cultivation with minimum water consumption at the same time that the electrical demand is supplied with a microgrid based on renewable resources, which is optimally managed. This research proposes a system that allows smart irrigation and, at the same time, achieves an optimal management of water resources. In addition, optimal energy management is achieved by improving agricultural production while respecting technical conditions and guaranteeing clean, environmentally friendly and low-cost energy. The proposal considers two stages, the first stage corresponds to the smart irrigation through the water balance, which provides the knowledge of the water needs in the root zone of the crop, thus generating the optimal irrigation profile, considering climatic variables.