Http binding option 'granularity'

Tags: #<Tag:0x00007f616dd93598>

Can someone explain me more about the’granularity’ option for http binding?

The documentation contains the following information:

By default, the binding checks once every second (1000 milliseconds) to see if any bound items should be retrieved.

But I don’t understand why you have an extra parameter for time settings when you do it directly on the items:

http="<[http://www.domain.org/weather/openhabcity/daily:60000:REGEX(.?(.?).*)]"

When using HTTP cache configuration you specify how often the HTTP binding goes to the URL to download the data. On the Item you specify how often you want your Item to update from the cache.

The example you provide above is NOT using the HTTP cached config so you the 60000 specifies how often the Item requests the data from the URL directly. In this case, the http.cfg isn’t even used.

The purpose of the cache configuration is to only hit the URL once when you have multiple Items that need to get populated from that URL. See Comprehensive Wunderground using HTTP Binding Example for an extensive example of using the HTTP cached config.

Ok, another example by using the http.cfg:

http.cfg:

weatherCache.url=http://weather.yahooapis.com/forecastrss?w=566473&u=c
weatherCache.updateInterval=60000

weather.items:

Number temperature { http="<[weatherCache:10000:XSLT(demo_yahoo_weather_temperature.xsl)]" }

I thought this is specified by weatherCache.updateInterval=60000, so the data is loaded every 60 seconds?

What is the difference between “updateInterval”, which is specified for each URL, and the parameter “granularity” in http.cfg?

@mas

In your case just above, the http cache get updated by an http request every 60000ms
You item gets updated from the cache every 10000ms

When you use the http binding directly with an url in the binding parameters like:

http="<[http://www.domain.org/weather/openhabcity/daily:60000:REGEX(.?(.?).*)]"

The item will pull an http request directly every 60000ms

Using the cache allows a large amount of data (a json for example) to be pulled and stored in the cache and then different items to get the data from the cache without making an http request for each of them.

I hope that helps with your question

Thank you for the answer, but unfortunately it still doesn’t help me. I’ll extend my example above.

http.cfg:

# timeout in milliseconds for the http requests (optional, defaults to 5000)
#timeout=

# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
granularity=2000

# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
#format=

# configuration of cache items
weatherCache.url=http://weather.yahooapis.com/forecastrss?w=566473&u=c
weatherCache.updateInterval=60000

weather.items:

Number temperature { http="<[weatherCache:10000:XSLT(demo_yahoo_weather_temperature.xsl)]" }

What does granularity=2000 mean in this case? What happens every two seconds?

from the docs:

granularity 1000 the binding checks once every second (1000 milliseconds) to see if any bound items should be retrieved. For example, to only check once every five seconds, change this value to 5000

This is for items with a direct (non cached) binding. Let’s say that you have two items with a direct http binding and they both make a call within a second. This value will ensure that the calls are separated by (1000ms or more or less) to avoid too many calls at the same time.

Ah okay, thank you. Now I realize what that parameter means.