I've spent a lot of time looking for examples, and I can't find any commutative rings which have a finite number of idempotents other than a power of $2$. Intuitively, adjoining an extra idempotent $a$ always seems to double the number, as for every other idempotent $b$, $ab$ is a new idempotent. But there doesn't seem to be any way to turn this into a proof. I'm not sure whether it's even true.
I have managed to prove the characteristic $2$ case, as there the idempotents form a subring, and hence $\mathbb{Z}_2$-Algebra. But this doesn't seem to be any help for the other cases. I'm sorry I can't show more of an attempt, but this really has me stumped.
So are there commutative rings with a finite number of idempotents which don't have $2^n$ idempotents for some $n$?
I also don't know of any rings that have $k \ne 2^n$ idempotents in the noncommutative case, but I haven't investigated that much.