MQTT manual config, confusion and issues

  • Platform information:

    • Hardware: Raspberry Pi 4 (4gb)
    • OS: raspbian 4.19.75-v7l+
    • Java Runtime Environment: Zulu8.40.0.178-CA-linux_aarch32hf
    • openHAB version: 2.5.1~20200109043448-1, snapshot
  • Issue of the topic: Im trying to get my PC metrics into openhab thru MQTT, using iotlink on my windows 10 pc to publish the metrics and MQTT Dashboard on my phone as a debug-client (to verify successfully published metrics).

…the “metrics” are CPU usage, current user, uptime and so on…

The mosquitto MQTT server is running(on my pi) and working, my phone can see my pc´s metrics.

But i cant seem to figure out how to get these metrics onto openHAB, where to add the channels for each “function” and so on…

Ive tried adding the MQTT broker via paperUI unsuccessfully, so i removed everything and added the .items/.things-files instead.
I now have a Status: Online in paperUI>configuration>things, but no channels.
So how and where would i input my different channels in the manual config files?

minMQTT-bridge.things

Bridge mqtt:broker:minMQTT "MQTT Broker: minMQTT Mosquitto"
[
    host="127.0.0.1",
    port=1883,
    secure="AUTO",
    username="redacted",
    password="redacted"
]

minMQTT_blackbox.things

Thing mqtt:topic:minMQTT:mqtt_BlackBox  "MQTT Thing: BlackBoxData"
     (mqtt:broker:minMQTT) @ "TV-möbeln"
{
    Channels:
        Type string : uptime "uptime"
            [
                upTime= "iotlink/workgroup/blackbox/windows-monitor/stats/system/uptime",

            ]
        Type string : currentUser "currentUser"
            [
                currentUser= "iotlink/workgroups/blackbox/windows-monitor/stats/system/current-user",

            ]
}

minMQTT_blackbox.items

String mqtt_BlackBox_uptime "BlackBox Uptime [%s]"
(gMQTT, gmqtt_BlackBox)
{
    BlackBox_uptime = "mqtt:broker:minMQTT:mqtt_BlackBox:uptime"
    BlackBox_currentUser = "mqtt:broker:minMQTT:mqtt_BlackBox:currentUser"
}

It’s recommended to use PaperUI to create the Thing and place items in files. From PaperUI things copy the item description and place in item file. I’m hard headed and use files for all so here is my example.

Item file:

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

Things file:

Bridge mqtt:broker:pibroker "pibroker" [ host="10.0.1.19", port=1883, secure=false, username="xxxxxx", password="xxxxxx" ]
{
    // Sonoffs
    Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }
}
2 Likes

Hi and thank you very much for your assistance!

However, after modifying my things-file to match yours, my MQTT-server is no longer showing up in paperUI>configuration>things…

I removed my earlier things-files, replaced with a single one.
so no more minMQTT-bridge.things or minMQTT-blackbox.things…

Any clues or ideas?

minMQTT.things

Bridge mqtt:broker:minMQTT "MQTT Broker: minMQTT Mosquitto" [ host="127.0.0.1", port=1883, secure="AUTO", username="redacted", password="redacted" ]
{
    Thing topic blackbox_metrics "BlackBox Metrics" @ "TV-möbeln"
    Channels:
        Type String : uptime "uptime" [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/uptime"]
        Type String : currentUser "currentUser" [ stateTopic= "iotlink/workgroups/blackbox/windows-monitor/stats/system/current-user" ]
}

What does openhab.log have to say about loading your new things file?
What does openhab.log have to say about connecting to your broker?

What mqtt broker are you using and the logs as rossko57 mentioned.

Im using Mosquitto and its verified as working, i can publish info from my pc and read it on my android phone.

The logfile says:
2020-01-10 17:53:16.786 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘minMQTT.things’ has errors, therefore ignoring it: [5,14]: mismatched input ‘String’ expecting RULE_ID
[6,14]: mismatched input ‘String’ expecting RULE_ID

and a whole lot of:

2020-01-10 20:44:25.582 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to ‘192.168.1.10’. Next attempt in 60000ms
2020-01-10 20:44:25.589 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.10’ with clientid 7fd5025e-898c-4ebd-87f6-b632cc7d2a65

my current .things file:

Bridge mqtt:broker:minMQTT "MQTT Broker: minMQTT Mosquitto" [ host="127.0.0.1", port=1883, secure="AUTO", username="redacted", password="redacted" ]
{
    Thing topic blackbox_metrics "BlackBox Metrics" @ "TV-möbeln"
    Channels:
        Type String : uptime "uptime" [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/uptime"]
        Type String : currentUser "currentUser" [ stateTopic= "iotlink/workgroups/blackbox/windows-monitor/stats/system/current-user" ]
}

Seems important. Are you going to fix it?
If you look at other peoples examples of Thing topic ... there are curly braces involved for the Channels: section.
An example -

2 Likes

i did add those curly brackets i was missing, but i also noticed that the “string” data-type is lowercase in things.

So i changed those too and now its actually “working”, i had to manually link my mqtt-thing to items from the paperUI things page, but the control-page in paperui is showing my PC metrics.

But i think i need to fix the issue with the linkage, how do i link the .items and .things?

Every time i change the things-file, my linked items gets removed from my thing, forcing me to manually link them again in the PaperUI…

edit: i solved the linkage!
minMQTT.items:

String BlackBox_uptime "BlackBox Uptime [%s]" { Channel="mqtt:broker:minMQTT:blackbox_metrics:BlackBox_uptime" }

minMQTT.things:

Bridge mqtt:broker:minMQTT "MQTT Broker: minMQTT Mosquitto" [ host="127.0.0.1", port=1883, secure="AUTO", username="redacted", password="redacted" ]
{
    Thing topic blackbox_metrics "BlackBox Metrics" @ "TV-möbeln" {
    Channels:
        Type string : BlackBox_uptime "uptime" [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/uptime"]
        Type string : BlackBox_currentUser "current User" [ stateTopic= "iotlink/workgroups/blackbox/windows-monitor/stats/system/current-user" ]
        Type string : BlackBox_cpu_used "CPU usage" [ stateTopic= "iotlink/workgroups/blackbox/windows-monitor/stats/cpu/usage" ]
	}
}

edit2: its NOT solved, linkage still gets deleted when .things-file gets updated…

But earlier you showed us your Items with channels defined in Items files.
You cannot use both methods to link,
If an Item is defined in an xxx.items file, there must also link using {channel= } format.
If you created your Item in PaperUI, there you make the link.
Mixing will not work.

thanks for the input rossko57, im sincerely grateful for all the help im getting!

However, ive been at this for days now and im simply not understanding the finer details here…
But i do belive i AM using the channel= format, but im probably linking to the wrong item…

minMQTT.items:

 String BlackBox_uptime "BlackBox Uptime [%s]" { Channel="mqtt:broker:minMQTT:blackbox_metrics:BlackBoxUptime" }
String BlackBox_currentUser "BlackBox Current User" { Channel="mqtt:broker:minMQTT:blackbox_metrics:BlackBoxCurrentUser" }
String BlackBox_cpu_used "BlackBox CPU Usage" { Channel="mqtt:broker:minMQTT:blackbox_metrics:BlackBoxCPUused" }
String BlackBox_idle_time "BlackBox Idle Time" { Channel="mqtt:broker:minMQTT:blackbox_metrics:BlackBoxIdleTime" }

Look in your PaperUI and determine if that is really the channel uid (“name”).
With many changes in both configuration systems you might well have ended up with duplicate broker Things, etc.
If you think you are now close to the right setup, stop openHAB and restart it, to get rid of old rubbish,
What do the logs say about the linking?

1 Like

Heh… My channel name was actually mqtt:topic:minMQTT:blackbox_metrics:BlackBoxUptime

I changed the config file and rebooted the pi server but its hard to know if it did anything…
I didnt have any duplicates in paperUI, but i do have 2 mqtt-things, one broker (the server) and one generic thing (the pc metrics)

Yes, having defined a Broker Thing and a Topic Thing, you might expect to see two Things in PaperUI. So far, so good.

So, does it work?

well, its not quite working properly yet…
My previously added items are now all showing up in the paperUI>control page, even showing correct data! :smiley:

I tried to add more metrics details (harddrive info) in the config files, but it doesnt show up on the paper ui.
The paperUI>configuration>things>blackbox metrics lists all the new channels but none of the new .things entries have any links.

The paperUI>configuration>items lists all the new channel items aswell (the thing link targets), so appearantly i am still not linking thing>item properly in the config files…

minMQTT.things:

Bridge mqtt:broker:minMQTT "MQTT Broker: minMQTT Mosquitto" [ host="127.0.0.1", port=1883, secure="AUTO", username="redacted", password="redacted" ]
{
    Thing topic blackbox_metrics "BlackBox Metrics" @ "TV-möbeln" {
    Channels:
        Type string : BlackBoxUptime "uptime" 		 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/uptime"]
        Type string : BlackBoxCurrentUser "current User" [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/current-user" ]
        Type string : BlackBoxCPUused "CPU usage"  	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/cpu/usage" ]
        Type string : BlackBoxIdleTime "idle time" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/system/idle-time" ]
	
	
        Type string : BlackBoxDisk1Name  "disk1Name" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/c/volume-label" ]
	Type string : BlackBoxDisk1Free  "disk1Free" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/c/available-free-space" ]
        Type string : BlackBoxDisk2Name  "disk2Name" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/d/volume-label" ]
	Type string : BlackBoxDisk2Free  "disk2Free" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/d/available-free-space" ]
        Type string : BlackBoxDisk3Name  "disk3Name" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/e/volume-label" ]
	Type string : BlackBoxDisk3Free  "disk3Free" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/e/available-free-space" ]
        Type string : BlackBoxDisk4Name  "disk4Name" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/m/volume-label" ]
	Type string : BlackBoxDisk4Free  "disk4Free" 	 [ stateTopic= "iotlink/workgroup/blackbox/windows-monitor/stats/hard-drive/m/available-free-space" ]
	}
}

minMQTT.items:

String BlackBox_uptime "BlackBox Uptime [%s]" 		{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxUptime" }
String BlackBox_currentUser "BlackBox Current User" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxCurrentUser" }
String BlackBox_cpu_used "BlackBox CPU Usage"  		{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxCPUused" }
String BlackBox_idle_time "BlackBox Idle Time" 		{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxIdleTime" }


String BlackBox_Disk1_Name "BlackBox disk1 Name" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk1Name" }
String BlackBox_Disk1_Free "BlackBox disk1 Free" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk1Free" }
String BlackBox_Disk2_Name "BlackBox disk2 Name" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk2Name" }
String BlackBox_Disk2_Free "BlackBox disk2 Free" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk2Free" }
String BlackBox_Disk3_Name "BlackBox disk3 Name" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk3Name" }
String BlackBox_Disk3_Free "BlackBox disk3 Free" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk3Free" }
String BlackBox_Disk4_Name "BlackBox disk4 Name" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk4Name" }
String BlackBox_Disk4_Free "BlackBox disk4 Free" 	{ Channel="mqtt:topic:minMQTT:blackbox_metrics:BlackBoxDisk4Free" }

PaperUI does not play very nice with stuff defined in files. It was never designed to be compatible, and it’s all rather hit and miss and inconsistent.

Which is to say, don’t rely on PaperUI for xxx.items file defined Items.
You can use REST API to interrogate Items directly, you can see if Items get changed in your events.log, you can see when configuration errors get grumbled about in openhab.log, you can display information in the user facing UIs.
Learn to use all the tools to get all the clues.

Well, i havent a clue what REST is, API suggests a programming interface and that means i´ll learn to live without it… :slight_smile:

I guess i´ll have to manually link the things > items in the paperUI for all my MQTT topics…
Its not the end of the world, hopefully i´ll only set it once. :slight_smile:

Please yourself, this stuff is not simple and does require effort on your part.

I know, and im sorry if i came across as a buffoon, that was not my intention.

Im just a “tiny” bit frustrated over the fact that im not getting it to work even tho im working HARD trying to learn…

At any rate, i am sincerely grateful for your assistance, kudos to you for your effort! :smiley:

That’s what the heart icon on each post is for. :wink:

While reading through all the topics on the forum if you come across one that helps you can show your appreciation by giving it a like. This lets the person know that their time and effort was helpful and your grateful. :smiley:

1 Like

thank you for that nugget of wisdom! :slight_smile: i´ll make sure to use it! :heart:

1 Like