Solution (source code)

= Solution

The pair $Z_n=(X_n,Y_n)$ is an irreducible positive recurrent <product Markov chain> with stationary distribution
$$
\Pi_{ij}=\pi_i\pi_j.
$$
The <stationary cycle occupation formula> says that, during one return cycle to a state $z$, the expected number of visits to a set $A$ is $\Pi(A)/\Pi(z)$. Take
$$
z=(0,0),
\qquad A=\{(i,1):i\geq0\}.
$$
Then
$$
\Pi(A)=\pi_1=\frac14,
\qquad
\Pi(0,0)=\pi_0^2=\frac14.
$$
The initial and terminal states both have $Y=0$, so either convention for including the endpoints gives the same count. Thus
$$
\boxed{\mathbb E\!\left[\#\{0\leq n\leq T:Y_n=1\}\right]=1}.
$$