I am having trouble understanding the following equality:
If the starting distribution is $\lambda$, than the expected numbers of visits to $A$ before $T$ is $$E_\lambda \sum_{n=0}^{T-1} \delta_{X_n}(A)=\sum_{n=0}^\infty P_\lambda(X_n\in A,T>n)$$ where $\delta_{X_n}(A)$ is the indicator function.
I am having trouble relating the sums on both sides. I know that
$$E_\lambda \sum_{n=0}^{T-1} \delta_{X_n}(A)=\sum_{n=0}^{T-1} P_\lambda(X_n\in A)$$
but that doesn't help me much. I know there is something obvious I am missing. To me, it seems weird, that the left side is dependent on $T$, as it is stated "the number of visits before $T$", yet the right side has the $T$ summed out. Is there a misunderstanding between me and the text, and the $T$ is not a fixed quantity?
Hint : Write $\sum\limits_{k = 0}^{T - 1} \mathbb{1}_{A}(X_n) = \sum\limits_{k = 0}^{\infty}\Big( \mathbb{1}_{[0, T - 1]}(k) \,\cdot\, \mathbb{1}_{A}(X_n)\Big) $
One needs to be careful when the boundaries of the summation are themselves defined as random variables (here $T$). A good trick to go is the one given above, where we use an indicator to have a summation that does not longer depend on something random.