HTTP binding & JSON data to items

Hi there,

Could someone please point me in the right direction, I would like to get some data from a local (Enphase Envoy) device into items in openhab.
I have installed the HTTP binding and JSON transformation.

I have created the HTTP thing,

At the moment this URL provides this data,

{
  "wattHoursToday": 570,
  "wattHoursSevenDays": 84550,
  "wattHoursLifetime": 84550,
  "wattsNow": 391
}

Could someone please help me to get the four values into Channels and Items.
I have tried a couple of ways but failed so far.

Kind Regards,
George

Install the jsonpath transformation

Use that to change the state description in your channel

Hi James

Thanks.

I seems to be having a bit of difficulty,

  • When I put, JSONPATH$.wattHoursToday in the Channel I get an error message in the log of,

2021-02-27 12:08:06.527 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.thingUpdated()' on 'org.openhab.binding.http.internal.HttpThingHandler@189d672': The transformation pattern must consist of the type and the pattern separated by a colon

  • When I put the JSONPATH$.wattHoursToday in the Link to Item, I get this in the logs,
    2021-02-27 12:10:54.519 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state 'UNDEF' with function 'JSONPATH$.wattHoursToday' and format '%s'

I must be misunderstanding something. Could you give me a hint.

Regards,
George

1 Like

When put directly into the channel (which is usually the best choice when available), just do as it says.
You might have any transformation here - like MAP - so you must tell it which one. Then supply the parameter/pattern for it.

JSONPATH:$.wattHoursToday

When selecting a profile from the UI, you’ve already selected JSONPATH and so you only need the parameter/pattern in the text box
$.wattHoursToday

But use the channel method here, set your profile back to default.

1 Like

Thankyou rossko57 & James for your help! Really appreciated.

Kind Regards,
George

Just to be clear: you almost had it correct, but you were just missing a colon! As the log complains:

@rossko57 provided the correct syntax

You’ll see the colon after JSONPATH. I thought that the UI would show the correct syntax, but it seems like the HTTP Binding doesn’t. Here’s what a similar field for the MQTT Binding shows:

1 Like

Not directly related to the specific problem here but when using HTTP APIs and JSON, I have found it helpful to use a jsonpath parser to test my path definition first: http://jsonpath.com/

You can alter and test the parameter definition quickly and easily so you know it’s right when you code it into OpenHAB

2 Likes

Thanks Barney that will come in handy!