JSONPATH-transformation failed

I had a working thing with three channels each extracting a temperature from an mqtt string. It was displaying the three temperatures without issue for a few hours then when I check later all values just showed a hyphen.
The following is an extract from the log.

Executing the JSONPATH-transformation failed: Invalid path '$.3C01A8160EFB.Temperature' in '{"Time":"2020-06-20T13:35:52","DS18B20_1":{"Id":"3C01A8160EFB","Temperature":34.4},"DS18B20_2":{"Id":"3C01A8162221","Temperature":28.3},"DS18B20_3":{"Id":"51D7FD1D64FF","Temperature":35.5},"TempUnit":"C"}'

I can’t see where the problem is, I’ve reinstalled the JSONpath transformation and restarted openhab but it’s still giving the error. I did add a new thing and item but it was still working after that. No other things have a JSON transformation. Since then I’ve removed the new thing and item and restarted openhab but I’m still getting the error.

Hi Lester, you’re having a mare with these sensors!

Your transformationPattern should look something like:

$.DS18B20_1.Temperature

The ID attribute is nested at the same level as the temperature attribute - the ID attribute doesn’t have a temperature attribute.

Nothing changed at the sensor end? An explanation is that the format of the JSON string has somehow changed…

Hi Lester

Maybe openhab can’t see the sensor any more

What controller you got the sensors plugged into

If it’s a D1 mini with Tasmota firmware you can see the temperatures of sensors on main screen?
If can’t see them maybe loose connection?

Maybe a reboot may help?

Yet it was working.
I’ve now changed the

$.3C01A8162221.Temperature

back to

 $.DS18B20_2.Temperature

and saved it but the log still shows it is looking for

$.3C01A8162221.Temperature

I’m using Visual Studio Code to create and edit my scripts and it normally shows any syntax errors but I get the following in my log.

2020-06-20 15:21:55.458 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'mythings.things', using it anyway:

2020-06-20 15:21:55.471 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mythings.things'

It seems to be ignoring the change. There are 3 things in mythings.things and the others are working fine but they don’t use the JSON transformation.

openhab is seeing the tasmota device with the sensors because that is where it is getting the mqtt string shown in the error log. The device console also shows that it is sending the message every minute.

You’d have to post the entire contents of mythings.things if you want troubleshooting help!

This is mythings.things file.

Bridge mqtt:systemBroker:embedded-mqtt-broker [host="openhab", secure=false] {
Thing mqtt:topic:nodemcu1 "nodemcu1" @ "myHome/Water_Heater"
	{
		Channels:
			Type number : temperature "Temperature" [
				stateTopic="tele/nodemcu1/SENSOR",
				transformationPattern="JSONPATH:$.3C01A8160EFB.Temperature"
				]
			Type number : temperature2 "Temperature2" [
				stateTopic="tele/nodemcu1/SENSOR",
				transformationPattern="JSONPATH:$.DS18B20_2.Temperature"
				]
			Type number : temperature3 "Temperature3" [
				stateTopic="tele/nodemcu1/SENSOR",
				transformationPattern="JSONPATH:$.51D7FD1D64FF.Temperature"
				]
	}
Thing mqtt:topic:sonoffs26_1 "SonoffS26_1" @ "myHome/Living_Room"
	{
		Channels:
			Type switch : power "S26_1 On/Off" [ 
				stateTopic="stat/sonoffs26_1/POWER",
                commandTopic="cmnd/sonoffs26_1/POWER",
				on="ON",
				off="OFF"
				]
	}
Thing mqtt:topic:sonoffs26_2 "SonoffS26_2" @ "myHome/Living_Room" 
	{
		Channels:
			Type switch : power "S26_2 On/Off" [ 
				stateTopic="stat/sonoffs26_2/POWER",
                commandTopic="cmnd/sonoffs26_2/POWER",
				on="ON",
				off="OFF"
				]
	}
}

Visual Studio Code doesn’t show any errors.

Hi

Have you changed anything like typing sensor ID wrong .

Nothing to do with Setoption64 ?

I’m just a beginner here

Nothing was changed from when it was working until it wasn’t.
The fact that I have now changed from the id (3C01A8162221) to name (DS18B20_2) and saved the file but openhab is still looking for the id I think is the clue.
openhab isn’t seeing the change in the things file or that section of the things file.

Hi

Not sure how you do it ,Google be your friend

Maybe clean the openhab2 cache?

What version of OpenHAB are you using? Earlier versions required a complete restart after changing a things file. This was only fixed ‘relatively’ recently…

(Also, a small note: the embedded MQTT broker will go away in future versions of OpenHAB. At this stage I would take the opportunity to move to stand-alone MQTT broker, such as Mosquitto)

OK. I’ve tried swapping id and name back and forth with a reboot each time I make a change and it appears that it doesn’t work with id. I would swear the values changed when I first swapped to id but perhaps I saved the changes but didn’t restart openhab so it was still using the name.
If that is the case, what is the transformation needed to extract the Temperature from the following string based on id?

'{"Time":"2020-06-20T16:30:11","DS18B20_1":{"Id":"3C01A8160EFB","Temperature":31.9},"DS18B20_2":{"Id":"3C01A8162221","Temperature":27.5},"DS18B20_3":{"Id":"51D7FD1D64FF","Temperature":38.0},"TempUnit":"C"}'

Unless I really misunderstand JSON, you can’t extract the temperature based on the ID attribute - they are not related other than being at the same level. You can visualise the levels like so:

{
	"Time": "2020-06-20T13:35:52",
	"DS18B20_1": {
		"Id": "3C01A8160EFB",
		"Temperature": 34.4
	},
	"DS18B20_2": {
		"Id": "3C01A8162221",
		"Temperature": 28.3
	},
	"DS18B20_3": {
		"Id": "51D7FD1D64FF",
		"Temperature": 35.5
	},
	"TempUnit": "C"
}

As you can see, DS18B20_1 is the ‘name’ of a group of attributes, which are Id and Temperature. Using transformationPattern to extract temperature, you need:

$.DS18B20_1.Temperature

To be clear, you can’t extract Temperature using Id.

EDIT:
To perhaps give you more to work with, see my thing below. This is a Sonoff Basic switch with a DHT22 sensor attached, flashed with Tasmota. My MQTT broker is Mosquitto, which I have defined in a separate things file and is referenced in the (mqtt:broker:MosquittoMqttBroker) part of the thing definition.

    // Switch Bedroom Desk Light
	Thing mqtt:topic:swBedroomDeskLight "Switch Bedroom Desk Light" (mqtt:broker:MosquittoMqttBroker) {
		Channels:
			Type switch : switch "Power Switch" [ 
				stateTopic="stat/swBedroomDeskLight/POWER", 
				commandTopic="cmnd/swBedroomDeskLight/POWER",
				on="ON",
				off="OFF"          
			]
			Type switch : reachable "Reachable" [
				stateTopic = "tele/swBedroomDeskLight/LWT",
				on="Online",
				off="Offline"
			]
			Type number : temperature "Temperature" [ 
				stateTopic="tele/swBedroomDeskLight/SENSOR",
				transformationPattern="JSONPATH:$.AM2301.Temperature"
			]
			Type number : humidity "Humidity" [ 
				stateTopic="tele/swBedroomDeskLight/SENSOR",
				transformationPattern="JSONPATH:$.AM2301.Humidity"
			]
			Type string : tempunit "TempUnit" [ 
				stateTopic="tele/swBedroomDeskLight/SENSOR",
				transformationPattern="JSONPATH:$.TempUnit"
			]
			Type switch:state "State" [
				stateTopic="tele/swBedroomDeskLight/STATE",
				transformationPattern="JSONPATH:$.POWER",
				on="ON",
				off="OFF"
			]
	}

The JSON string received on tele/swBedroomDeskLight/SENSOR looks very similar to yours:

{"Time":"2020-06-20T07:43:44","AM2301":{"Temperature":21.1,"Humidity":65.1},"TempUnit":"C"}

Because Temperature is within the group AM2301, my transformationPattern is:

JSONPATH:$.AM2301.Temperature

OK. It’s working again after changing back to names for all 3 sensors and restarting.
I’m worried that if I restart the nodemcu with sensors attached that it may rename them depending on the order in which is sees them.

Can I install Mosquitto in parallel with the embedded broker and change over one at a time to make sure I don’t stuff something else up?

I don’t know the answer to that, unfortunately. I presume the default ports for both brokers is the same, which might cause some issues.

I’ve just updated to openhab 2.5.5-1.
I’ll let you know how I go converting to Mosquitto.
Thanks again for your help.

I deleted my MQTT Broker under Things in PaperUI and uninstalled the MQTT binding then followed an article I found on how to install Mosquitto…
I then went into openhab configuration > optional components and installed Mosquitto. I then went into Things in PaperUI and installed MQTT Broker. In the configuration there is a field for Broker ID.

The thing shows the same as the last one mqtt:systemBroker:embedded-mqtt-broker
image

Configuration of the broker needs a Broker ID.

Do you know what form the Broker ID should take?

So you installed Mosquitto twice? Are you on openhabian? I’m not, so my system may vary…

All I did was install Mosquitto completely separately from openHAB using the instructions on the Mosquitto website.

Then, back in openHAB, I have a single things file with the following:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
	host="192.168.1.92",
	secure=false,
	port=1883,
	qos=0,
	retain=false,
	clientid="OpenHAB2",
	keep_alive_time=30000,
	reconnect_time=60000,
	username="",
	password=""
]

That’s it, I think.

In PaperUI I can then see (under Configuration -> Things):

image

Each thing is then connected to Mosquitto as exampled in JSONPATH-transformation failed

You definitely need to re-install this, though!!

Careful, “System Broker” is not what you want, that is about the embedded moquette broker that you just abandoned.

You want a Bridge Thing under the MQTT binding, pointing to your mosquitto.

It is, by the way, quite common for bindings not to pick up small edits to existing Things in-flight. Generally you only need to restart the binding to enforce new settings, not re-boot, not cache clearing.