I’m new with MQTT, I have a mosquitto MQTT broker on a Raspberry Pi.

I have some topics from a client in this format /topic/lighton can be true or false.

In other hand I can invoke some topics like /topic/light_on with value replay and /topic/light_off value replay.

I just need to push one of this two topic if I get the first topic true or false. Is there any kind of transformation or some software client subscribed to first topic that publish the second topics.

2 Answers 2


You might be overthinking it. You can just create an MQTT client service that runs on the RasPi separate from the mosquitto server that subscribes to the topic that you want to transform, then publishes to the new topic upon receiving the original one. It's perfectly fine to have an MQTT client running on the same machine as the MQTT server.

So the MQTT client would subscribe to /topic/lighton and publish to /topic/light_on or /topic/light_off after processing the value of what was received. The MQTT client transform service could be a simple Python program, or be in whatever your language of choice is using an MQTT client library.


First, it's bad practice to start topics with a leading / (while allowed in the spec it ends up causing problems later when you starting using things like shared subscriptions).

As John S hinted in his answer, this is not something you really want the broker to be doing, you should be doing this yourself with a separate client.

Assuming you are running the full Rasbian (RaspberryPi OS) then you have an application called Node-RED installed. This is a graphical flow based programming environment that was practically built to do this sort of thing.

You can drag a MQTT in node on to the canvas along with a change or function node to do the conversion and update the topic before passing it on to a MQTT out node to publish the new message.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.