  We investigate via exact diagonalization of finite clusters the electronic
structure and magnetism of M$_2$O$_9$ dimers in the mixed-valence hexagonal
perovskites A$_3$B'M$_2$O$_9$ for various different fillings of 4$d$ and 5$d$
transition-metal M ions. We find that the magnetic moments of such dimers are
determined by a subtle interplay of spin-orbit coupling, Hund's coupling, and
Coulomb repulsion, as well as the electron filling of the M ions. Most
importantly, the magnetic moments are anisotropic and temperature-dependent.
This behavior is a result of spin-orbit coupling, magnetic field effects, and
the existence of several nearly-degenerate electronic configurations whose
proximity allows occupation of excited states already at room temperature. This
analysis is consistent with experimental susceptibility measurements for a
variety of dimer-based materials. Furthermore, we perform a survey of
A$_3$B'M$_2$O$_9$ materials and propose ground-state phase diagrams for the
experimentally relevant M fillings of $d^{4.5}$, $d^{3.5}$ and $d^{2.5}$.
Finally, our results show that the usually applied Curie-Weiss law with a
constant magnetic moment cannot be used in these spin-orbit-coupled materials.
