A discussion of the H-H interactions in a metal is given. Based on self-consistent total-energy calculations within the local-density approximation for H2 in a homogeneous electron gas, we show that metallic electrons make the H-H interaction more repulsive than in vacuum. Using effective-medium theory to calculate total energies we show the same tendency for the short-range part of the H-H interaction when two H atoms are squeezed into a single site in Pd or PdH. At longer range (of the order a lattice constant) there is an attractive, lattice-mediated H-H interaction. On the basis of the calculated energetics, the thermodynamical properties of various palladium hydrides are modeled.