Dynamic URL's for HTTP

I am trying to use a dynamic URL to fetch some data from pvoutput.org about my solar panel production. In services/http.cfg I have this config:


%1$tY%1$tm%1$td should expand to todays date as YYYYMMDD I think, but it does not.

This is used in my items as:

Number Solar_production_D "Solar [%.1f KWh]" { http="<[pvoutputb:60000:JS(getProduction.js)]" }

transform/getProduction.js reads the CSV output from pvoutput.org:

(function(i) {
    var array = i.split(",");
    var solardate = array[0]
    var solarproduction = array[1] / 1000
    return solarproduction;

In the log file I see that the date is not expanded in the URL:

2017-10-06 09:56:08.069 [DEBUG] [ab.binding.http.internal.HttpBinding] - item 'Solar_production_D' is fetched from cache
2017-10-06 09:56:08.069 [DEBUG] [ab.binding.http.internal.HttpBinding] - updating cache for 'pvoutputb' ('https://pvoutput.org/service/r2/getoutput.jsp?df=%1$tY%1$tm%1$td?tz=Europe/Amsterdam')
2017-10-06 09:56:08.474 [WARN ] [org.openhab.io.net.http.HttpUtil    ] - Method failed: HTTP/1.1 500 Server Error
2017-10-06 09:56:08.485 [DEBUG] [ab.binding.http.internal.HttpBinding] - transformed response is 'NaN'
2017-10-06 09:56:08.485 [DEBUG] [ab.binding.http.internal.HttpBinding] - Couldn't create state for item 'Solar_production_D' from string 'NaN'

How can I fix my config so the date gets inserted in the URL so I only see today’s output from pvoutput.org?

Many thanks for your help.

The docs are a little bit ambiguous. I suspect that dynamic URLs are not supported using the caching config. I think it only works when you just define the URL on the Item.

Thank you Rich, that seems to be the problem.

I moved the URL to my items file and now it works. Except for the fact that pvoutput.org gives me a 400 return code when it cannot find any data to return. And that means my value ends up undefined, and I would rather it would be 0 then.

I ended up changing the Javascript transformation to this:

(function(i) {
    var array = i.split(",");
    var solardate = array[0];
    var y = solardate.substr(0,4);
    var m = solardate.substr(4,2) - 1;
    var d = solardate.substr(6,2);
    var pvoutdate = new Date(y, m, d);
    var solarproduction = array[1] / 1000;
    var today = new Date();

    today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0);

    if (today.getTime() === pvoutdate.getTime()) {
        return solarproduction;
    } else {
        return 0;

And I took out the ?df= part from the URL and replaced with ?limit=1. Now I always get some data returned from pvoutput, I check if it matches with today’s date, and return 0 if it does not.