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.

http.cfg

# configuration of the first cache item
openhabVersion.url="https://openhab.ci.cloudbees.com/job/openHAB-Distribution/api/json?tree=lastSuccessfulBuild%5Bnumber%5D"
openhabVersion.updateInterval=3600000
# update interval = milliseconds
# 3600000 = jede Stunde

items-file

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

What is the difference between this two update intervals?

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

items-file
–> 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 https://docs.openhab.org/addons/bindings/http1/readme.html#item-configuration
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:

http.cfg   
# openhabVersion.url="https://openhab.ci.cloudbees.com/job/openHAB-Distribution/api/json?tree=lastSuccessfulBuild%5Bnumber%5D"
# openhabVersion.updateInterval=3600000


items-file
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="<[https://openhab.ci.cloudbees.com/job/openHAB-Distribution/api/json?tree=lastSuccessfulBuild%5Bnumber%5D:600000:JSONPATH($.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(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) [248:org.openhab.binding.http:1.12.0.201712210210]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [206:org.openhab.core.compat1x:2.3.0.201712210749]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [206:org.openhab.core.compat1x:2.3.0.201712210749]
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 https://openhab.ci.cloudbees.com/job/openHAB-Distribution/api/json without declaring the tree? You can get the build number from there with the same jsonpath.

1 Like

This works, thanks!