MQTT separate state channel from command vs All-in-one

I’ve been playing around with MQTT lately (openhab 2.4, embedded broker and MQTT 2.4 binding) and I think I’m ready to put all my rollershutters under openhab.
Putting aside the rollershutter type problems and the need of “proxy” items and transformation I would like to know if there is a “best practice” in creating all the needed MQTT channels:

Is it better to create separate channel for every topic or it’s better to “aggregate” when possible?
I can see in PaperUI that you can set up a “MQTT command topic” and a “MQTT state topic” all in one channel definition, which method do you suggest?
Do you see any pros or cons in both of the two methods?

Thank you for your time!

The point of the having a command topic and a state topic in one channel is for knowing if the command you sent got actually executed. By publishing with qos 1 or 2 you can make sure your subscriber / device receives a command but you wouldn’t know if it actually acted on it. This is what the state topic is for. Many commercial products that use mqtt do something like this. One main topic per device and than subtopics for command and state, subtopics for sensor values and than another one for firmware EG.
This actually works well with how the Openhab 2 architecture is setup. As you have one thing which represents a physical object and you can add channels to that which represent it’s properties.
So to summarize I would probably recommend one Thing per physical object (rollershutter) and than one channel per function/ property this object has.
Best regards Johannes

1 Like

I recommend thinking about it from the OH perspective. A Thing represents a device. Each device has one or more sensors and/or one or more actuators (things OH can command to cause something to happen).

Actuators tend to be two way. You get status updates from them and you can send messages to them. And most of the time in MQTT those two are done on different topics. But because it is logically the same actuator, it makes the most sense to create just one Channel for that actuator that subscribes to the status topic and publishes to the command topic.

Taking it one step further, all of the Channels for that device should be in one Thing. But each device should have it’s own Thing. This will keep your MQTT Things consistent with how all the other bindings create their Things.

1 Like

Thank you very much guys!

I will surely follow your suggestions.