Consider paths through the lamplighter group $\mathbb{Z}_n\wr\mathbb{Z}$ with steps consisting of moving left, moving right, and toggling the lamp at the current position. How many paths of length $m$ visit an unlit lamp $k$ times, with all lamps initially off?
In other words, let $D$ be the set of "dark paths", i.e. paths where the lamp at the final position is off. This set is equinumerous with the set of paths $D'$ that leave the lamp at the origin off. A grammar for $D'$ is
$$D' = (((RM_RL+LM_LR)^* T)^n)^* (RM_RL+LM_LR)^* (\varepsilon+RM_R(RM_R)^*+LM_L(LM_L)^*)$$
where \begin{align} M_R=(T+RM_RL)^* \\ M_L=(T+LM_LR)^* \end{align}
are left- and right-leaning Motzkin paths, respectively. Thus the generating function for $D$ at $z$ is $D'$ with $L = R = T = z$:
\begin{align} D(z)=\frac{1-z(2+3z+\sqrt{1-2z-3z^2})}{(1-3z)(1-2z-4z^2)\left(1-\left(\frac{z}{z+\sqrt{1-2z-3z^2}}\right)^n\right)} \end{align}
I am interested in obtaining the generating function $f$ such that
$$[x^m y^k]f_n(x,y) = \{w \in \{L,R,T\}^m : |\text{Pref}(w) \cap D| = k\}$$
where $\text{Pref}(w)$ is the set of $|w|+1$ prefixes of $w$. For example, $$f_2(x,y) = y + x(y+2y^2) + x^2(5y^2+4y^3) + x^3(5y^2+14y^3+8y^4) + \dots$$
I can establish some lower bounds. For example, we can consider only words where the lamplighter doesn't move left (or right) after toggling a lamp, so there's only one lamp state to keep track of at a time. Is it possible to generalize this to the case where the lamplighter can encounter multiple previously-toggled lamps?