Lagrangian mechanics and thermodynamics

Dear friends,

After having studied thermodynamics for some months as well as Lagrangian mechanics, I'm trying to find a relationship between the Hamiltonian, Lagrangian, conjugated potentials etc. and thermodynamic potentials (such as Gibbs free energy, Enthalpy etc.).

I mean, they may have nothing to do with each other but I'm sure there's an analogy. I've learned to do Legendre's transformations in both fields!

Is The analogous of the principle of least action the principle of minimum energy at constant entropy?

I don't know if it's a waste of time trying to find a conexion.

Happy new year!