I am having trouble trying to understand how to use MQTT for none Homie/HA devices. On the screenshot below, I would like to subscribe to the room/* topics and the device/* topics and then parse those topics in Jython. I can’t figure out how to set a OH item to catch those base topics and pass the full topic and the value.
First, if it is Homie then the Thing can be automatically discovered by the binding. Just open the Inbox, click + and choose Homie. You don’t have to create a Generic Thing. When scanning for things, each device in that hierarchy will be discovered as a separate Thing and each Thing will have Channels for all the sensors and actuators. Those Channels you care about are linked to Items. No parsing of topics nor parsing of the telemetry nor anything like that is required. That’s kind of the whole point of bindings after all.
If you don’t want to take advantage of the automatic discovery of devices through Homie, you can. Follow the steps James outlined to create your MQTT Things with some modifications. The general preference is to do one Thing per device represented in the MQTT hierarchy. You will probably want to use the regex transform to extract each of the pieces if information you want from the array of name/value pairs that you are interested in. Each would get its own Channel. So for example, one Channel would subscribe to espresense/rooms/office with a regex .distance":"(.)".* for distance and another Channel would subscribe to the same topic with regex .speed":"(.)".* for speed.
You can open the code tab and once you create one Channel it’s really easy to copy/paste edit to create the rest.
You also have two options for wild card subscriptions. You can follow James’ approach to create a Channel linked to a String Item that receives the messages on any topic below rooms. However, the actual full topic name will be lost. You’ll just get the message itself which might not be sufficient to identify which Items the data belongs with.
Another alternative is to create an Event Channel on the MQTT Broker Thing itself. Use the wild card subscription and add a divider character. The event passed to the rule will have the full topic name as well as the message separated by that character so you can easily do a split to separate the two.