[SOLVED] JSONpath doesn't have enough parameters?

I am having an issue parsing my sensor data from an ESP8266. The documentation is not much help (or i’m looking in the wrong direction). So I’d love to hear your views. I made this config by using [SOLVED] MQTT item parsing as an example.

The JSON string published to MQTT looks like this, with the “esp8266_25” part being the MQTT topic:

esp8266_25 {"Humidity":37.70,"Temperature":26.30}

.items entry according to example:

String GreenhouseTemperatureSensor "Temperature: [%s]" (Greenhouses) {mqtt="<[mqtt:/esp8266_25:state:default:JSONPATH($.svalue1):.*\"Temperature:\".*]"}

.sitemap entry

Text item=GreenhouseTemperatureSensor label="[%s]" valuecolor=[>25="orange",>15="green",<=15="blue"]

but Openhab gives me the following error in the log:

ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'GreenhouseTemperatureSensor' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mqtt:/esp8266_25:state:default:JSONPATH($.Temperature):."Temperature:".' is not a valid inbound configuration: Configuration requires 4 or 5 parameters separated by ':'
	at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[191:org.openhab.core.compat1x:2.1.0.201705081517]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:326)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:298)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:184)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:360)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:244)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:315)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:211)[99:org.eclipse.smarthome.core:0.9.0.201705081821]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]

It returns a string in my sitemap when I change the .items entry to

String GreenhouseTemperatureSensor "Temperature: [%s]" (Greenhouses) {mqtt="<[mqtt:/esp8266_25:state:default]"}

so which parameter am I missing?

Thanks in advance for your replies! :slight_smile:

EDIT: Found out the default state should be replaced by the JSONPATH function, giving this

String GreenhouseTemperatureSensor "Temperature: [%s]" (Greenhouses) {mqtt="<[mqtt:/esp8266_25:state:JSONPATH($.Temperature)]"}

It now functions as it should :slight_smile:

changing the .items entry to

String GreenhouseTemperatureSensor "Temperature: [%s]" (Greenhouses) {mqtt="<[mqtt:/esp8266_25:state:default:JSONPATH($.Temperature):.\d.]"}

changes my log error to

[ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'GreenhouseTemperatureSensor' for widget org.eclipse.smarthome.model.sitemap.Text

it shows three times in a row (why? I don’t know)

the weird thing is, according to my logic and results from the JSONPath expression tester, I should be able to retrieve the value without the regular expression…

But when I negate setting the 5th parameter as such:

String GreenhouseTemperatureSensor "Temperature: [%s]"  (Greenhouses)   { mqtt="<[mqtt:/esp8266_25:state:default:JSONPATH($.Temperature)]" }

It does not show any new log entries.

This entry does, but it just keeps throwing me the 4 or 5 parameters error again -_________-

String GreenhouseTemperatureSensor "Temperature: [%s]"  (Greenhouses)   { mqtt="<[mqtt:/esp8266_25:state:default:JSONPATH($.Temperature):*]" }

Shouldn’t that be:
String GreenhouseTemperatureSensor “Temperature: [%s]” (Greenhouses) {mqtt=“<[mqtt:/esp8266_25:state:default:JSONPATH($.svalue1):.*"Temperature":.*]”}

Well I gave it a go, but I believe the ‘.’ is used to concatenate the last parameter (the one being set from the regex), so I’d imagine there not be a need for the last ‘:’, as this is my last parameter.

It still gives

[ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'GreenhouseTemperatureSensor' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mqtt:/esp8266_25:state:default:JSONPATH($.svalue1):.*"Temperature":.*' is not a valid inbound configuration: Configuration requires 4 or 5 parameters separated by ':'
	at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[191:org.openhab.core.compat1x:2.1.0.201705081517]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:326)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:298)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:184)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:360)[124:org.eclipse.smarthome.model.item:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:244)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:315)[123:org.eclipse.smarthome.model.core:0.9.0.201705081821]
	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:211)[99:org.eclipse.smarthome.core:0.9.0.201705081821]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]

I’ve also tried switching the ‘:.’ to be ‘.:’, but this has the same effect unfortunately

Solution: The state:default should’ve been state:JSONPATH(expression). See the line below, this gives me what I need, just the temperature :smiley:

Everyone who replied, thank you very much!

String GreenhouseTemperatureSensor "Temperature: [%s]" (Greenhouses) {mqtt="<[mqtt:/esp8266_25:state:JSONPATH($.Temperature)]"}