In this work, a novel approach to deal with the PV forecast uncertainty during the energy management of a microgrid is presented. A novel adaptation of an analogs ensembles method allows to obtain a Sharpness indicator that is correlated with the PV forecast uncertainty. This indicator can be used to dynamically restrict the usable battery capacity when doing the day-ahead optimal scheduling using a genetic algorithm. This permits to deal with the PV uncertainty internally within the microgrid. This gives a total certainty to the grid operator about the power needs of the microgrid one day in advance. In this way, in a big scale, the uncertainty caused by a higher penetration of renewable energy sources in the national grid could be highly reduced. The main results of a real study-case are presented and the limitations of the method for its implementation are also discussed.