I don't really think you need an infinite recurrence equation. I'm pretty confident that the following solves the question with a recurrence relation with just 2 terms.
Ternary sequences can start with $0$, $1$, or $2$, so we need cases
- $3a_{n-1}$ Starts with $0$, $1$, or $2$, followed by an $n-1$ length sequence. This includes some invalid sequences so we subtract them later
- $-a_{n-2}$ Has two a $1$s in a row, so follow with a $n-2$ length sequence. (We subtract since it's invalid)
- $-a_{n-2}$ Has two a $2$s in a row, so follow with a $n-2$ length sequence. (Again, subtract since it's invalid)
Combining the cases we get
$$a_n=3a_{n-1}-2a_{n-2}$$
Base cases
$a_0=1$ (1 way to have a sequence of nothing)
$a_1=3$ (3 since there's no way to get an illegal sequence using only 1 digit & there are 3 digits)
$$$$
Does this work? I think it does, but let's verify for $n=2$
$a_2=3a_{2-1}-2a_{2-2}$
$=3a_1-2a_0$
$=3*3-2*1$ (plugging in bases cases)
$=9-2$
$=7$
Verifying combinatorially by counting
$a_2=$ all sequences of length $2$ minus the invalid ones ($11$ and $22$)
$a_2=3^2-1-1$ (3 possible digits in each space, minus 2 invalid)
$=9-2$
$=7$
Or you could literally write out the possible sequences of length 2 & count them up excluding the invalid sequences $11$ and $22$
$00$, $01$, $02$, $10$, $12$, $20$, $21$
I count $7$ valid sequences