siod
(John Doe)
December 31, 2020, 10:36am
1
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?
siod
(John Doe)
December 31, 2020, 10:41am
3
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…
rossko57
(Rossko57)
December 31, 2020, 10:43am
4
siod:
{mqtt="<[mysensor ...
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"}
siod
(John Doe)
December 31, 2020, 10:48am
6
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
rossko57
(Rossko57)
December 31, 2020, 10:51am
8
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
I’ve got a smoke detector that could send out something (via PAI) on an open topic or fire topic. Under V1 Mqtt I do this with:
Contact alarm_smoke_computer "Computer Smoke State [%s]" <fire> (g_smoke_detection)
{ mqtt="<[openhab:paradox/states/zones/Smoke_computer/open:state:MAP(onoff.map)],
<[openhab:paradox/states/zones/Smoke_computer/fire:state:MAP(onoff.map)]"}
What woulc be the equivalent thing defintion for the v2 binding? I’ve currently got open state:
Ty…
1 Like
siod
(John Doe)
December 31, 2020, 10:58am
9
Thank you guys, with your help I made it work now!!
Happy New Year!