How to assign more than one MQTT Message to a Channel

Tags: #<Tag:0x00007f6174a09290> #<Tag:0x00007f6174a09010>

I am using a Tasmota device with a lot of inputs which i want to use in openHAB.This works in general with openHAB2.5 and MQTT 2.5.1.

The Tasmota device sends a MQTT-Message
stat/RESULT = {“Time”:“2020-06-29T12:55:39”,“MCP230XX_INT”:{“D0”:0,“MS”:1305604}} or
stat/RESULT = {“Time”:“2020-06-29T12:56:07”,“MCP230XX_INT”:{“D0”:1,“MS”:28480}}

when the status of the input changes.

Every 5 minutes It also sends a
tele/SENSOR = {“Time”:“2020-06-29T12:54:02”,“MCP230XX”:{“D0”:1,“D1”:1,“D2”:1,“D3”:1,“D4”:1,“D5”:1,“D6”:1,“D7”:1,“D8”:0,“D9”:0,“D10”:0,“D11”:0,“D12”:0,“D13”:0,“D14”:0,“D15”:0}}
message which includes the stati of all inputs.

So i defined in a .things file:

Thing mqtt:topic:Homeio "Home IO" (mqtt:broker:myMqttBroker)  {
    Channels:
    Type switch : In0 "Home IO In 0"      [ stateTopic="tele/SENSOR", transformationPattern="JSONPATH:$.MCP230XX.D0", on="0", off="1" ]
   
    Type switch : In0 "Home IO In 0"      [ stateTopic="stat/RESULT", transformationPattern="JSONPATH:$.MCP230XX_INT.D0", on="0", off="1" ]

}

I want to use the two different message-types to set the status of the item, because if an stat/RESULT message gets lost the staus should be set at least every 5 Minutes from the tele/SENSOR message.

and in my .items file:

Switch   OG1_Homeio_in0	     "Test Taster 0"    ( G_HOMEIO ) { channel="mqtt:topic:Homeio:In0" }

But it does not work as expected. Only the stat/RESULT message sets the item. I don’t know the right method to set the item from two different MQTT-Messages.

Has anyone an idea?

Michi

You must give your channels different, unique names. In0A and In0B perhaps. Then you can link two channels to one Item

But how to link two channels to one item?

Switch   OG1_Homeio_in0	     "Test Taster 0"    ( G_HOMEIO ) { channel="mqtt:topic:Homeio:In0", channel="mqtt:topic:Homeio:In1" }

Separate the channels with a comma. Note that I just made up that second channel - it depends on what you decide to name it!

really easy solution (if you know how to…). It works perfectly now.

Thanks a lot

It was a hidden feature to me too until not long ago.

It’s way down the page in the docs

2 Likes