Hydrogen is a promising candidate for green energy sources for future endeavors because of its abundance on Earth. Although its storage is a major challenge for the researchers of this era because of its unsafe and highly explosive nature. The structural, optoelectronic, thermoelectric, vibrational, thermodynamic properties and hydrogen storage capacity of XMgH3 ([Formula: see text], Ba) are carried out by using the full potential linearized augmented plane wave (FP-LAPW) method in the DFT framework. The theoretical study about these magnesium-based metal hydride perovskites, i.e., SrMgH3 and BaMgH3, declares them structurally stable compounds in space group Pm-3m. The optimization graph for SrMgH3 and BaMgH3 reflects the lowest ground state energy, i.e., −6759[Formula: see text]Ry and −16683[Formula: see text]Ry, respectively. Comparatively, BaMgH3 seems to be more stable. The electronic band structures and density of states declare them pure metallic due to zero band gap and overlapping of electronic states of the valence and the conduction bands. The electrical conductivity of BaMgH3 increases up to [Formula: see text] and thermal conductivity [Formula: see text] in the temperature range 100[Formula: see text]K to 1000[Formula: see text]K revealing the good metallic character of BaMgH3. The optical analysis portrays the absorption of compounds in the visible range along with valance shell electrons to the weak bond of hydrogen and dissociates hydrogen molecules at a certain intensity of light. BaMgH3 compound shows minimum scattering and maximum absorption of light in the visible region up to 3[Formula: see text]eV. The reflectivity peaks in the visible region 3.0[Formula: see text]eV show that 40% of light energy is absorbed due to the opaque nature of BaMgH3. Both these compounds are declared thermodynamically stable due to negative free energy such as −1.20[Formula: see text]eV for SrMgH3 and −1.50[Formula: see text]eV energy for BaMgH3 at 1000[Formula: see text]K, respectively. Moreover, the three acoustic modes showing zero imaginary phonon frequencies at [Formula: see text] symmetry points predict these compounds’ structural and thermodynamical stability. The gravimetric hydrogen storage concentration of SrMgH3 and BaMgH3 is determined as 2.637% and 1.836%, respectively.