MQTT2, Things, Channels, Items

I’m belatedly migrating from MQTTv1 to MQTTv2. I may be being thick but I’m struggling to know the difference between a Channel and an Item,
I created a Thing in PaperUI, I then add Chennels to the Thing. As I have rules which refer to Items previously created I then cut and paste the Channel ID into the Item description.
I then end up with 2 ‘Items’ in PaperUI in the Control section one the Channel created in PaperUI and the other the Item created in my items file.
It looks like I only need an Item because I can’t give the Channel a suitable name when I create the Channel. There appears to be no documentation on how to create an Item from the original Thing for the device instead of adding the Channels so it looks like I need both channels and Items.
I have no objection to the duplication of the Channels and Items but I started programming Commodore PETs with 64k of RAM and still don’t like wasting memory unnecessarily.
Am I misunderstanding the concepts?

It might be worth while to re-review the concepts sections of the docs. At a high level:

Things represent the device. Each piece of information (i.e. actuators and sensors) are represented by a Channel. Channels are linked to Item. Everything else in openHAB uses Items.

The abstraction between Thing and Item is there for a reason and it’s deliberate. So you do in fact need to have both the Channel and the Item.

There is an OH2 system option ‘Simple Mode’ which (un)helpfully auto-creates Items when channels appear. They come with long names etc.
Simple Mode seemed like a good idea, but invariably becomes a nuisance when you progress beyond novice e.g. when manually creating Things. It’s certainly no help if you are trying to fit to existing rules.
Turn that mode off!

1 Like

Thanks Rik but why do I end up with the sensor appearing twice in the Control section of PaperUI? I’ve been running openHAB for several years now with MQTTv1 and used PaperUI on a minimal basis as I’ve used Items files (and the very occasional Things files) but I read your advice to create the MQTT Things using PaperUI. The old MQTTv1 binding had lots of examples of how to create Items and the ability to cut and paste a previous Item meant I could add a new Item in seconds (I have 342 items in my configuration).

It appears that I cannot create a link to the base Thing in an Items file so I have to create a Channel in PaperUI. So my Sonoff TH10 with 5 DS18B20s has 5 Channels for the sensors plus another for the relay. I create them in PaperUI and they then will appear in the Control section. But I want to use them with Rules and in my Sitemap (I think I can use the Channel directly but it’s not user friendly and I’d have to hunt through several Rules to find them) so I create 6 Items (in fact my old Items with channel= instead of mqtt=). They also appear in the Control section so I now have 12 there. I can read the sensors (twice) and switch the relay on/off with either the Channel or the Item.

There seems to be pointless duplication which could be resolved if I could give the ‘Channel’ the Item name or, better still, call the ‘Channel’ an Item and get rid of the Channel completely. It may be that MQTTv2 is operating slightly differently to other Bindings but the TP-Link binding, for example, doesn’t end up with duplicates whether I create it with files or via PaperUI.

Regards

Philip Knowles

I upgraded recently (prior to a potential move to OH3) and Simple Mode must have set itself back on somehow which explains a lot. I normally only use PaperUI to add a binding etc so didn’t even look. I can stop pulling out what’s left of my hair.

Well it’s not the fairies or the hated channels that create Items. It’s either you or Simple Mode. Turn it off. I seem to recall there was one upgrade path somewhere in OH2.x that could turn it on if it wasn’t before, so this may not always have been present for you. EDIT -ah you discovered that already :slight_smile:
Afterwards, you will have to deal with any duplicates it created manually.

I see that you may have found the source of the phantom entry in the Control tab. But I want to elaborate on what is going on and clear a few other things up.

The Control tab in PaperUI will present all Items that are linked to a Channel. If the same Channel shows up twice there that means there are two Items linked to that Channel.

As an aside, this is only one of the reasons why I hate PaperUI’s Control tab and absolutely loath Simple Mode. It blurs the distinction between Item and Thing/Channel and as a result only serves to confuse the user and ultimately does a whole lot of stuff that will have to be manually cleaned up later.

I recommend the following procedure.

  1. If you haven’t already, install the REST API Docs.
  2. Manually create one of your Generic MQTT Things with all the Channels you care about.
  3. Open the REST API Docs and query for that newly created Thing
  4. Copy the JSON that was returned to the “create thing” form.
  5. Edit the JSON with the configuration for the new similar Thing you want to create. All that you should really have to change are the topics published and subscribed to and the UID and label. Submit.
  6. Repeat 5 for each similar Generic MQTT Thing you need to create.

You will then need to go to your .items file and change out the MQTT 1 config for a link to the proper Channel.

That makes no sense. The Thing represents the device. A device will have one or more sensors and actuators. If you link the Thing to a Switch Item, which sensor or actuator on that Thing would the Item control? That’s why Things have Channels. Each Channel represents an individual sensor or actuator and that Switch Item needs to link to a Channel.

Only certain types of Channels (event trigger Channels) can be used to trigger a Rule, but those Channels cannot be linked to an Item. And Channels are stateless which makes them pretty much useless to sitemaps (so they cannot be used there) and rules. It’s the Items that maintain the state.

Since you are migrating this is how you should continue. Don’t create new Items, just change your old Items to point to the new MQTT Thing’s Channels.