Diagonalizing an idempotent matrix over a local ring
Let $\mathcal O$ be a commutative local ring, let $I$ be a finite set, and let $e\in M_I(\mathcal O)$ satisfy $e^2=e$. There are matrices $P,Q\in M_I(\mathcal O)$ and elements $d_i\in\{0,1\}\subseteq\mathcal O$ such that $$PQ=QP=I,\qquad e=P\operatorname{diag}(d_i)Q.$$