  We present a representation of the generalized $p$-Onsager algebras
$O_p(A^{(1)}_{n-1})$, $O_p(D^{(2)}_{n+1})$, $O_p(B^{(1)}_n)$,
$O_p(\tilde{B}^{(1)}_n)$ and $O_p(D^{(1)}_n)$ in which the generators are
expressed as local Hamiltonians of XXZ type spin chains with various boundary
terms reflecting the Dynkin diagrams. Their symmetry is described by the
reflection $K$ matrices which are obtained recently by a $q$-boson matrix
product construction related to the 3D integrability and characterized by
Onsager coideals of quantum affine algebras. The spectral decomposition of the
$K$ matrices with respect to the classical part of the Onsager algebra is
described conjecturally. We also include a proof of a certain invariance
property of boundary vectors in the $q$-boson Fock space playing a key role in
the matrix product construction.
