OpenHAB3 http binding + jsonpath

  • Platform information:
    • Hardware: VM, 2 core CPU, 2 GB RAM
    • OS: Debian 10.7
    • Java Runtime Environment:11.0.9.1
    • openHAB version: 3.0.0
  • Issue of the topic: old 2.5 config didn’t work with 3.0

I have a device that returns a json string:
{“Distanz”:68.50,“Heizung_Vorlauf”:37.94,“Heizung_Ruecklauf”:33.81,“Heizungskeller”:17.12}

In v2.5 I configured a http item
[http.cfg]
waterbox.url=http://192.168.168.24/json
waterbox.updateInterval=20000

[http.items]
Number Distanz “Fuellstand [%d %%]” { http="<[waterbox:60000:JSONPATH($.Distanz)]" }

JSONPath Transformation is installed.
Everything worked fine with Version 2.5
grafik

I tried the same configuration in version 3.0, installed the JSONPath Transformation and see the item in the List.
But it didn’t return a value. No error message in the logs.

any hints ?

greetings,
Juergen

You are using the V1 HTTP binding configuration, but the V1 binding does not work and is not shipped with openHAB 3.

See here for the new binding information:

Hi,
thanks, but can you help me with this item ?
maybe an example.

regards
Jürgen

Unfortunately I cannot, as I don’t use the binding. Here is the forum thread for development of the binding. It’s long, but has some examples:

However, you will be encouraged to use the new MainUI to configure your Thing, as this should be less error prone.

1 Like

Please try in the Main UI

After installing the binding goto thing
Add new thing (blue + bottom right corner)
HTTP Url Thing

Then you will have to create a channel and item.

Hi and thank you,
ok I created the Thing, added a channel and linked it to an item.

UID: http:url:e7b04a55b1
label: Waterbox URL Thing
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: http://192.168.168.24/json
refresh: 60000
commandMethod: GET
timeout: 3000
bufferSize: 512
location: Keller
channels:

  • id: pegel001
    channelTypeUID: http:string
    label: waterlevel
    description: “”
    configuration:
    mode: READONLY
    stateTransformation: JSONPATH:$.Distanz

This works and show a value.
But it doesn’t update the values in my persistance db. (other items are updated and saved)
So i will now try to find the update error.

Regards
Juergen

I glad you got it working. You persist items not thing channels so create an item

Hello,

I glad you got it working. You persist items not thing channels so create an item

maybe you missed it, in my last post I wrote:
ok I created the Thing, added a channel and linked it to an item.
The item is created in the database with a value, but is not updated anymore.

regards
Juergen

Yep I missed it was late. your channel refresh is 60000 so It should update a couple of times a day. Try setting it lower

Hi,
60000 means every minute. Should be possible. Anyway I changed the variable - nothing.
The only update in the db is after save the config (thing).
So for me it’s currently not working. Maybe someone should try a http config and test it.

update:
The value refresh (Item -> Refresh time) is given in seconds not ms
the value 600 = 10 minutes

UID: http:url:e7b04a55b1
label: Waterbox URL Thing
thingTypeUID: http:url

refresh: 600
commandMethod: GET
timeout: 3000
bufferSize: 512

HAB_Thing

now I’ve got an update every 10 minutes:
HAB_db

regards
Juergen

1 Like

I just tried something similar but sadly my value stays NULL :-/

The thing:

The channel:

UID: http:url:PoolTemp
label: PoolTemp
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: true
baseURL: http://www.myurl.net/data/report/temperatur.json
refresh: 30
commandMethod: GET
contentType: application/json
timeout: 3000
bufferSize: 2048
channels:

  • id: PoolTemp
    channelTypeUID: http:string
    label: PoolTemp
    description: “”
    configuration:
    mode: READONLY
    stateTransformation: JSONPATH:$.pooltemp

The json content:

{“pooltemp”:“24.8”}

Of course myurl is my url :wink:
Where is my mistake?

Did you already install JSONPATH Transformation?

4 Likes

Thanks! That indeed was my mistake.

Once again I am stuck at this, I got another json pulled from my server containing the data of my heating:

{"energie":"0331666","volumen":"0737536","stunden":"0142377","tempin":"0007432","tempout":"0002891","tempdiff":"0004541","mpower":"000016","zusatz1":"000030","zusatz2":"0000247","zusatz3":"0000000","zeitstempel":"2022-07-31 02:24:57"}

Now I got two items, actually one should get the “energie” and the other one the “volumen” however second stays UNDEF even if I set it to “energie” just like the other one. Why is that?

Please delete JSONPATH: from the Profile Configuration (JSONPATH Expression).

Thanks Udo, this didn´t change it though I guess it was wrong anyway. However I found out that I missed the state transformation in the channel configuration and set it to JSONPATH:$.volumen. This works, I guess I´ll never understand the logic at all. :wink:

If looking at incomming data, there are some options to setup JSONPATH.

  1. Data is received by a Binding (here http) through a channel.
    a) use a channel for each bit of information, so e.g. use a number channel and provide JSONPATH to extract one Number to the Channel
    b) use a string Channel to get the whole JSON Object.
  2. Channel ist linked to an Item
    a) 1.a): As there is a simple Number, you can’t use JSONPATH anymore.
    b) 1.b): The String channel provides the whole JSON Object, so now you can extract Data in the link.
    This is useful if there are many informations from the same JSON Object to be extracted. You will only need one Channel per JSON Object and just link as many Items to this Channel as you need.
    Item Type is not limited to String but to the Type of data which is extracted.
    c) You can even use a String Item to get the whole JSON Object.
  3. Item state
    When not providing the whole JSON Object through a String Item 3.c), you simply can’t use JSONPATH.
    If you are using a String Item with the whole JSON Object, you can use JSONPATH within the display Options and/or you can use transformation action within a rule.

So, there are three possible options to use JSONPATH, but you can only use it at one position.

To be honest, it would be nice to exclude transformation Services when it makes no sense to use them (e.g. channel is not of type string, so there can’t be a JSON Object), but it adds a lot more of complexity, so I guess the developers chose not to do so…