Difference between the energy and the Hamiltonian in a specific example The problem is the following:

Consider a particle of mass $m$ confined in a long and thin hollow pipe, which rotates in the $xy$ plane with constant angular velocity $\omega$. The rotation axis passes through one of the ends of the pipe.
The objective of the problem is to describe the motion of the particle.

My question is about the Lagrangian, Hamiltonian and energy of the particle.
Let $r$ be the distance of the particle from the $z$ axis. The kinetic energy $T$ is
$$T=  \dfrac{1}{2}m\dot{r}^2+\dfrac{1}{2}mr^2 \omega^2.$$
The potential is zero. So that, the Lagrangian is
$$L=T= \dfrac{1}{2}m\dot{r}^2+\dfrac{1}{2}mr^2 \omega^2.\tag{1}$$
We have that $\dfrac{\partial L}{\partial \dot{q}}=p$ and $\dfrac{\partial L}{\partial q}=\dot{p}$. In this case,
$\dfrac{\partial L}{\partial \dot{r}}=m \dot{r}=p$ and $\dfrac{\partial L}{\partial r}=mr\omega^2=\dot{p}$.
The Hamiltonian is $\sum p\dot{q} -L$, so that
$$H=\dfrac{1}{2m}p^2 -\dfrac{1}{2}mr^2\omega^2\tag{2}.$$
According to Laudau and Lifshitz-Mechanics, the energy of a system $E$, when the Lagrangian have no explicit dependence on time (page 14), is
$$ E =\sum \dot{q} \dfrac{\partial L}{\partial \dot{q}} -L=\sum \dot{q}p -L.\tag{3}$$ 
Applying this definition to our Lagrangian (1), we get that the energy is equal to the Hamiltonian
$$E=\dfrac{1}{2m}p^2 -\dfrac{1}{2}mr^2\omega^2=\dfrac{1}{2}m\dot{r}^2 -\dfrac{1}{2}mr^2\omega^2.  \tag{4}$$ 
But the kinetic energy of the system is just $T=\dfrac{1}{2}m\dot{r}^2+\dfrac{1}{2}mr^2 \omega^2$ and the potential is zero, so the energy should be 
$$E=T=\dfrac{1}{2}m\dot{r}^2\color{red}{+}\dfrac{1}{2}mr^2 \omega^2\tag{5}$$
The middle sign is different from the sign of equation (4).
The questions are: Are my expressions right? Am I missing something? IS $L\&L$ definition of energy right?
 A: OP's pipe-confined bead can be modelled in at least 2 ways using an initial frame:

*

*As having 1 DOF $r$. This is OP's method. The Lagrangian is$^1$
$$ L_1(r,\dot{r})~=~  \frac{1}{2}m( \dot{r}^2+r^2\omega^2), \tag{1L}$$
the Lagrangian energy function is
$$\begin{align}
h_1(r,\dot{r})~:=~&\dot{r}\frac{\partial L_1(r,\dot{r})}{\partial\dot{r}}- L_1(r,\dot{r}) \cr
~=~& \frac{1}{2}m( \dot{r}^2\color{red}{-}r^2\omega^2),\end{align}\tag{1h}$$
and the Hamiltonian is
$$ H_1(r,p_r)~=~\frac{p_r^2}{2m}\color{red}{-}\frac{1}{2}mr^2\omega^2.\tag{1H}$$
The Lagrangian $L_1$ has no explicit time dependence, so the Lagrangian energy function $h_1$ and Hamiltonian $H_1$ are conserved. The 2 latter functions $h_1$  and $H_1$ have the same value, but different from the total mechanical energy $E$ of the bead. As we shall see, the issue is that the bead is not an isolated system.


*As having 2 DOF $(r,\phi)$ with 1 time-dependent holonomic constraint $\phi-\omega t\approx 0$. The Lagrangian is
$$L_2~=~ \frac{1}{2}m( \dot{r}^2+r^2\dot{\phi}^2)+ \lambda(\phi-\omega t),\tag{2L}$$
the Lagrangian energy function is
$$h_2~=~ \frac{1}{2}m( \dot{r}^2\color{red}{+}r^2\dot{\phi}^2) -\lambda(\phi-\omega t),\tag{2h}$$
and the Hamiltonian is
$$ H_2~=~\frac{p_r^2}{2m}\color{red}{+}\frac{p_{\phi}^2}{2mr^2}  -\lambda(\phi-\omega t).\tag{2H}$$
The 3 functions $L_2$, $h_2$ and $H_2$ have explicit time dependence. The Lagrangian energy function $h_2$ and Hamiltonian $H_2$ are equal to the total energy $E$.
The Lagrange multiplier$^2$
$$\lambda~\approx~\dot{p}_{\phi}, \qquad p_{\phi}~=~mr^2\dot{\phi},\tag{$\lambda$}$$
can be determined from the EOM. It has an interpretation as an external constraint generalized force $Q_{\phi}=\lambda$ acting on the bead. Its power is equal to the rate of total energy gain
of the bead $$ \frac{dh_2}{dt}~\approx~P~=~Q_{\phi}\dot{\phi}~=~\lambda\dot{\phi}~\approx~\frac{d(p_{\phi}\omega)}{dt}, \tag{P}$$
i.e. the pipe is doing work on the bead. In other words, the difference
$$ h_1~\approx~h_2-p_{\phi}\omega \tag{h}$$
between the LHS and RHS of eq. (P) is conserved. This explains OP's observations.
References:

*

*H. Goldstein, Classical Mechanics; section 1.6. (Hat tip: secavara.)


*For a similar example, see e.g. this Phys.SE post.

$^1$ The Lagrangian $L_1$ is the same in the pipe's rotating reference frame: the only difference is that the second kinetic term is reinterpreted as minus the centrifugal potential.
$^2$ The $\approx$ symbol means equality modulo EOMs & constraints.
