[OH3] Cant get data via HTTP + JSON

Good day,
i am in the middle of a OH2->OH3-Migration and struggeling with some HTTP-Get-Commands.

In OH2.5.6 i made a item like this:

String HueMotionSensor001_Name { http=“<[http://IP-ADRESS/api/USERNAME/sensors/3:60000:JS(getHueName.js)]” }

and could resolve the Clear-Name of a Hue Device from my Hue Bridge.
This is just for an example. I have several items like this.

Since OH3.0.0 i am not able to get this working.
Bindings installed: HTTP, JSONPath Transform, HUE
Unfortunately i cant see any errors in the logs or something. Its just receiving nothing and doing nothing.

Content of GetHueName.js:

(function(i) {
var json = JSON.parse(i);
return ((json[‘name’]));
})(input)

Do you have any hints for me?

Why not use the JSONPATH transformation directly in your Thing Channel?

And just to check: you’re aware that your syntax that you showed is for the V1 binding, but openHAB 3 has a V3 binding which is no longer compatible with v1 configurations?

The short answer is: It worked like a charm before and i am not sure how to do this in text-file-format.
Can you give me an example?
I am using Text-file-Format only for backup- and migrations-purposes, since it seems more complicated for me to backup/export your data from “GUI-created” things/items/… Would you agree?

Yes, i am aware of the canceled v1-bindings, but since i am not sure how to improve my code in v3 i landed here.
I read the Binding-manuals before, but it seems not to solve my problem.

I would be very thankful for help :slight_smile:

Can you show us what the JSON string looks like as sent by your Hue Bridge? I can then provide an example text file configuration.

Well, the item shown in my first post is everything which was needed in OH2.5.6 to receive a name like “Badezimmer” from my HUE Bridge, where are several things/items/sensors located.
So for example HueMotionSensor001_Name gets its name every xx seconds (sure, a name isn’t changing often, but just for example).
No rule, no thing or something more was needed.

I am thankful for you reply, but unfortunately i can’t serve with more details :frowning:

Right, but your old Item used a JS transform to extract some information from a JSON string which was sent by your Hue Bridge. Can you show me what this JSON string looks like so I can be certain of the correct transformation to apply?

Ah ok, i hope this helps:
URL: http://192.168.2.XX/api/USERNAME-WITHOUT-A-PW/sensors/3
I am searching for “name”.

{

  • state: {

    • presence: false,

    • lastupdated: “2021-01-05T14:58:14”},

  • swupdate: {

    • state: “noupdates”,

    • lastinstall: “2019-12-23T14:05:54”},

  • config: {

    • on: true,

    • battery: 79,

    • reachable: true,

    • alert: “none”,

    • ledindication: false,

    • usertest: false,

    • sensitivity: 2,

    • sensitivitymax: 2,

    • pending: },

  • name: “Sensor Flur”,

  • type: “ZLLPresence”,

  • modelid: “SML001”,

  • manufacturername: “Signify Netherlands B.V.”,

  • productname: “Hue motion sensor”,

  • swversion: “6.1.1.27575”,

  • uniqueid: “00:17:88:01:03:29:f2:xx-xx-xxxx”,

  • capabilities: {

    • certified: true,

    • primary: true}

}

OK, so that’s

{
   "state":{
      "presence":false,
      "lastupdated":"2021-01-05T14:58:14"
   },
   "swupdate":{
      "state":"noupdates",
      "lastinstall":"2019-12-23T14:05:54"
   },
   "config":{
      "on":true,
      "battery":79,
      "reachable":true,
      "alert":"none",
      "ledindication":false,
      "usertest":false,
      "sensitivity":2,
      "sensitivitymax":2,
      "pending":[
         
      ]
   },
   "name":"SensorFlur",
   "type":"ZLLPresence",
   "modelid":"SML001",
   "manufacturername":"SignifyNetherlandsB.V.",
   "productname":"Huemotionsensor",
   "swversion":"6.1.1.27575",
   "uniqueid":"00:17:88:01:03:29:f2:xx-xx-xxxx",
   "capabilities":{
      "certified":true,
      "primary":true
   }
}

Thing

Save the following in a file called hue.things inside your things folder. You can actually call it anything you like, as long as it has .things on the end.

Thing http:url:hue "Hue" [
	baseURL = "http://192.168.2.xx/api/USERNAME-WITHOUT-A-PW",
	refresh = "60000",
	ignoreSSLErrors = "true"
]
{
	Channels:
		Type string: name3 "Sensor 3 Name" [
			mode = "READONLY",
			stateExtension = "/sensors/3",
			stateTransformation = "JSONPATH:$.name"
		]
}

Item

Reconfigure your Item to look like:

String HueMotionSensor001_Name { channel="http:url:hue:name3" }

Further

If you wanted to get your battery state, for example, your transformation becomes:

"JSONPATH:$.config.battery"

which you could configure into a Number Channel, and a Number Item.

3 Likes

Many thanks !!
First it was not able to fill in the name to the item and nothing appeared in the logs.
After i added some additional and non-optional stuff (according to HTTP - Bindings | openHAB) like

timeout = “3000”,
buffersize = “2048”,
delay = “0”,
authMode = “BASIC”,
commandMethod = “GET”

it suddently pulls the name inside the item :smiley:

2021-01-05 21:11:33.812 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘HueMotionSensor001_Name’ changed from NULL to Sensor Flur

Again: Many thanks, marked as Solution and stay healthy :slight_smile:

1 Like

That’s strange - you shouldn’t need those. Whilst it says they are non-optional, they are also provided with default values by the binding so if they’re not specified the Thing should still work. I suspect either you didn’t wait long enough for data to come in, or you’re hitting the age-old issue where openHAB doesn’t always properly load a Things file after it has been saved. You can restart openHAB if this happens, or do this.

Either way, doesn’t really matter - glad you’ve got it working!