This is not a direct answer, rather a small contribution of what happens in the opposite case as well as an answer to a comment of the OP. Hope that it can help.
Of course, if your $C^*$-algebra $\mathcal{B}$ admits such an idempotent endomorphism (call it $\alpha$), you have a (straightforward) structure theorem
$$
\mathcal{B}=ker(\alpha)\oplus im(\alpha)=\mathcal{I}\oplus \mathcal{B}_1 \qquad\qquad (*)
$$
$\mathcal{I}$ is a two-sided ideal and $\mathcal{B}_1$ a sub-$C^*$-algebra.
Even if this direct sum is not trivial, the decomposition of $1_\mathcal{B}$ can be trivial.
Before giving examples, I elaborate a bit on the vein of retracts indicated by Ali and underlined by Nik. I provide it in the framework of operator-valued algebras in order to answer a comment of the OP, as $\mathcal{C}(K)\widehat{\otimes} M_n(\mathbb{C})\simeq \mathcal{C}(K,M_n(\mathbb{C}))$.
Let $\mathcal{A}$ be a $C^*$-algebra and $K_1\subset K_2$ be two compact Hausdorff sets, we suppose that it exists a continuous retraction $r : K_2\rightarrow K_1$. Let
$$
res_{1,2} : \mathcal{C}(K_2,\mathcal{A})\rightarrow \mathcal{C}(K_1,\mathcal{A})\mbox{ and }
\delta_r : \mathcal{C}(K_1,\mathcal{A})\rightarrow \mathcal{C}(K_2,\mathcal{A})
$$
be respectively the natural restriction and $\delta_r(f)=f\circ r$. One checks immediately that\
$res_{1,2}\circ \delta_r=Id_{\mathcal{C}(K_1,\mathcal{A})}$ and that $\alpha=\delta_r\circ res_{1,2}$ is an idempotent $*$-endomorphism of $\mathcal{C}(K_2,\mathcal{A})$.
We come back to the notation around (*).
Below two examples : in the first, $\alpha$ is due to the multiplication by an idempotent (which serves as unit for $\mathcal{B}_1=Im(\alpha)$) and the second one, transformed in its noncommutative incarnation, where this is not the case (one can take $\mathcal{A}=M_n(\mathbb{C})$ with $n\geq 2$, but it is true for all $\mathcal{A}$).
Example 1 Direct sum of two (non trivial) $C^*$-algebras : in this case $1_{\mathcal{B}_1}\not= 1_\mathcal{B}$
Example 2 Where $1_{\mathcal{B}_1}=1_\mathcal{B}$ and therefore the projection of the unity on $\mathcal{I}$ is zero. Take the following real intervals
$$
K_1=[0,1];\ K_2=[0,2], \mathcal{B}=\mathcal{C}(K_2,\mathcal{A}),\
\mathcal{B}_1=\mathcal{C}(K_1,\mathcal{A})\ .
$$
The retraction $r : K_2\rightarrow K_1$ being given by the identity on $[0,1]$ and $r(t)=r(1)=1$ on $[1,2]$. It becomes clear that, for $f\in \mathcal{B}$, $\alpha(f)=g$ where $g(x)=f(x)$ on $K_1=[0,1]$ and $g(x)=f(1)$ on $[1,2]$ then the image of $\alpha$ is the sub-$C^*$-algebra of (continuous) functions which are constant on $[1,2]$, it contains the identity and the supplement $\mathcal{I}$ is the space of functions vanishing at $1$. We are in the second case.