We present a framework to carry out highly accurate $\mathrm{GGA}+U$ thermochemistry calculations by deriving effective $U$ values from experimental data. The $U$ values predicted in this approach are applied to metal cations, and depend not only on (i) the chemical identity and the band to which the $U$ correction is applied, but also on the local environment of the metal described by (ii) its oxidation state and (iii) the surrounding ligand. We predict such local environment dependent (LD) $U$ values for the common oxidation states of $3d$ metals $M=$ Ti, V, Cr, Mn, Fe, Co, and Ni in their oxides and fluorides. We implement the GGA/$\mathrm{GGA}+U$ mixing method [Jain et al. Phys. Rev. B 84, 045115 (2011)] to establish the total energy compatibility among the $\mathrm{GGA}+U$ calculations involving $M$ treated with different LD-$U$ values. Using the presented framework, formation enthalpies of 52 transition metal bearing oxides (which are not used during the LD-$U$ parametrization) are predicted with a remarkably small mean absolute error of $\ensuremath{\sim}19$ meV/atom, which is on the order of the experimental chemical accuracy. In addition, we present applications of the method in redox processes of important $3d$-metal oxide and fluoride systems such as ${\mathrm{Li}}_{x}{\mathrm{CoO}}_{2},{\mathrm{Li}}_{x}{\mathrm{V}}_{6}{\mathrm{O}}_{13},{\mathrm{Li}}_{x}{\mathrm{FeF}}_{3}$, and ${\mathrm{VO}}_{1.5+x}$, and show that LD-$\mathrm{GGA}+U$ can overcome several drawbacks of using constant-$U$ values in conventional $\mathrm{GGA}+U$.