How to get the second argument (2$) in Javascript Transformation

Hello, I have successfully installed and configured openHab on my Raspberry Pi. However, I need some help with the coding of a transformation script:
I’m using the “Fritzbox TR064” Binding in order to integrate my phone which works pretty well already. The item definition for an incoming call is:

Call    fboxIncomingCall    "Incoming call: [%2$s]"     {fritzboxtr064="callmonitor_ringing" }

The setup works, but once the incoming call ended, I get an “Err” since the input for “[%2$s]” is empty. My question now is how to write a transformation script in javascript to prevent the BasicUI from showing “Err” when there is no incoming call. I’ve tried to get the second argument and if it is empty, to return a valid value. But I can’t seem to get the second parameter in my transformation script…

How did you add the JS transform to your Item?

Was it something like [JS(transformFile.js):%2s]?

What is the transform you wrote?

Knowing what you have tried helps us avoid duplicated effort.

Alright, so at first I had the default item definition

Call    fboxIncomingCall    "Incoming call: [%2$s]"     {fritzboxtr064="callmonitor_ringing" }

The logging tool shows the arguments like this

[ItemStateChangedEvent     ] - fboxIncomingCall changed from  to 54069xx,017683xxxxx

I only want to show the second number (which works with “[%2$s]”) - but if there is no active call (fboxIncomingCall is empty), I don’t want to get “Err” on my sitemap.
What I tried in my transformation script was to split the argument by “,” and always return the second one. The new definition looks like this:

Call    fboxIncomingCall    "Incoming call: [JS(getCaller.js):%1$s]"     {fritzboxtr064="callmonitor_ringing" }


(function(i) {
    var array = i.split(",");
    return array[1];

This only gives a “null” as result in my sitemap file.
And the definition in my sitemap file looks like this:

Text item=fboxIncomingCall

Here you go:

Oh sorry, i saw you want to know something other…

No idea, i only use this to get notifications from openhab on my android phone.

OK. So the getCaller.js always returns null, or it returns null when there is no active call? I would have expected the JS to work for at least the incoming call case.

If you can’t figure anything out, you can resort to a Rule and Proxy Item.

The script always returns “null”, at least that’s what is being displayed in the BasicUI (see screenshot).

Could you please explain the “resort to a Rule and Proxy Item” part?

Maybe store the value in a proxy item. When new value comes in, look if it is a real number, if yes change proxy item to new value. If null or error, keep old value.

1 Like