[SOLVED] HTTP and xpath

Trying to get an http request working.

Here’s my item:

String weather_air_quality_birchlane    "Air Quality [%s]"              <pollen>        (g_weather)                                      { http="<[http://hilltop.gw.govt.nz/Data.hts?Service=Hilltop&Request=GetData&Site=Birch%20Lane%20AQ&Measurement=PM10:600000:default]" }

I seem to get the following in the log (http log with debug on)

2018-11-26 08:16:59.706 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.UnknownFormatConversionException: Conversion = 'L'
        at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691) [?:?]
        at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720) [?:?]
        at java.util.Formatter.parse(Formatter.java:2560) [?:?]
        at java.util.Formatter.format(Formatter.java:2501) [?:?]
        at java.util.Formatter.format(Formatter.java:2455) [?:?]
        at java.lang.String.format(String.java:2940) [?:?]
        at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:144) [241:org.openhab.binding.http:1.12.0]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [218:org.openhab.core.compat1x:2.3.0]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [218:org.openhab.core.compat1x:2.3.0]

Just trying to pull any data at this stage. Then later there’s a specific value I want.

Number weather_air_quality_birchlane    "Air Quality [%.2f ug/m3]"                    (g_weather)                                      { http="<[http://hilltop.gw.govt.nz/Data.hts?Service=Hilltop&Request=GetData&Site=Birch%20Lane%20AQ&Measurement=PM10:60000:XPATH(/Hilltop/Measurement/Data/E[1]/I1/text() )]" }

Here’s the xml data:

<?xml version="1.0" ?>
 <Measurement SiteName="Birch Lane AQ">
   <DataSource Name="PM10" NumItems="1">
    <ItemInfo ItemNumber="1">
  <Data DateFormat="Calendar" NumItems="1">

I may be completely wrong but it seems that the HTTP Binding doesn’t like the space (%20) in your URL
The next character after the space is L and the binding may be parsing that as a “Conversion” ?

Try to use caching to see if this goes away or try to escape the % character with another % or \

Found this: Http binding error, Invalid query (from 3 years ago :slight_smile:)

Hmm I’ll give that a go. Though I think the http binding has died…

…and yes, that’s done it. It’s pulled the value now

1 Like

this deserves a github issue against https://github.com/openhab/openhab1-addons/ to include quotation marks (single ' or double ") around the URL for the HTTP binding…

{ http="<['URL':refresh:xform" }

No, quotes didn’t make a difference. I tried that. But the escaping the % with another % worked.

so space (%20) becomes %%20

I know… I was thinking to open a new feature request (to allow to enclose the URL to avoid this % story) :slight_smile:

{ http="<['URL':refresh:xform" }

If I figure out how, I could do a documentation update for the http binding to mention it.

easy: bottom of: https://www.openhab.org/addons/bindings/http1/
Edit this page on GitHub

1 Like

I’ll have a look tonight. Apart form some bridges, I don’t think I’ve contributed to OH yet.

1 Like

those bridges are a life saver for me

I can control my Paradox because of you

I owe you! :blush:

The feeling is mutual. The number of posts you’ve responded to for questions I’ve asked.

1 Like

Adding full item string for solution.

String weather_air_quality_birchlane    "Air Quality [%s]"              <pollen>        (g_weather)                                      { http="<[http://hilltop.gw.govt.nz/Data.hts?Service=Hilltop&Request=GetData&Site=Birch%%20Lane%%20AQ&Measurement=PM10:600000:default]" }
1 Like