Controlling Relay using mqtt

One of my IoT students was asking about nearly the same question that you posted on the forum.
He was using a Wemos D1 Mini - not sure what you are using. But I'm sure it could be adapted.

I've posted what we did on the forum as I think it might go some way to solving your problem.