HTTP thing how to extract channels values?

Hi,

on Openhab 4.2.2 I’m trying to extract current weather data from an HTTP request, I’ve written the follow for the thing and channels, then linked items, but last succes is fine all the reply can be readed as json from risultato but all of the others items got NULL, UNDEF.

Can you please tell me if this is completely wrong? I cannot understand where the reply should go or how can I extract single values.

Thanks, BR

UID: http:url:weatherservice
label: weather Thing URL HTTP
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://wttr.in/Caserta?format=j1
  delay: 0
  stateMethod: GET
  refresh: 42300
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: last-failure
    channelTypeUID: http:request-date-time
    label: Last Failure
    configuration: {}
  - id: last-success
    channelTypeUID: http:request-date-time
    label: Last Success
    configuration: {}
  - id: risultato
    channelTypeUID: http:string
    label: Channel Testo
    description: ""
    configuration:
      transformationPattern: JSONPATH($.current_condition[0].weatherDesc[0].value)
  - id: weatherhumidity
    channelTypeUID: http:number
    label: Humidity
    description: Umidità
    configuration:
      transformationPattern: JSONPATH($.current_condition[0].humidity)
  - id: weatherpressure
    channelTypeUID: http:number
    label: Pressure
    description: Pressione
    configuration:
      transformationPattern: JSONPATH($.current_condition[0].pressure)
  - id: weathertemp
    channelTypeUID: http:number
    label: Temperatura
    description: Temperaturada meteo web
    configuration:
      transformationPattern: JSONPATH($.current_condition[0].temp_C)

Errors in the log?

HTTP Channels have two transformations, and I don’t think either of them is “transformationPattern”. There’s “commandTransformation” and “stateTransformation”. HTTP - Bindings | openHAB

Always check your syntax against the docs if you use .things files. Another thing you can do is configure it in the UI and then click on the code tab to see the names of the parameters.

Beyond that :shrugging. I don’t support .things files. I’d rather solve home automation problems than syntax errors.

Thank you @rlkoshak, I was using wrong syntax!

UID: http:url:weatherservice
label: weather meteo Thing URL HTTP
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://wttr.in/Caserta?format=j1
  delay: 0
  stateMethod: GET
  refresh: 42300
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: last-failure
    channelTypeUID: http:request-date-time
    label: Last Failure
    configuration: {}
  - id: last-success
    channelTypeUID: http:request-date-time
    label: Last Success
    configuration: {}
  - id: risultato
    channelTypeUID: http:string
    label: Channel Testo
    description: ""
    configuration:
      stateTransformation: JSONPATH:$.current_condition[0].weatherDesc[0].value
  - id: weatherhumidity
    channelTypeUID: http:string
    label: Humidity
    configuration:
      stateTransformation: JSONPATH:$.current_condition[0].humidity
  - id: weatherpressure
    channelTypeUID: http:string
    label: Pressure
    configuration:
      stateTransformation: JSONPATH:$.current_condition[0].pressure
  - id: weathertemp
    channelTypeUID: http:number
    label: Temperatura
    configuration:
      stateTransformation: JSONPATH:$.current_condition[0].temp_C

Now only pressure and humidity seems missing, but if I try:

curl -s http://wttr.in/Bologna?format=j1 | jq '.current_condition[0].humidity'
"82"

The value is shown, I’ve tried also type number for channel but seems to be the same.

if the result is literally "82" you need to remove the quotes. The HTTP transform supports chaining transformations so you can run the JSONPATH and then chaing that to an inline script transformation to strip off the quotes.

Thank you for the advice but I’m a little confused, tried out this but still got UNDEF:

  - id: weatherpressure
    channelTypeUID: http:string
    label: Pressure
    configuration:
      stateTransformation: JSONPATH:$.current_condition[0].pressure |REGEX:"\"(.*)\"":$1

Don’t guess at the syntax. It says right there in the description for the field how to chain two transformations.

Transformation pattern used when receiving values. Multiple transformations can be chained by listing each transformation on a separate line, or by concatenating them with “∩”.

Also always look at the logs when something goes wrong. It will usually tell you exactly what’s wrong and sometimes how to fix it

Thank you, if I’ve understood, the correct syntax should be:
stateTransformation: JSONPATH:$.current_condition[0].pressure ∩ REGEX:"\"(.*)\"":$1

In logs only those rows are shown so I suppose data are managed correctly:

6:06:30.912 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing 'http:url:weatherservice' changed from INITIALIZING to UNKNOWN
16:06:32.481 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'weather_meteo_Thing_URL_HTTP_Last_Success' changed from 2025-03-15T16:04:03.442712746+0100 to 2025-03-15T16:06:32.478219543+0100
16:06:32.485 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing 'http:url:weatherservice' changed from UNKNOWN to ONLINE

Anyway I’ve tried replacing the pressure transformation with the one from temp_c expecting to see the same data both in pressure and temperature. But temperature is shown, pressure is NULL

That’s events.log. openhab.log is where the errors will appear.

All those logs show is that the Thing came online and was successfully able to pull down the JSON data. But the success in parsing that data and updating the Items is failing and those errors will be in in openhab.log.