Self-similarity in spaces of homogeneous type