We introduce a notion of an associative trinary relation arising from two homeomorphisms that satisfy a certain relation and construct an associated $C^*$-algebra. We prove a sufficient condition for the $C^*$-algebra to have a maximal closed two-sided ideal. As an example, we study a trinary relation arising from two homeomorphisms of the ring of $p$-adic integers and show that the associated $C^*$-algebra has a maximal closed two-sided ideal.