Setting up http-chache and item

Hi, i´m on oh 2.3 snapshot and use the http1 binding.

Please can someone explain me the difference between the update intervals in the http.cfg and in the *.items?

I have looked into the docs, but i think i don´t understand this part.


# configuration of the first cache item
# update interval = milliseconds
# 3600000 = jede Stunde


String OH_LastBuild         "OH: LastBuild[%s]" { http="<[openhabVersion:60000:JSONPATH($.lastSuccessfulBuild.number)]" }

What is the difference between this two update intervals?

–> is this the interval, openhab checks the web for a new build?

–> is this the interval, openhab checks only the http-cache (and not the webpage) for a new build?

In this case, it would be a silly idea, when i make http.cfg-update every day and items-file every minute, because http.cfg will only get new values one time a day?

So when i check the web for an update every 2 hours, which value do you suggest me to set in the items-file?

(2 hours is —> 1000 miliseconds x 60 x 120 = 7.200.000 milliseconds - is that right for updateinterval?)

The refresh in the cfg file is how often the binding will pull down information from the server. The refresh on the Item is how often it updates its state from the cache.

There can be cases where a user might want to have a different refresh rate on the Item and the cache and having the two paramters allows that.

Not necessarily. If you update the cache once every 24 hours and your Item only refreshes once every 24 hours also, you can end up with your Item refreshing one minute before the cache is updated and the Item will not update again until the next day and therefore perpetually showing 23 hour old data instead of the more recent data. So you will want your refresh rate on the Item set to minimize this lag.

Put another way, if you have a one minute refresh rate on the Item, your Item will show the new data in the cache no later than one minute after the cache is updated. If you chose a 24 refresh rate on the Item you can only guarantee that the Item will reflect the latest data in the cache up to 23:59:59.999 after the cache is updated.

It depends on the maximum amount of time you are willing to have your Item be out of date with the cache. I usually do at least half so if you update the cache every 2 hours I’d update my Items every hour.

Ok, now i understand.

I think, i go the other way and make the updates without http-binding, only with a cronjob in a rule. So i only have one thing to update.

You can also use the http binding without caching and thay way your item definition solely determines the update interval.

So i have to remove the config from the http.cfg and write this definitions behind my items?

To put it short: yes.
The info can be found at
If you’re only getting one item from a request it doesn’t make sense to cache anyway, it just adds complexity. If you’re getting several items, you reduce to load on the server you’re requesting from by caching.

I know the docs, but i can´t get it to work.

This works:

# openhabVersion.url=""
# openhabVersion.updateInterval=3600000

String OH_LastBuild         "OH: LastBuild[%s]" { http="<[openhabVersion:600000:JSONPATH($.lastSuccessfulBuild.number)]" }

And this doesn´t work:

items-file without any http.cfg-configs
String OH_LastBuild         "OH: LastBuild[%s]" { http="<[$.lastSuccessfulBuild.number)]" }

Error in openhab.log

2017-12-22 08:26:31.651 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.UnknownFormatConversionException: Conversion = 'D'
	at java.util.Formatter$FormatSpecifier.conversion( [?:?]
	at java.util.Formatter$FormatSpecifier.<init>( [?:?]
	at java.util.Formatter.parse( [?:?]
	at java.util.Formatter.format( [?:?]
	at java.util.Formatter.format( [?:?]
	at java.lang.String.format( [?:?]
	at org.openhab.binding.http.internal.HttpBinding.execute( [248:org.openhab.binding.http:]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute( [206:org.openhab.core.compat1x:]
	at org.openhab.core.service.AbstractActiveService$ [206:org.openhab.core.compat1x:]
2017-12-22 08:26:32.651 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service

Honestly I don’t know why it’s failing. I can only think of one suggestion to try. Have you tried the URL without declaring the tree? You can get the build number from there with the same jsonpath.

1 Like

This works, thanks!