Generalized q-Onsager algebras and dynamical K-matrices