OH3 Generic MQTT Thing Item linking problem

Hi,

could someone take me by the hand and give me an example how to add a specific MQTT item in OH 3?
I already created the MQTT Thing, but I have problem to link an item now. That´s what I have in the “home.items” file in OH2:

Number  Pow2EnergyMon "Energieverbrauch Trockner [%.1f W]"	<line>    (gBM, gMyOpenHAB)   {mqtt="<[mysensor:tele/sonoff/trockner/SENSOR:state:JSONPATH($.ENERGY.Power)]"}    

The data is like that:

{"Time":"2020-12-31T11:32:48","ENERGY":{"Total":438.436,"Yesterday":0.785,"Today":0.171,"Period":39,"Power":469,"Factor":0.93,"Voltage":234,"Current":2.147}}

Thanks in advance!

What’s the configuration of your Thing and its Channel? Can you show us the YAML from the Code tab of the Thing?

Sure:

UID: mqtt:topic:broker:Trockner
label: Trockner
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
availabilityTopic: tele/sonoff/trockner/LWT
 payloadAvailable: online
bridgeUID: mqtt:broker:broker
location: Waschküche
channels:
  - id: TrocknerVerbrauch
    channelTypeUID: mqtt:number
label: Energy
description: ""
configuration:
  stateTopic: tele/sonoff/trockner/STATE

So with these settings the thing is shown as “online” at least…

This is old syntax for MQTT binding version 1 you have found from somewhere, get rid of it.

If you are creating a Thing, you should also create channel(s).
You link your Item to a channel.

Number  Pow2EnergyMon "Energieverbrauch Trockner [%.1f W]"	<line>    (gBM, gMyOpenHAB)   {channel="mqtt:topic:broker:Trockner:TrocknerVerbrauch"} 

Yes Sir, that´s what I´m trying to achieve. I can only tell the expression above has worked…

I don´t get it how to link the item now. How can I tell the linked item to only extract e.g. the “Uptime” data from the dataset?

You don’t do that at the Item level. The Item only has a link to the Thing Channel. Within the Thing Channel you do your transformation.

If you defined the Channel via the UI just add

JSONPATH:$.ENERGY.Power

into the appropriate Transformation field. Or, add

transformationPattern: JSONPATH:$.ENERGY.Power

below stateTopic in your YAML, appropriately indented!

1 Like

You don’t. This is the job of the channel that you must create as part of your MQTT Thing configuration. You may have several channels, extracting different bits of data.
Later, you link the channel to your Item.

This is a generic “how do I configure MQTT v2 binding” question.

If that means “I used to use MQTT v1” -
you might find this useful

1 Like

Thank you guys, with your help I made it work now!!

Happy New Year!