[SOLVED] HTTP-Binding errors from JSONPATH with Cache-Item

I have http-binding installed to get data from a website, to extract several values.

  1. Installed HTTP-binding via Paper-UI.
    2.Activated http.cfg
# timeout in milliseconds for the http requests (optional, defaults to 5000)
timeout=120000

# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
#granularity=

# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
#format=

# configuration of the first cache item
owm_test.url=https://api.openweathermap.org/data/2.5/weather?id=123456&APPID=my-key_1-32&lang=de&units=metric
owm_test.updateInterval=450000

# configuration of the second cache item  
#<id2>.url=
#<id2>.updateInterval=
  1. Created two items
String      Test_1   "Test1"     {http="<[owm_test:450000:JSONPATH($.[1].weather.main.temp)]"}
Number    Test_2     "Test2"     {http="<[owm_test:450000:JSONPATH($.[1].weather.main.pessure)]"}

  1. Tested my Url via Browser and got this
{

    "coord": {
        "lon": 9.xx,
        "lat": 48.yy
    },
    "weather": [
        {
            "id": 800,
            "main": "Clear",
            "description": "clear sky",
            "icon": "01d"
        }
    ],
    "base": "stations",
    "main": {
        "temp": 297.02,
        "pressure": 1020,
        "humidity": 38,
        "temp_min": 296.15,
        "temp_max": 298.15
    },
    "visibility": 10000,
    "wind": {
        "speed": 3.1,
        "deg": 70
    },
    "clouds": {
        "all": 0
    },
    "dt": 1539435000,
    "sys": {
        "type": 1,
        "id": 4891,
        "message": 0.004,
        "country": "DE",
        "sunrise": 1539409104,
        "sunset": 1539448444
    },
    "id": 1234567,
    "name": "Berlin",
    "cod": 200

}

The Logger shows me now:

2018-10-14 01:27:10.173 [INFO ] [smarthome.model.script.weather-rules] -  Forecast executed 
2018-10-14 01:29:07.686 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.[1].weather.main.temp)' threw an exception. [response={"coord":{"lon":9.xx,"lat":48.yy},"weather":[{"id":800,"main":"Clear","description":"Klarer Himmel","icon":"01n"}],"base":"stations","main":{"temp":12.73,"pressure":1017,"humidity":87,"temp_min":11,"temp_max":14},"visibility":10000,"wind":{"speed":2.1,"deg":270},"clouds":{"all":0},"dt":1539471000,"sys":{"type":1,"id":4891,"message":0.0054,"country":"DE","sunrise":1539409142,"sunset":1539448393},"id":1234567,"name":"Berlin","cod":200}]
org.openhab.core.transform.TransformationException: Invalid path '$.[1].weather.main.temp' in '{"coord":{"lon":9.87,"lat":48.89},"weather":[{"id":800,"main":"Clear","description":"Klarer Himmel","icon":"01n"}],"base":"stations","main":{"temp":12.73,"pressure":1017,"humidity":87,"temp_min":11,"temp_max":14},"visibility":10000,"wind":{"speed":2.1,"deg":270},"clouds":{"all":0},"dt":1539471000,"sys":{"type":1,"id":4891,"message":0.0054,"country":"DE","sunrise":1539409142,"sunset":1539448393},"id":1234567,"name":"Berlin","cod":200}'
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [221:org.openhab.binding.http:1.13.0.M4]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [193:org.openhab.core.compat1x:2.4.0.M4]
2018-10-14 01:29:07.696 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.[1].weather.main.pessure)' threw an exception. [response={"coord":{"lon":9.xx,"lat":48yy},"weather":[{"id":800,"main":"Clear","description":"Klarer Himmel","icon":"01n"}],"base":"stations","main":{"temp":12.73,"pressure":1017,"humidity":87,"temp_min":11,"temp_max":14},"visibility":10000,"wind":{"speed":2.1,"deg":270},"clouds":{"all":0},"dt":1539471000,"sys":{"type":1,"id":4891,"message":0.0054,"country":"DE","sunrise":1539409142,"sunset":1539448393},"id":1234567,"name":"Berlin","cod":200}]
org.openhab.core.transform.TransformationException: Invalid path '$.[1].weather.main.pessure' in '{"coord":{"lon":9.87,"lat":48.89},"weather":[{"id":800,"main":"Clear","description":"Klarer Himmel","icon":"01n"}],"base":"stations","main":{"temp":12.73,"pressure":1017,"humidity":87,"temp_min":11,"temp_max":14},"visibility":10000,"wind":{"speed":2.1,"deg":270},"clouds":{"all":0},"dt":1539471000,"sys":{"type":1,"id":4891,"message":0.0054,"country":"DE","sunrise":1539409142,"sunset":1539448393},"id":1234567,"name":"Berlin","cod":200}'
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [221:org.openhab.binding.http:1.13.0.M4]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [193:org.openhab.core.compat1x:2.4.0.M4]
2018-10-14 01:36:38.571 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.[1].weather.main.temp)' threw an exception. [response={"coord":{"lon":9.xx,"lat":48.xx},"weather":[{"id":800,"main":"Clear","description":"Klarer Himmel","icon":"01n"}],"base":"stations","main":{"temp":12.5,"pressure":1017,"humidity":81,"temp_min":11,"temp_max":14},"visibility":10000,"wind":{"speed":0.5},"clouds":{"all":0},"dt":1539472800,"sys":{"type":1,"id":4891,"message":0.0033,"country":"DE","su

Have i forgotten something to set?
Is there someone to help me ?
Thank’s in advance

The jsonpath are incorrect.
You can use www.jsonpath.com to check

String      Test_1   "Test1"     {http="<[owm_test:450000:JSONPATH($.main.temp)]"}
Number    Test_2     "Test2"     {http="<[owm_test:450000:JSONPATH($.main.pressure)]"}

Note that your temperature is in Kelvin!
You can convert easily by using the UoM system:

Item:

Number:Temperature      Test_1   "Test1 [%.1f K]"     {http="<[owm_test:450000:JSONPATH($.main.temp)]"}

Sitemap:

Test item=Test_1 label="Temperature [%.1f °C]"
1 Like

:+1: You’re great !! Done as you described, and it works. Although I have MQTT with Tasmota in Use, I always have to trial and error with JSONPATH. (as one says: most of the time, the mistake is in front of the screen :wink: :joy:).

.
This stuff (java, jsonpath, atomio,flashing, etc…) it’s a new world for me. In my former live, balances, profit-loss and numbers were my daily business.
But with a little help from my friends (as Joe Cocker would have said) the world’s getting better.

Are you sure ?

My api-call is with the parameter metric

One more question: Is there a possibility to see what’s in the cache-item?


A command in the console ? And/Or a logInfo ?

Regards
Peter

Yes 297.02

1 Like

The cache is not an Item!

I think you have to use another Item:

String      Test_3   "Cache"     {http="<[owm_test:450000:REGEX((.*))"}

Sorry Vincent, I forgot to say, when using the api https://api.openweathermap.org/data/2.5/weather?id=1234567&APPID=my_key-1-32&lang=de&units=metric
i get this

{

    "coord": {
        "lon": 9.00,
        "lat": 48.00
    },
    "weather": [
        {
            "id": 800,
            "main": "Clear",
            "description": "Klarer Himmel",
            "icon": "01d"
        }
    ],
    "base": "stations",
    "main": {
        "temp": 24.41,
        "pressure": 1012,
        "humidity": 22,
        "temp_min": 24,
        "temp_max": 25
    },
    "visibility": 10000,
    "wind": {
        "speed": 2.1,
        "deg": 160
    },
    "clouds": {
        "all": 0
				
.........

I found your post to UoM here
https://community.openhab.org/t/list-of-units-in-the-uom-unit-of-measurement/46842/6?u=fibu-freak

and understand what is meant with Number:Temperature Test_1 "Test1 [%.1f K]"
Thanks again

Hi Udo, thanks for your interest helping me. I took this expression <cacheItemName1>.url from the http-binding-documentation.
I will use your suggestion.

EDIT:
Isn’t there a limitation in size ?

Now the Cache is running and i get values from it.

My items are now:

//		Data from openweathermap via http
//		i use this way because regular api-key causes error in the log, when using it with the weather-binding
Number							Temperature_owm						"Temperatur owm [%.1f °C]"														<thermometer_red_earth>			(gYahoo)				{http="<[owm_test:120000:JSONPATH($.main.temp)]"}
//Number							Temp_Feel_owm							"Gefühlte Temperatur owm [%.1f °C]"										<thermometer_red_earth>			(gYahoo)				{http="<[owm_test:120000:JSONPATH($.main.)]"}
Number							Humidity_owm							"Luftfeuchtigkeit owm [%d %%]"												<humidity>									(gYahoo)				{http="<[owm_test:120000:JSONPATH($.main.humidity)]"}
String							CommonId_owm							"Himmel owm [%s]"																			<sun_clouds>								(gYahoo)				{http="<[owm_test:120000:JSONPATH($.weather[0].description)]"}
Number							Clouds_owm								"Bewölkung owm [%.0f %%]"																													(gYahoo)				{http="<[owm_test:120000:JSONPATH($.clouds.all)]"}
Number							Sight_owm									"Sichtweite owm [%.1f m]"															<binoculars1>								(gYahoo)				{http="<[owm_test:120000:JSONPATH($.visibility)]"}
Number:Pressure			Pressure_owm							"Luftdruck owm [%.1f mbar]"														<pressure>									(gYahoo)				{http="<[owm_test:120000:JSONPATH($.main.pressure)]"}

and the http.cfg is

# timeout in milliseconds for the http requests (optional, defaults to 5000)
timeout=60000

# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
#granularity=

# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
#format=

# configuration of the first cache item
owm_test.url=https://api.openweathermap.org/data/2.5/weather?id=1234567&APPID=my api-id_1-32&lang=de&units=metric
owm_test.updateInterval=600000

# configuration of the second cache item  
#<id2>.url=
#<id2>.updateInterval=

and it looks like this:

But from time to time i got now this message in the logger:

2018-10-14 23:09:22.376 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.weather[0].description)' threw an exception. [response={"cod":"500","message":"Internal error: 500001"}]
org.openhab.core.transform.TransformationException: Invalid path '$.weather[0].description' in '{"cod":"500","message":"Internal error: 500001"}'
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [221:org.openhab.binding.http:1.13.0.M4]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [193:org.openhab.core.compat1x:2.4.0.M4]
2018-10-14 23:09:22.388 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.main.humidity)' threw an exception. [response={"cod":"500","message":"Internal error: 500001"}]
org.openhab.core.transform.TransformationException: Invalid path '$.main.humidity' in '{"cod":"500","message":"Internal error: 500001"}'
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [221:org.openhab.binding.http:1.13.0.M4]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [193:org.openhab.core.compat1x:2.4.0.M4]
2018-10-14 23:09:22.396 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.visibility)' threw an exception. [response={"cod":"500","message":"Internal error: 500001"}]
org.openhab.core.transform.TransformationException: Invalid path '$.visibility' in '{"cod":"500","message":"Internal error: 500001"}'
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [221:org.openhab.binding.http:1.13.0.M4]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [193:org.openhab.core.compat1x:2.4.0.M4]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [193:org.openhab.core.compat1x:2.4.0.M4]

any idea ?

Looks like the request returns this json {"cod":"500","message":"Internal error: 500001"}
Then your transformation is throwing an exception for invalid path.

Http error 500:
The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the website’s server, but the server could not be more specific on what the exact problem is.

So… Not your fault. The Http server returns a fault from time to time… As you said

1 Like

:+1: thanks :sweat_smile:
Edit:
Is there a possibility to supress this message ? eg. via log:set ? .
If yes, can you give me the correct binding-name to set ?