MQTT link item

  • Platform information:
    • Hardware: RPI 3 B+ / SD 64Go
    • OS: strech_
    • Java version “1.8.0_201” Java™ SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot™
      Client VM (build 25.201-b09, mixed mode)
    • openHAB 2.4
  • Issue of the topic: I can not find how to link my string item in OH2 to subscribe and view the msg.payload of my topic (TCPin) that I published with node-red. Yet I see the string in the Node-red console and in the debug window of Node-red UI

Hello everyone

Below my parameters :

  • Items configuration related to the issue
String Message2 "Lu [%S]"          {mqtt = "<[broker:MosquittoPI3:/TCPin:state:default"}
String Message  "Lu [%S]"          {mqtt = "<[broker:MosquittoPI3:/TCPin"}
  • Sitemap configuration related to the issue

sitemap mqtt label="Test MQTT"
    //    Text item=VoiceCommand
        Frame label="MQTT Control" {
            Text item=MyString
            Text item=Message
  • Rules code related to the issue -> None
  • Services configuration related to the issue
  • If logs where generated please post these here using code fences:
  • Mosquitto Log:
    1558977765: mosquitto version 1.4.10 (build date Wed, 13 Feb 2019 00:45:38 +0000) starting
    1558977765: Config loaded from /etc/mosquitto/mosquitto.conf.
    1558977765: Opening ipv4 listen socket on port 1883.
    1558977765: Opening ipv6 listen socket on port 1883.
    1558977770: New connection from on port 1883.
    1558977770: New client connected from as paho5084805050204 (c1, k60, u’openhab’).
    1558977779: New connection from on port 1883.

Openhab2 Log:

08:55:19.227 [INFO ] [smarthome.event.ItemStateChangedEvent] - Message changed from Unknown pattern P0=13 - P1=12 - P2=25 - P3=34
to Apres lecture des pulses 00000101110001100000000000000001 len=32

08:55:19.255 [INFO ] [smarthome.event.ItemStateChangedEvent] - Message changed from Apres lecture des pulses 00000101110001100000000000000001 len=32
to 20;01;SmartWare;ID=00171800;SWITCH=1;CMD=OFF;

08:57:54.961 [INFO ] [.io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 1c3f93db-384a-4257-afa0-be8708c6a40a, base URL = http://localhost:8080)
08:59:51.571 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 1c3f93db-384a-4257-afa0-be8708c6a40a, base URL = http://localhost:8080)
09:18:28.414 [INFO ] [smarthome.event.ItemStateChangedEvent] - Message changed from 20;01;SmartWare;ID=00171800;SWITCH=1;CMD=OFF;
to Decodage stream de bits > 162 RawSignal.Number = 132

Thank you in advance for your information

We will probably need some more information to help you here. Which binding are you using? Mqtt 1 or 2? What kind of string are you sending and what is the thing and item you have in Openhab connected to your mqtt topic? An finally are you using paper ui or textual configuration or a mix. Without out some or all of this information it will be hard to tell what the problem is as we dont know your setup.
Best regards Johannes

sorry but I posted incomplete … I complemented my post … thank you

I think you are mixing the syntax from the mqtt 1x and 2x binding. From your paper ui screenshot it looks like you are using the new 2x Version of the Binding? If this is the case your string item will look nothing like this.
You need to create a string channel linked to the topic you post to from nodered in your generic mqtt thing in paper ui.

You than have to link this channel to your item in the item file with the correct syntax

String Test "Nodered Test" {channel="mqtt:topic:70f172d4:noderedtest"}

Hope this helps.

OK it works … great … a big thank you!
I have been badly oriented by some examples based on Mqtt1!
now can you tell me how to post a command to Mqtt from OH2 …

The most basic answer is you need to fill in the topic you expect commands on as your command topic in the channel settings.
Depending on what format your device expects its commands in you will need to use outgoing transformation which don’t work under openhab 2.4. You would have to install openhab 2.5 M1.
But as I see your are already using nodered, so you could transform/format your command there.

In fact the transformation and formatting is not the goal of my question!
I certainly did not speak well! my question is :
how can i send the correctly formatted text as expected my device i think i have to link a text item and create a rules that will change this text according to some events and thus publish this text on the topic created by Node-red?

Example: (I have to make a big bet!)

String Out_msg “TCPout” {channel = “mqtt:topic:9d027bc0:TCPout”}


Depending on what kind of string you want to send it might be easiest to use the publish action which is included in the mqtt binding.
With this you can publish anything to a specified topic from a rule, just use this in the than part of your rule:

   val actions = getActions("mqtt","mqtt:broker:yourBrokerThing")