HMM - state transition depending on amount of time spent in states Can we have a HMM where state transition is dependent on amount of time spent in states? 
Suppose I build a hidden markov model(HMM) with 2 hidden states - S1, S2. In normal HMM, we assume the state transitions P(S1|S2) and P(S2|S1) is same irrespective of the time spent in S1 and S2. 
Is there a way to relax this assumption? e.g. In my use case - a better assumption may be - Probability of transitioning to S2 from S1 i.e. P(S2|S1) at time t, is a decreasing function of how much time is spent in S1 till time t. 
In other words, if more time is spent in a state, the probability of transitioning out of that state decreases. Is there a similar model in literature that I can use?
 A: The amount of time a chain $X_t$ spends in some set or region $A$ up until time $k$ can be written as 
$$
\sum_{i=1}^k 1(X_i \in A).
$$
Making the transitions at time $k$ depend on this would imply the process is no longer a Markov chain.
However, if you create a variable 
$$
\tilde{X}_k = \sum_{i=k-l+1}^k 1(X_i \in A)
$$
then this is Markov of order $l$, and this will be a Markov chain. You will have to manually derive the transitions of this chain, but in general, it can only go up one, down one, or stay the same.
And, as @whuber points out, you may have the the transition matrix of the hidden chain depend on time deterministically. It is often assumed for convenience that the chain is homogeneous, but this is not necessary. 
Third, you might be interested in left-to-right hidden Markov models. Instead of the hidden state representing which regime you're in, it will represent the amount of time heretofore spent in state, say, $1$. That means that this state can only increase, or stay the same, making the transition matrix upper-triangular (and very large). 
