In this paper we describe 4-dimensional gravity coupled to scalar and Maxwell fields by the Einstein-Katz action, that is, the covariant version of the "Gamma-Gamma − Gamma-Gamma" part of the Hilbert action supplemented by the divergence of a generalized "Katz vector". We consider static solutions of Einstein's equations, parametrized by some integration constants, which describe an ensemble of asymptotically AdS black holes. Instead of the usual Dirichlet boundary conditions, which aim at singling out a specific solution within the ensemble, we impose that the variation of the action vanishes on shell for the broadest possible class of solutions. We will see that, when a long-range scalar "hair" is present, only sub-families of the solutions can obey that criterion. The KatzBicak-Lynden-Bell ("KBL") superpotential built on this (generalized) vector will then give straightforwardly the Noether charges associated with the spacetime symmetries (that is, in the static case, the mass). Computing the action on shell, we will see next that the solutions which obey the imposed variational principle, and with Noether charges given by the KBL superpotential, satisfy the Gibbs relation, the Katz vectors playing the role of "counterterms". Finally, we show on the specific example of dyonic black holes that the sub-class selected by our variational principle satisfies the first law of thermodynamics when their mass is defined by the KBL superpotential.