[SOLVED] Problem with Jsonpath in combination with mqtt

Good day,

I have a problem with jsonpath and mqtt. I would like my 3D printer’s data to be sent to OpenHab using Octoprint via mqtt. Unfortunately I can’t get Jsonpath to run. The data from Octoprint arrives without any problems via mqtt. Here is some information about my installation: I have version 2.4.0.002 of Openhab running on a Synology Diskstation. As a Mqtt broker I use Mosquitto, which also runs on the disk station. I’ve been dealing with the problem for a few weeks now. Unfortunately, the documentation helped me with another tutorial. The data from the printer arrives without any problems if I have it output as a string and do not use JsonPath. As soon as I try to use Jsonpath, nothing is printed (I installed the jsonpath binding). This is my item definition:

Number Temp_Bed “Temperatur Druckbett [%. 1f ° C]” {mqtt = “<[broker: octoprint / temperature / bed: state: JSONPATH ($. actual)]”}

I get the following Error: 2019-12-28 12:04:40.362 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Convert JSON to Item Type Number’: The name ‘Temperature’ cannot be resolved to an item or type; line 9, column 5, length 11

If you need more information please write again, because this is my first post, I do not know what information is helpful.

Thank you

Can you post the JSON?

Also it seems that you have extra spaces in there:

Number Temp_Bed "Temperatur Druckbett [%. 1f ° C]" { mqtt="<[broker:octoprint/temperature/bed:state:JSONPATH($.actual)]" }

The binding parser is picky. and for JSONPATH, ($. actual) is different than ($.actual)

Can I ask why are you not using the MQTTv2 binding?

Thank you for your prompt reply. The space comes from copy paste. I watched some tutorials on how to do it using text definition. I use the mqtt 2.x binding. I tried PaperUI too, but I don’t know what Jsonpath should look like here in my case. And unfortunately I have not found any instructions that could really help me.

This is the string sent by Octoprint: {"_timestamp": 175291, “actual”: 42.7, “target”: 60.0}

You looked at old tutorials. Your Item binding configuration with mqtt= is for version 1.x binding. It will not work with MQTT binding version 2.x, which uses Things and channels for configuring.

OK. Thanks I find that with the 1.x and 2.x a bit confusing.

The error you are showing us comes from a rule of yours, and has no direct link to your Item. Maybe it would work if the Item got a value, of course.

With the the correct thing/channel set up, you should not need a rule to get a Number from your JSON.

The rule has survived from a tutorial and was only a test on my part. I thought it should work (can’t because of 2.x binding). I now need the right JsonPath for the definition via PaperUI? Unfortunately I don’t know how it should look like. On the Internet, I simply don’t find anything on this topic that helps me.

You can configure your channel with either PaperUI or with xxx.things files. I would advise sticking with one method or the other for each binding for the sake of sanity.

Searching this forum for Mqtt and jsonpath will give you lots of results. You can choose to see more recent ones.
Remember, mqtt= is old v1, things+channels is new v2

I have now solved the problem. The hint that the text definition didn’t work was very helpful. So I specifically looked for instructions on how to set it up using PaperUI. I found some forum posts on this topic and was able to solve the problem. Thank you for your support.