Use MQTT payload in new Item/Thing channel


I’m working on OpenHAB 2.5.2 on an RPi2. OH is installed on Raspian
I’m a litte bit stuck with an issue on persisting messages that are received in an MQTT2-topic.

OpenHAB configuration is working well and I’m able to subscribe or publish certain MQTT topics (with MQTT binding to a mosquitto mqtt broker).

Now the problem: On getting a message containing a string in a certain MQTT topic I need to save the payload of the message in some way. Then I need create a thing channel and further on an item which should be added to a sitemap.
This item/channel should publish exactly the message (on another topic) which was received before.
Does anyone have an idea how this could be done?
I think it involves dynamic channel (or even item) creation but I’m not sure how to do this.

Any help is very much appreciated!



Hmmm you are looking forward do create Things/Chanel/Items after a MQTT message on X Topic has published right?

For the whole Things/Chanel/Items I would use the openHAB REST API

Do you have any from of persistence on your openHAB system like InfluxDB?

Your goal looks to me more like some external script example Python which listens to MQTT and does the magic via REST.

I’m not sure I fully understand what you are after but dynamic Channel or Item creation seems way more complex than is warranted here. Let’s break it down step by step.

Goal: Save a received MQTT message so it can be published to a different MQTT topic later.

On getting a message containing a string in a certain MQTT topic I need to save the payload of the message in some way.

Create a Generic MQTT Thing with a Text Channel to subscribe to this topic.

Link the Channel to a String Item.

The message will be saved in that String Item.

What is different about this Item that goes on your sitemap from the String Item that saves the message? What do you need the Thing and Channel for? What information would you use to create this Thing, Channel, and Item? The contents of the message perhaps?

What event occurs to cause the message to be sent to this new topic?

I can’t say one way or the other with the information provided but I suspect the MQTT Action and a Rule would suffice.


thank you very much for the very helpful answers so far!
Seems that there are muliple solutions for that problem.
The way with python/REST API fits good for me as I prefer programming things myself and I’m not that familiar with all the possibilities OH is offering.
One question that arises here is how items can be added to a sitemap automatically? Or should i simply add the items to a group and add the group to the sitemap which displays all items contained in it?

Concerning the question for what I need these things/channels for:
I’m getting decoded IR commands from an ESP. They should be stored in OH and added to a sitemap to create a kind of remote control.
In learn-mode the ESP recognizes IR commands from a “hardware” IR remote control (e.g. from a TV), and sends them as a string via MQTT.
From this commands I’ve to create different items in a sitemap and when I click on a specific item the command-string stored before is sent to the ESP again (to another MQTT topic), which emits the IR signal.

Adding the Item to a Group might work assuming the sitemap is smart enough to query for changes in Group membership. I’m not sure that it is so you’ll have to reload the page to see the new Items. Also you will have zero customization that you can do. The order of the Items added is not guaranteed and you can’t override the defaults.

Personally, unless I had a metric ton of buttons to handle I’d probably just use something like MQTT Explorer to see the messages and code up the sitemap manually. In the end the overall end user experience will be better as you will be able to define the order in which they appear, take advantages of stuff like mappings so you can present buttons on the sitemap instead of each and every button being a toggle switch.

You are trying to make something that duplicates the functionality of your remote. You probably want it to look like a remote too. You can’t do that in OH programatically. There isn’t enough information to do so and even if there was enough information you would have to open up and make edits to the sitemap from your Rule, something that is never as easy as it seems.

If you care how it looks, I recommend another approach.